Download FINAL PROJECT REPORT
Transcript
Ecowatt
*
Returns :
None
*
*
Parameters :
char input
*
*
Purpose :
Initialize the ADC
with the selected ADC-channel
*
***************************************
**************************************/
void ADC_init(char input)
{
ADMUX = input;
// external
AREF and ADCx
ADCSRA = (1<<ADEN) | (1<<ADPS1) |
(1<<ADPS0);
// set ADC prescaler to
, 1MHz / 8 = 125kHz
input = ADC_read();
//
dummy
}
/**************************************
***************************************
*
*
Function name : ADC_read
*
*
Returns :
int ADC
*
*
Parameters :
None
*
*
Purpose :
Do a Analog to
Digital Conversion
*
***************************************
**************************************/
int ADC_read(void)
{
char i;
int ADC_temp;
int ADCr = 0;
// To save power, the voltage over
the LDR and the NTC is turned off when
not used
// This is done by controlling the
voltage from a I/O-pin (PORTF3)
sbi(PORTF, PORTF3);
the VCP (VC-peripheral)
sbi(DDRF, PORTF3);
// Enable
sbi(ADCSRA, ADEN);
the ADC
// Enable
//do a dummy readout first
ADCSRA |= (1<<ADSC);
// do
single conversion
while(!(ADCSRA & 0x10));
// wait
for conversion done, ADIF flag active
for(i=0;i<8;i++)
// do
the ADC conversion 8 times for better
accuracy
{
ADCSRA |= (1<<ADSC);
//
do single conversion
while(!(ADCSRA & 0x10));
//
wait for conversion done, ADIF flag
active
ADC_temp = ADCL;
read out ADCL register
ADC_temp += (ADCH << 8);
read out ADCH register
//
//
ADCr += ADC_temp;
//
accumulate result (8 samples) for later
averaging
}
ADCr = ADCr >> 3;
the 8 samples
// average
cbi(PORTF, PORTF3);
the VCP
cbi(DDRF, PORTF3);
// disable
cbi(ADCSRA, ADEN);
the ADC
// disable
return ADCr;
}
/**************************************
***************************************
*
*
Function name : ADC2Temp
*
*
Returns :
nothing
*
*
Parameters :
char log (char to
log to rs232 else print to screen)
*
int
ADCResult (ADC reading to convert)
*
*
Purpose :
Convert an ADC
reading into a temp
*
***************************************
**************************************/
void ADC2Temp(int ADCresult)
{
//
int ADCresult = 0;
//
int ADCresult_temp = 0;
int Temp_int=0;
int dif;
int top;
char Temp;
unsigned char i = 0;
char TL;
105