Hi there I am a newbie who is very lost in programming this adc. I am using AVR162 but any experience and advice on how to work with this sort of adc is very much appreciated.
I have tried all possible ways that I can think of to make it work but still.. I am lost.. and desperate.
These are few codes that I attempted.
#include#include #include #define F_CPU 1000000UL volatile unsigned char RDY_FLG= 0x00; volatile unsigned char SCLK_FLG = 0x00; // sclk flag long char data = 0; int k; void init (void) { DDRC = 0x00; // PORTC is input (PINC1 <-- DRDY/ DOUT) DDRB = 0xFF; // PORTB is output (PORTB0 --> CLK of ADC ; PORTB1--> SCLK of ADC) DDRA = 0xFF; // PORTA is output (PORTA0 --> output to memory) PORTA = 0x00; PORTB = 0x00; TCCR1B |= (1 << CS10); // Set up timer while (TCNT1 <= 2304) //reset adc { PORTB |= 0x02; //SCLK high for 6 conversion cycles +1 to reset } PORTB &= ~0x02; MCUCR |= 0x03; // set up interrupt (0x03 shows rising edge interrupt) GICR |= 0x40; //enable pin INT0 for use sei(); } ISR (INT0_vect) { //interrupt function with its vector RDY_FLG = 0xFF; cli(); //disable interrupt } int main (void) { //DDRB = 0xFF; // PORTB is output //PORTB = 0x00; //TCCR1B |= (1 << CS10); // Set up timer while (1) { if (RDY_FLG == 0xFF) { TCNT1 = 0; // Reset timer value while (TCNT1 <= 37) {} TCNT1 = 0; // Reset timer value SCLK_FLG = 0xFF; while (TCNT1 <= 348) { /*if (TCNT1 <= 240) { for (k=23; k>=0; k--) { PORTB |=0X02; data |= (PINC1<<k); PORTA = (data << 0); _delay_us (0.3125); PORTB &=~0x02; _delay_us (0.3125); } } else {*/ PORTA |= 0x02; PORTB |=0X02; _delay_us (0.3125); PORTB &=~0x02; _delay_us (0.3125); //} //} } PORTA &= ~0x02; RDY_FLG = 0x00; //reset RDY_FLG after 1 conversion cycle sei(); // re- activate interrupt } } return(0); }
#include#include #define F_CPU 1000000UL //volatile unsigned char RDY, data; volatile unsigned char data [1] [24]; volatile unsigned char RDY; void init (void) { DDRC = 0x00; // PORTC is input DDRB = 0xFF; // PORTB is output DDRA = 0xFF; // PORTA is output PORTA = 0x00; PORTB = 0x00; TCCR1B |= (1 << CS10); // Set up timer while (TCNT1 <= 2304) //reset adc { PORTB |= 0x02; //SCLK high for 6 conversion cycles +1 to reset } PORTB &= ~0x02; MCUCR |= 0x03; // set up interrupt (0x03 shows rising edge interrupt) GICR |= 0x40; //enable pin INT0 for use sei(); } ISR (INT0_vect) { //interrupt function with its vector RDY = 0xFF; cli(); //disable interrupt } int main (void) { int k; init(); while (1) { if (RDY == 0xFF) { //data = 0x00; TCNT1 = 0; // Reset timer value while (TCNT1 <= 37) {} /* for (k=23; k>=0; k--) { data = (PINC0 <<k); PORTB ^= (1<<1); PORTB |= 0x02; PORTB &= ~0x02; } PORTA0 = data; */ for (k=23; k>=0; k--) { PORTA = PINC0; PORTB ^= (1<<1); } RDY = 0x00; sei(); } } return(0); }
I have been wondering at the same point for weeks and I am still here. Please help me. Many thanks in advanced.