Differential ADC
Posted: 11 December 2007, 19:44 PM
Here is a little program demonstrating how to do differential ADC. It was written for the ZX24, but the technique is good for all processors
-Tony
-Tony
A place to discuss ZBasic and ZX series microcontrollers.
https://forum.zbasic.net/
Good point. I was wondering about doing something with the ADLAR bit. It is an easy mod to make. I had to do a little extra math to check if the value is greater than 511, then subtract 1024 from the value to get the correct signed value.dkinzer wrote:In differential mode, it is convenient to use the ADLAR bit to force the result into bits 15-6. The advantage of doing this is that the result can be directly used as a 16-bit signed value. Obviously, an adjustment needs to be made in the ADC-to-voltage conversion equation to compensate for the fact that the value is 64 times what it should be.
Code: Select all
dim ADC_Reading as Integer
'NOTE: ADLAR bit is set
ADC_Reading = ShR(CInt(Register.ADC) ,6)
If the value will ultimately be converted to some other units (e.g. voltage, pressure, etc.) the scaling can be combined into that conversion, often at no additional cost since those conversions generally involve multiplication and division anyway.spamiam wrote:I am reasonably sure that always doing a quick right shift will be faster than deciding when to sometimes subtract 1024.
Right. But for the little demo program, I wanted it to be as general-purpose as possible. I was thnking that some users might transplant the code directly into their progran as-is, then further translate the data as needed.dkinzer wrote:If the value will ultimately be converted to some other units (e.g. voltage, pressure, etc.) the scaling can be combined into that conversion, often at no additional cost since those conversions generally involve multiplication and division anyway.