summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschodet2005-05-01 14:59:03 +0000
committerschodet2005-05-01 14:59:03 +0000
commit7bed3836db97e3c626a604cbe8b10c49236bb724 (patch)
tree491dff55fa30c0f23bd812f31612ceade1e05d0a
parentad45b4df5face15604b44f47f9b086063df477bb (diff)
Correction du problème de plantage.
ADC clock à 115200 Hz.
-rw-r--r--n/avr/adc/adc.c35
-rw-r--r--n/avr/adc/adc.h24
-rw-r--r--n/avr/adc/test_adc.c5
3 files changed, 28 insertions, 36 deletions
diff --git a/n/avr/adc/adc.c b/n/avr/adc/adc.c
index 7f6ee52..e20a158 100644
--- a/n/avr/adc/adc.c
+++ b/n/avr/adc/adc.c
@@ -23,7 +23,6 @@
#include "adc.h"
#include "n/avr/utils/utils.h"
-#include <avr/io.h>
#include <avr/signal.h>
/* Tested AVR check. */
@@ -34,11 +33,6 @@
# warning "adc: not tested on this chip."
#endif
-/* Different name on ATmega8535. */
-#if defined (__AVR_ATmega8535__)
-#define ADCSR ADCSRA
-#endif
-
/* +AutoDec */
/* -AutoDec */
@@ -53,33 +47,22 @@ adc_init (void)
1, 1, 0, 0, 0, 0, 0, 0);
/* Adc enabled. */
ADCSR = regv (ADEN, ADSC, ADATE, ADIF, ADIE, ADPS2, ADPS1, ADPS0,
- 1, 0, 0, 0, 0, 0, 0, 0);
+ 1, 0, 0, 1, 0, 1, 1, 1);
}
-/** Choose and start mesure on adc line. */
+/** Change channel. */
void
-adc_start (uint8_t d)
+adc_mux (uint8_t c)
{
/* Choose adc. */
- ADMUX &= 0xe0;
- ADMUX |= d & 0x07;
- /* Clear ADIF. */
- ADCSR = ADCSR;
- /* Start mesure. */
- ADCSR |= _BV (ADSC);
-}
-
-/** Return a value different of zero if finished. */
-uint8_t
-adc_checkf (void)
-{
- return !(ADCSR & _BV (ADSC));
+ ADMUX = (ADMUX & 0xe0) | (c & 0x07);
}
-/** Read mesure. */
-uint16_t
-adc_read (void)
+/** Choose and start mesure on adc line. */
+void
+adc_start (void)
{
- return ADCW;
+ /* Start mesure. */
+ ADCSR |= _BV (ADSC);
}
diff --git a/n/avr/adc/adc.h b/n/avr/adc/adc.h
index 57df73a..05b6e19 100644
--- a/n/avr/adc/adc.h
+++ b/n/avr/adc/adc.h
@@ -24,6 +24,12 @@
* }}} */
#include <inttypes.h>
+#include <avr/io.h>
+
+/* Different name on ATmega8535. */
+#if defined (__AVR_ATmega8535__)
+#define ADCSR ADCSRA
+#endif
/* +AutoDec */
@@ -31,18 +37,20 @@
void
adc_init (void);
-/** choose and start mesure on adc line */
+/** Change channel. */
+void
+adc_mux (uint8_t c);
+
+/** Choose and start mesure on adc line. */
void
-adc_start (uint8_t d);
+adc_start (void);
+
+/* -AutoDec */
/** check on finish mesure */
-uint8_t
-adc_checkf (void);
+#define adc_checkf() bit_is_set (ADCSR, ADIF)
/** read mesure */
-uint16_t
-adc_read (void);
-
-/* -AutoDec */
+#define adc_read() ADCW
#endif /* adc_h */
diff --git a/n/avr/adc/test_adc.c b/n/avr/adc/test_adc.c
index b7ab6bb..a8a9267 100644
--- a/n/avr/adc/test_adc.c
+++ b/n/avr/adc/test_adc.c
@@ -71,11 +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 (i);
+ adc_start ();
/* Attente active sur adc jusqu'a ce que la valeur soit
* disponible. */
- while (adc_checkf() !=0)
+ while (adc_checkf())
;
/* Lit l'adc. */
adc[i] = adc_read();