2016年6月29日 星期三

為一個精確的ADC提供一個簡易可靠的參考電壓 (A simple and reliable reference voltage for an accurate ADC) TL431



因為使用Arduion 做為電池容量測試的工具並以電腦做為長期資料收集的後端。因為Arduino 吃電腦USB的電,所以Arduino無法使用內部的參考電位做為ADC的參考電壓。必須要額外使用一個穩定和足夠精準的參考電壓,來做為ADC 的校正。這樣才能保證ADC計算出來的電池電壓值的精確度在一定的範圍內。便宜方便的做法是使用一顆TL431,它的2.5V的電壓輸出,做為ADC自我校正的參考電位。其電路如下圖所示:

這個參考電壓電路只要一顆TL431與一顆電阻的組成,就可以得到一個穩定的2.5V的參考電壓。input 接Arduino的VCC, Vka就接到ADC的輸入做為校正電壓。

另外如果有精度更高的需求,可以使用更好的參考電壓原件,比如 ADR3425。


The circuit on Figure 1 is used to get a reliable and stable reference voltage. Usually the ADC will not be accurate when Arduino connected to PC via USB. If we want an accurate ADC/voltage mapping, we will need an accurate and reliable reference voltage to calibrate AD value. The figure 1 is a sample solution. The VKA is a stable  2.5 voltage output. The MCU can use it to calibrate the ACD/Voltage mapping.




2016年4月24日 星期日

按鈕或開關彈跳的問題 (Button Debounce)


今天找到一個更好的解決方法,網址如下:

https://electrosome.com/switch-debouncing/


I think the best solution is "Hardware" solution, if there is no limitation of dimension.  I use a sample RC circuit (shows as below) which can be found on Internet easily. The resister and capacitor values which I used are 250K ohm and 0.1 uF. The basic rule to choose the value of R and C are, small C can be discharged quickly when switch closed, and high value of R will charge slowly. I think the limitation of this debounce circuit is that this circuit can not handle the high frequency switch action. Regarding the values of RC, it will take about 0.125 second to charge capacitor from 0 V to 5 V. The RC value can be calculated in fact. 5 * R * C is time of C charge to 5V, and discharge time will be 5 * C (assumed the resistor in switch is 1 ohm). and the rule is discharged time is sorter than bounce cycle time, and charge time much longer than bounce cycle time. Regarding measurement, the bounce cycle time of the switch is about 50 us.

如果沒有硬體空間限制的問題的話,我想採用硬體的對策是最好的消除彈跳的方法。我這次使用的數值是250K歐姆的電阻,以及0.1uF的電容器。電路如下圖所示。我想這個電路的限制是,無法使用在高速切換的開關電路上,因為充電的時間比較長。依照電容充放電的特性,與所選的數值。在開關打開後約須0.125秒的時間,電容器才能充電到5伏特。電阻電容值事實上可以通過計算決定。5 *R*C為充電時間,5*C為放電的時間(假設開關電路阻抗為1歐姆)。充電的時間必須要比跳跳訊號的週期長,而放電的時間則是要比彈跳的週期短。依據視波器的量測,彈跳週期約為50 us。






Bounce signal when R C values are not good enough.