Skip to content
Snippets Groups Projects
Commit 99270fa2 authored by Ben Z Yuan's avatar Ben Z Yuan
Browse files

update for xmega proto1

parent 19de9d82
No related branches found
No related tags found
No related merge requests found
File added
...@@ -133,16 +133,16 @@ void ADC_Init() ...@@ -133,16 +133,16 @@ void ADC_Init()
ADCA.CTRLA = ADC_ENABLE_bm; // enabled, no DMA, no started conversion, no flush ADCA.CTRLA = ADC_ENABLE_bm; // enabled, no DMA, no started conversion, no flush
ADCA.CTRLB = (1<<4); // high impedance, no limit, signed, non-freerunning, 12-bit right ADCA.CTRLB = (1<<4); // high impedance, no limit, signed, non-freerunning, 12-bit right
ADCA.REFCTRL = ADC_BANDGAP_bm; // Internal 1v ref ADCA.REFCTRL = (ADC_REFSEL1_bm) | (ADC_REFSEL0_bm); // AREFB
ADCA.EVCTRL = 0 ; // no events ADCA.EVCTRL = 0 ; // no events
ADCA.PRESCALER = ADC_PRESCALER_DIV4_gc ; ADCA.PRESCALER = ADC_PRESCALER_DIV64_gc ;
ADCA.CALL = ReadSignatureByte(0x20) ; //ADC Calibration Byte 0 ADCA.CALL = ReadSignatureByte(0x20) ; //ADC Calibration Byte 0
ADCA.CALH = ReadSignatureByte(0x21) ; //ADC Calibration Byte 1 ADCA.CALH = ReadSignatureByte(0x21) ; //ADC Calibration Byte 1
_delay_us(400); // Wait at least 25 clocks _delay_us(400); // Wait at least 25 clocks
ADCA.CH0.CTRL = ADC_CH_GAIN_1X_gc | 1; ADCA.CH0.CTRL = ADC_CH_GAIN_4X_gc | ADC_CH_INPUTMODE_DIFFWGAIN_gc;
ADCA.CH0.MUXCTRL = 0; // ADC0 ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN0_gc | ADC_CH_MUXNEG_PIN4_gc;
ADCA.CH0.INTCTRL = 0; // no interrupt ADCA.CH0.INTCTRL = 0; // no interrupt
} }
...@@ -150,22 +150,21 @@ int32_t ADC_Read(void) ...@@ -150,22 +150,21 @@ int32_t ADC_Read(void)
{ {
int32_t res = 0; int32_t res = 0;
// throw away 5 readings and average the next 128 (software denoising attempt) // throw away 1 reading and take the next one
for(uint8_t i = 0; i < 5; i++) { //for(uint8_t i = 0; i < 1; i++) {
ADCA.CH0.CTRL |= ADC_CH_START_bm; // Start conversion ADCA.CH0.CTRL |= ADC_CH_START_bm; // Start conversion
while (ADCA.INTFLAGS==0) ; // Wait for complete while (ADCA.INTFLAGS==0) ; // Wait for complete
ADCA.INTFLAGS = ADCA.INTFLAGS ; // writing 1 to INTFLAGS clears it ADCA.INTFLAGS = ADCA.INTFLAGS ; // writing 1 to INTFLAGS clears it
} //}
for(uint8_t i = 0; i<128; i++) //for(uint8_t i = 0; i < 1; i++) {
{ ADCA.CH0.CTRL |= ADC_CH_START_bm; // Start conversion
ADCA.CH0.CTRL |= ADC_CH_START_bm; // Start conversion while (ADCA.INTFLAGS==0) ; // Wait for complete
while (ADCA.INTFLAGS==0) ; // Wait for complete ADCA.INTFLAGS = ADCA.INTFLAGS ; // writing 1 to INTFLAGS clears it
ADCA.INTFLAGS = ADCA.INTFLAGS ; // writing 1 to INTFLAGS clears it res = ADCA.CH0RES;
res += ADCA.CH0RES; //}
} return res;
return res >> 7;
} }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ /** Configures the board hardware and chip peripherals for the demo's functionality. */
......
...@@ -49,3 +49,6 @@ program-dfu: $(TARGET).hex ...@@ -49,3 +49,6 @@ program-dfu: $(TARGET).hex
program-avrisp2: $(TARGET).hex program-avrisp2: $(TARGET).hex
avrdude -p $(MCU) -c avrisp2 -U flash:w:$(TARGET).hex avrdude -p $(MCU) -c avrisp2 -U flash:w:$(TARGET).hex
program-avrisp2-dfu-fuses:
avrdude -p $(MCU) -c avrisp2 -U fuse2:w:0xBF:m
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment