You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.3 KiB
C

/*
* adc.c
*
* Created: 09/12/2021 16:31:16
* Author: n0x
*/
#include "adc.h"
#define myADC ((ADC_t*)(0x78))
void
adc_init(void)
{
myADC->uiADLAR = 0; /* Set ADLAR to 0 to not left adjust the presentation of the conversion result */
myADC->uiREFS = 0; /* Turn off reference Voltage */
myADC->uiADPS = 7; /* Set ADC Prescaler to 128 */
myADC->uiADIE = 1; /* Enable the ADC interrupt */
myADC->uiADATE = 0; /* Disable the ADC auto trigger */
myADC->uiADEN = 1; /* Enable ADC */
}
volatile int done = 1;
/* ADC 1 */
uint16_t
adc_get_poti(void)
{
uint16_t adc;
myADC->uiMUX = 1; /* Set ADMUX to access ADC channel 1 */
myADC->uiADSC = 1; /* Start the conversion */
done = 0; /* reset the done flag to false */
while(done == 0); /* Wait till conversion completes */
adc = myADC->uiADC;
return adc;
}
/* ADC 0 */
uint16_t
adc_get_LM35(void)
{
uint16_t adc;
//myADC->uiADIE = 0; /* Disable interrupt */
myADC->uiMUX = 0; /* Set ADMUX to access ADC channel 1 */
myADC->uiADSC = 1; /* Start the conversion */
done = 0; /* reset the done flag to false */
while(done == 0); /* Wait till conversion completes */
adc = myADC->uiADC;
//myADC->uiADIE = 1; /* Enable the interrupt again */
return adc;
}
ISR(ADC_vect){
done = 1; /* set the done flag to true */
}