RL78/G13內建溫度感測器
termerature sensor在 +25度時的電壓為1.05V
溫度每升高1度, 電壓降 3.6mV
此次測試會基于上一篇實驗接續 RL78 -[10]- CS+_CACX_Lab4_ADC_內部參考電壓
暫存器ADS可以切換ADC input channel
1. Procedure Modify
main.c 全域變數宣告
1 2 3 4 |
uint16_t adcValue[4]; double refVol;// adc refer voltage float temp; uint8_t step = 0;// 0:internal 1:temperature |
main()
1 2 |
R_ADC_Set_OperationOn(); R_ADC_Start(); |
r_cg_adc_user.c
1 |
#include <math.h>
|
r_adc_interrupt()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
extern uint16_t adcValue[4]; extern double refVol; extern uint8_t step; extern float temp; double ref145; double tempVoltage,i2,i3; ref145 = pow(2,10) * 1.45;// 2^7 * 1.45 R_ADC_Get_Result((adcValue+step)); refVol = ref145 / (double)adcValue[0]; tempVoltage = refVol * adcValue[1] / 1024; if(tempVoltage > 1.05){ i2 = tempVoltage - 1.05; i3 = i2 / 0.0036; temp = 25 - i3; }else if(tempVoltage < 1.05){ i2 = 1.05 - tempVoltage; i3 = i2 / 0.0036; temp = 25 + i3; } if( step == 0){ step = 1; ADS = _80_AD_INPUT_TEMPERSENSOR_0; } else{ step = 0; ADS = _81_AD_INPUT_INTERREFVOLT; } |
留言
張貼留言