/*
* Find AVCC based on the fact that we know the bandgap voltage.
* To avoid excessive rounding we multiply 1024 by 1000 before dividing
* with the ADC result and then divide the result by 1000 afterwards.
* the final result is the supply voltage in millivolts.
*/
supply_voltage = ((BG_VOLTAGE * ((1024000) / bandgap)) / 1000);
例程是将VCC作为参考电压,采集内部1.1V电压的adc值,倒推Vcc电压值。
因为是10位adc,所以满量程是1024,BG_VOLTAG是内部1.1V电压值,是1100. bandgap是测量内部1.1电压得到的adc值。
好奇这里为什么先是1024放大1000倍,最后结果再除1000. 要是说为了避免丢掉四舍五入,但感觉结果还是会舍弃小数位的。
为何不直接这样?
supply_voltage = BG_VOLTAGE * 1024 / bandgap;
离线
他是为了保留括号,两种方法都可以。如同进门迈左脚还是右脚,没啥好讨论的。
感谢,不纠结了。
离线
让我联想到 KEIL C51 常量的大坑
能细说下吗?虽然不怎么用51,但还是没准以后还会用到。
离线