summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemonchy2005-05-01 20:10:17 +0000
committerdemonchy2005-05-01 20:10:17 +0000
commit9bc7e5db8f294e14becaf23be6d59a0693ad36ed (patch)
treec0ee8bfba681bfe6af4967ada6e40775cc06655a
parentaf22488810653fdbc36f23a0cc622d371918a3ad (diff)
Résolution du problème de décalage ADC.
-rw-r--r--n/avr/adc/adc.c32
-rw-r--r--n/avr/adc/adc.h6
-rw-r--r--n/avr/adc/test_adc.c5
3 files changed, 18 insertions, 25 deletions
diff --git a/n/avr/adc/adc.c b/n/avr/adc/adc.c
index e20a158..48137fb 100644
--- a/n/avr/adc/adc.c
+++ b/n/avr/adc/adc.c
@@ -33,6 +33,16 @@
# warning "adc: not tested on this chip."
#endif
+/* ADC configuration. */
+/* REFS = 01: AVCC with external capacitor at AREF pin.
+ * 11: Internal 2.56V Voltage Reference with external capacitor
+ * at AREF pin. */
+#define ADMUX_CFG (regv (REFS1, REFS0, ADLAR, MUX4, MUX3, MUX2, MUX1, MUX0, \
+ 1, 1, 0, 0, 0, 0, 0, 0))
+#define ADCSR_CFG (regv (ADEN, ADSC, ADATE, ADIF, ADIE, ADPS2, ADPS1, ADPS0, \
+ 1, 0, 0, 1, 0, 0, 0, 0))
+#define ADCSR_CFG_115200 7
+
/* +AutoDec */
/* -AutoDec */
@@ -40,28 +50,16 @@
void
adc_init (void)
{
- /* REFS = 01: AVCC with external capacitor at AREF pin.
- * 11: Internal 2.56V Voltage Reference with external capacitor
- * at AREF pin. */
- ADMUX = regv (REFS1, REFS0, ADLAR, MUX4, MUX3, MUX2, MUX1, MUX0,
- 1, 1, 0, 0, 0, 0, 0, 0);
- /* Adc enabled. */
- ADCSR = regv (ADEN, ADSC, ADATE, ADIF, ADIE, ADPS2, ADPS1, ADPS0,
- 1, 0, 0, 1, 0, 1, 1, 1);
-}
-
-/** Change channel. */
-void
-adc_mux (uint8_t c)
-{
- /* Choose adc. */
- ADMUX = (ADMUX & 0xe0) | (c & 0x07);
+ /* Low freq. */
+ ADCSR = ADCSR_CFG | ADCSR_CFG_115200;
}
/** Choose and start mesure on adc line. */
void
-adc_start (void)
+adc_start (uint8_t c)
{
+ /* Choose adc. */
+ ADMUX = ADMUX_CFG | (c & 0x07);
/* Start mesure. */
ADCSR |= _BV (ADSC);
}
diff --git a/n/avr/adc/adc.h b/n/avr/adc/adc.h
index 05b6e19..8030fcd 100644
--- a/n/avr/adc/adc.h
+++ b/n/avr/adc/adc.h
@@ -37,13 +37,9 @@
void
adc_init (void);
-/** Change channel. */
-void
-adc_mux (uint8_t c);
-
/** Choose and start mesure on adc line. */
void
-adc_start (void);
+adc_start (uint8_t c);
/* -AutoDec */
diff --git a/n/avr/adc/test_adc.c b/n/avr/adc/test_adc.c
index a8a9267..0e2d5f7 100644
--- a/n/avr/adc/test_adc.c
+++ b/n/avr/adc/test_adc.c
@@ -71,13 +71,12 @@ main (void)
/* Dmarre une acquisition de mesure sur l'adc 0. */
for (i = 0; i < 3; i ++)
{
- adc_mux (i);
- delay_ms (33L);
- adc_start ();
+ adc_start (i);
/* Attente active sur adc jusqu'a ce que la valeur soit
* disponible. */
while (adc_checkf())
;
+ delay_us (250L);
/* Lit l'adc. */
adc[i] = adc_read();
}