Devices & Components
Breadboard - 840 contacts
16x2 LCD display with I²C interface
40 colored male-male jumper wires
THERMISTOR NTC 10KOHM 3950K DISC
RES 10K OHM 0.1% 1/4W AXIAL
CY8C58LP
Software & Tools
PSoC Creator 1
Project description
Code
Code for thermistor
c
This is the code
1#include "project.h" 2#include "math.h" 3#include "float.h" 4 5uint32 loop_counter, thermistor_R ; 6uint16 R_1_result, themistor_result ; 7int16 thermistor_mV, R_1_mV, temperature ; 8float R_1_result_f, R_1_mV_f, thermistor_mV_f, ratio_f, voltage_f ; 9float thermistor_RA_f, thermistor_RB_f ; 10float current_mA_f, temperature_K_f ; 11 12int main(void) 13{ 14 CyGlobalIntEnable; 15 16 ADC_DelSig_1_Start() ; 17 AMux_1_Start() ; 18 19 LCD_Start() ; 20 LCD_Position(0,0) ; 21 22 DAC_Start() ; 23 24 LCD_PrintString("Thermistor Test ") ; 25 CyDelay(1000) ; 26 27 LCD_Position(0,0) ; 28 29 while(1) 30 { 31 P0_1_Write(1) ; 32 CyDelay(100) ; 33 P0_1_Write(0) ; 34 CyDelay(100) ; 35 36 loop_counter++ ; 37 38 AMux_1_Select(0) ; 39 ADC_DelSig_1_StartConvert() ; 40 ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT) ; 41 42 P0_1_Write(0) ; 43 44 R_1_result = ADC_DelSig_1_GetResult16() ; 45 R_1_result_f = (float)R_1_result ; 46 47 R_1_mV = (int16)ADC_DelSig_1_CountsTo_mVolts(R_1_result) ; 48 R_1_mV_f = (float)R_1_mV ; 49 50 current_mA_f = R_1_mV_f / 10000. ; 51 52 AMux_1_Select(1) ; 53 ADC_DelSig_1_StartConvert() ; 54 ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT) ; 55 56 themistor_result = ADC_DelSig_1_GetResult16() ; 57 58 thermistor_mV = (int16)ADC_DelSig_1_CountsTo_mVolts(themistor_result) ; 59 60 thermistor_mV_f = (float)thermistor_mV ; 61 62 thermistor_RA_f = thermistor_mV_f / current_mA_f ; 63 64 thermistor_R = Thermistor_1_GetResistance(R_1_mV, thermistor_mV) ; 65 66 thermistor_RB_f = (float)thermistor_R ; 67 68 temperature = Thermistor_1_GetTemperature(thermistor_R) ; 69 70 DAC_SetValue( temperature - 2300 + 127 ) ; 71 72 P0_0_Write(1) ; 73 LCD_IsReady() ; 74 LCD_Position(0,0) ; 75 LCD_PrintString("loop cnt: ") ; 76 LCD_Position(0,10) ; 77 LCD_PrintU32Number(loop_counter) ; 78 LCD_Position(1,0) ; 79 80 LCD_Position(1,0) ; 81 LCD_PrintString(" degrees ") ; 82 LCD_Position(1,0) ; 83 LCD_PrintNumber( temperature/100 ) ; 84 LCD_Position(1,2) ; 85 LCD_PrintString(".") ; 86 LCD_PrintNumber( temperature%100 ) ; 87 P0_0_Write(0) ; 88 } 89}
Comments
Only logged in users can leave comments