Hello Tanaka san,
Thanks for your contribution to the community.
1 of 1 people found this helpful
You can speed-up temperature calculation using Fast Thermistor Calculator component, which takes about 15 times less CPU clocks than traditional calculations.
Thank you very much for your information!
I studied your code a little, and noticed that there are two differences.
(1) You (and Cypress Component) use approximation between 0 ~ 50 C degree,
beside the range of 103AT-11 is -50 ~ +105 C degree and I used the maker's formula.
(In general 0 ~ 50 should be enough though)
(2) The biggest contribution to the speed is usage of "fastlog()" which does not use "log()"
It requires 3 sampled values, such as @5C, @25C, @45C,
and the error out side of 0~50 could be large (Sorry I was too lazy to calculate them, yet).
About (2), if "fastlog()" can speed up the calculation, may be replacing "log()" in my
formula also provide speed boost similar to your estimation and it also discard the
requirement for "-lm" option, which is very nice.
BTW, the Thermistor Calculator's URL has been changed and it is now
Attached is my project using "fastlog()".
Around 25~26 C degree, the value seems to be OK.
Thank you for updated link and updated project.
Thank you all so much for your support and contributions ... I will try and apply your examples and report back.
Motoot thank you for your example code ... i tried to use it in my application using CY8C4024LQI-S402 but i am stuck on how i use the API to get just the ADC count only. There is some simple API for getting readings in mVolts. I believe I am supposed to use the ADC_StartConvert(uint8 chld), but I am not sure, how to make sure the ADC has completed it measurement using the ADC_IsBusy(void) API. Can i get some help on how to do this properly using this single slope 10-bit ADC for this PSoC 4000S.
int16_t adc_counts ;
float value ;
///??? adc_counts = ?????
value = (float)adc_counts / (float)ADC_MAX ;
return( value ) ;
Below it the available API, I am confused as to how to actually get the count and not the voltage. I was successful in getting the ReadResult_mVolts to function and give me the correct voltage, but i need Count.
• cystatus ADC_StartConvert(uint8 chId)
Initializes the hardware and initiates an analog-to-digital conversion on the selected input channel.
• uint8 ADC_IsBusy(void)
The function returns the status of the ADC's operation.
• uint16 ADC_ReadResult_mVolts(uint8 chId)
This is a blocking API. It initiates a conversion, waits for completion and returns the result.
• uint16 ADC_GetResult_mVolts(uint8 chId)
This API does not perform an ADC conversion and returns the last valid result for the specified channel.
Thanks again for the help!!
I did not know that CY8C4024LQI-S402 does not have Sequencing SAR ADC!
I tried to to use 10-bit ADC, which is probably same one with yours on my CY8CKIT-149.
I hope this will work with your system, if you change the device and pins. (Fingers crossed)
Note: As my board is using 5V as VDD/VDDA, if your system uses 3.3V,
please change VDDAMV to 3300.0 or something like that.
(I suggest you to measure the voltage and use real value * 1000.0 to make it mV)
/* value for 103AT-11 */
#define R1 10.0
#define R25C 10.0
#define B 3435
#define ABS_ZERO 273.15
#define T25C 298.15
#define VDDAMV 5000.0 /* use 3300.0 for 3.3V system */
volatile uint16 ADC_CSD_result;
char str ;
void print(char *str)
float mv2temp(int16_t mv)
float result ;
result = (float)mv / 1000.0 ; /* just for test */
return( result ) ;
float get_temp(int16_t mv)
float adc_in ;
float Rt ;
float Tk, Tc ;
adc_in = (float)mv / VDDAMV ;
Rt = R1 * adc_in / (1.0 - adc_in) ;
Tk = 1.0 / (log(Rt / R25C) / B + 1.0/T25C) ;
Tc = Tk - ABS_ZERO ;
sprintf(str, "test 103AT-11 (%s %s)\n", __DATE__, __TIME__) ;
uint16_t mv ;
float temp = 0.0 ;
CyGlobalIntEnable; /* Enable global interrupts. */
mv = ADC_CSD_ReadResult_mVolts(0);
temp = get_temp(mv) ;
sprintf(str, "%d.%03d\n", (int)temp, (int)(temp * 1000) % 1000) ;
Tera Term log
ADC_CSD_4.cyprj.Archive01.zip 461.7 K