- adc is event based

- changed timer frequency
- prepared for SW timer
- added PowerSwitch_in


git-svn-id: http://moon:8086/svn/projects/HendiControl@30 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
2019-02-28 19:18:40 +00:00
parent a22ffe8384
commit 8a8bb762e0
7 changed files with 133 additions and 82 deletions
+33 -2
View File
@@ -5,19 +5,40 @@
* Author: jens
*/
#include <stddef.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "adc.h"
#include "message.h"
void adc_init()
static int16_t adc_value[16];
static size_t adc_ch = 0;
static Fifo *g_pFifo = NULL;
ISR(ADC_vect)
{
int16_t value_low = (int16_t)ADCL;
int16_t value_high = (int16_t)ADCH;
ADCSRA |= (1<<ADIF);
int16_t value = value_high << 8 | value_low;
adc_value[adc_ch] = value;
Msg_t msg = {AdcComplete, adc_getChannel()};
fifo_push(g_pFifo, &msg);
}
void adc_init(Fifo *pFifo)
{
g_pFifo = pFifo;
PRR &= ~(1 << PRADC);
ADCSRA |= (1 << ADEN) | 7;
}
void adc_start_conversion(int ch)
void adc_start_conversion(size_t ch)
{
ADMUX = (ADMUX & 0xF0) | (ch & 0x0F) | (1 << REFS0);
ADCSRA |= (1 << ADSC) | (1 << ADIE);
adc_ch = ch & 0x0F;
}
int adc_is_fininshed()
@@ -25,3 +46,13 @@ int adc_is_fininshed()
return (int)(0 == (ADCSRA & (1 << ADSC)));
}
size_t adc_getChannel()
{
return adc_ch;
}
int16_t adc_getData()
{
return adc_value[adc_ch];
}