Getting Started

(lily) #1

Chapter 9 – Digital Meets Analog – ADC and DAC


ave included a voltage inverter circuit that looked like a prime candidate to
bine with a voltage on the Voltage In pin

h
radiate messy voltages that might com
and might, theoretically, cause a problem. So I changed PC_Comm so that it sent
the PC a ‘!’ every time it received a character. In HyperTerminal I got:


So after requesting ‘volt’ the Butterfly was no longer exclaiming with a ‘!’ but
ecided it wanted to play cards with a black club, or perhaps more reasonably, I
g scrambled on reception by the PC because the Baud rate
’ve seen that happen before). So I reread the data sheet on the
with the Butterfly schematics and tried a few coding
ill no fix. I messed with the USART initialization
on function, the ADC read function, the oscillator


r

in front of a line) to see
ventually I got to the getVolt function and
ch time you
nt something out, you have to recompile, load, and test the code. It takes a

0'};

d
thought, the ‘!’ was bein
had changed (I
USART and diddled
changes. Hours passed and st
function, the ADC initializati
calibration function and generally had myself a merry old goose chase for about
half a day. Nothing fixed the problem, but at least the Butterfly didn’t explode no
make the least bit of smoke, the code was consistently responding with a black
club rather than the ‘!’ but at least it was running.


Finally, in total desperation, I tried what I should have tried in the first place. I
bracketed code by commenting out sections (putting //
where exactly the problem occurred. E
started commenting out sections. This is a time consuming process, ea
comme
while. So here is the getVolt code:


void getVolt()
{
char voltintpart[]= {''0','\
char voltfractpart[]= {'0','\0'};
int intpart = 0;
int fractpart = 0;
int ADCresult = 0;


ADCresult = ADC_read();
intpart = ADCresult/50;

Free download pdf