[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] ADC usage on AT90S4433
From: |
Urs Seiler |
Subject: |
[avr-gcc-list] ADC usage on AT90S4433 |
Date: |
Wed, 08 May 2002 01:03:01 +0200 |
All,
Using the AT90S4433 I am trying to convert analogue signals to digital. I found
some examples on the web. One of them I implemented in the short test code
below (suggested from
Bernie about one year ago). I also used a code using the interrupts; both are
not working and behave the same way. Reading the datasheet I do not see a
reason why it should not
work. What happens:
Function "blink" lights a light for a short while. This happens three times, in
other words twice before the loop and one before the ADC starts but it does
never come out of the while
loop in function"readADC".
I am using AVR-GCC for Windows
Does anyone have a suggestion?
ThanX in advance
Urs
#include <io.h>
#include <sig-avr.h>
unsigned int iid,id,jd;
unsigned int v_ADC_data;
void delay_ds (unsigned char s) {
for (iid=0;iid<s;iid++){
for (id=0;id<60300;id++){
jd++;
}
}
}
void blink(unsigned char l) {
if (l==3) {
sbi (PORTB,5);
delay_ds(3);
cbi (PORTB,5);
delay_ds(3);
} else {
sbi (PORTB,3);
delay_ds(3);
cbi (PORTB,3);
delay_ds(3);
}
}
void ioinit(void) {
/* output = 1 input =0 */
outp(0x2a, DDRB); // X X 1 0 1 0 1 0 -> 0x2A
// PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0
outp(0x15, PORTB); // X X 0 1 0 1 0 1 -> 0x15
outp(0x0, DDRC); // X X 0 0 0 0 0 0 -> 0x0
// PC7 PC6 PC5 PC4 PC3 PC2 PC1 PC0
outp(0x0, PORTC); // X X 0 0 0 0 0 0 -> 0x0
// hint: 0x40 = D6
outp(0xc2, DDRD); // 1 1 0 0 0 0 1 0 -> 0xC2
// PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0
outp(0x38,PORTD); // 0 0 1 1 1 0 0 0 -> 0x38
}
/* reurns the analog input channel ch */
int readADC(unsigned char ch){
if(ch<=7) outp(ch,ADMUX);
outp((((1<<ADEN)|(1<<ADSC))+7),ADCSR); /* Sets ADEN and ADSC and
selects the slowest AD-conversation rate
*/
blink (2);
while((unsigned char)(inp(ADCSR)&& (1<<ADSC))){
/* wait for the ADC to do it's stuff.*/
asm volatile ("nop");
}
blink(2);
return (ADCL+(ADCH*256));
}
int main(void)
{
ioinit();
blink(1);
outp((((1<<ADEN)|(1<<ADSC))+7),ADCSR);
blink(1);
for (;;) {
v_ADC_data = readADC(0);
} /* loop forever */
}
avr-gcc-list at http://avr1.org
- [avr-gcc-list] ADC usage on AT90S4433,
Urs Seiler <=