|
Your code does not look right.
First question, do you have a terminating R on IDAC output ?
Next question is what is amp of input waveform ? You have to scale IDAC and pulse
signal path such that they match at max Vpulse, to maximize dynamic range and
resolution of the solution.
Just in case compiler not "aware" use >> and << vs multiplies/divides.
Lets assume the following
IDAC 0 - 2.04 mA
IDAC R = 600 ohms, therefore full scale = .6 x 2.04 = 1.224 V max pulse amplitude
We start at 1.02 mA = 0x80, 128 dec, half scale, .612 V
Pulse amp is 1.0 V
So first trial is
1) VDAC = .612
2) comp = low, the pulse is higher
3) So we add last VDAC value + 1/4 VDAC range = .612 + .306 = .918
4) comp = low, the pulse is higher
5) So we add last VDAC value + 1/8 VDAC range = .918 + ( 1.224 / 8 ) = .918 + .153 = 1.071
6) comp = high, VDAC > pulse
We know know 1.071 > Vpulse > .918, but we have more resolution than that. Our resolution
is 1.224 / 256 = 4.78125 mV
7) So we take VDAC value at beginning of last test, and add 1/16 to it
8) comp = .918 + ( 1.224 / 16 ) = .9945
9) comp = low, vpulse > .9945
..
..
..
..
Work out the same scenario when comp indicates pulse is lower, another switch flag. Its
all part of the same routine. You end when you want to divide (shift) by 512 (9 bits), as
the DAC is only 256 (bits).
Note some numbers are not precise above, I got lazy just using a calc, not integer math.
Regards, Dana.
|