ruchirvn
Newbie level 4
Hi,
I am interfacing 12 bit ADC 7109 with Atmega32.I am converting 12 bit ADC data in to serial form and then transmitting using wireless module TX 433 and at the receiver side after receiving I am displaying corresponding decimal value using ATmega32 micro-controller only.The baud rate set for ATmega32 is 800bps,but at the receiver side the in the display unit data is updating very slowly it is taking longer time to display proper value of the decimal equivalent of sending data i.e. it takes longer time to settle down.
I cant use inbuilt ADC of ATmega32 because i need 12 bit data at the output.
Kindly tell me the solution for this.
my TX and Rx side codes are given below
Rx side code
TX side code
Thanks
Ruchir
I am interfacing 12 bit ADC 7109 with Atmega32.I am converting 12 bit ADC data in to serial form and then transmitting using wireless module TX 433 and at the receiver side after receiving I am displaying corresponding decimal value using ATmega32 micro-controller only.The baud rate set for ATmega32 is 800bps,but at the receiver side the in the display unit data is updating very slowly it is taking longer time to display proper value of the decimal equivalent of sending data i.e. it takes longer time to settle down.
I cant use inbuilt ADC of ATmega32 because i need 12 bit data at the output.
Kindly tell me the solution for this.
my TX and Rx side codes are given below
Rx side code
Code:
#define __AVR_ATmega16__ 1
#define OSCSPEED 8000000 /* in Hz */
#include "avr/io.h"
void Initialize(void)
{
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
DDRA = 0XFF;
DDRB = 0xFF;
DDRC = 0xFF;
DDRD = 0x00;
}
void UARTInit(uint32_t Baud)
{
unsigned int BaudRate = OSCSPEED / (16 * Baud) - 1;
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH = (unsigned char) (BaudRate>>8);
UBRRL = (unsigned char) BaudRate;
}
unsigned char usart_receive( void )
{
unsigned char data;
while ((UCSRA & 0x80) == 0x00); // Wait for till the data arrives data
data=UDR; // Read the data from UDR, as soon as the data arrives
return data;
}
int main()
{
int i;
unsigned char ch,ch1;
Initialize();
UARTInit(800);
while (1)
{
ch = usart_receive();
ch1 = usart_receive();
PORTB = ch1;
PORTC = ch;
//PORTC = ch1;
}
}
TX side code
Code:
#define OSCSPEED 8000000
#include <avr/io.h>
#include <util/delay.h>
void Initialize(void)
{
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
DDRA = 0XFF;
DDRB = 0xF0;
DDRC = 0xFF;
DDRD = 0x00;
}
void UARTInit(uint32_t Baud)
{
unsigned int BaudRate = OSCSPEED / (16 * Baud) - 1;
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH = (unsigned char) (BaudRate>>8);
UBRRL = (unsigned char) BaudRate;
}
unsigned char usart_receive( void )
{
unsigned char data;
while ((UCSRA & 0x80) == 0x00); // Wait for till the data arrives data
data=UDR; // Read the data from UDR, as soon as the data arrives
return data;
}
int main(void)
{
unsigned char ch=0x00,ch1=0x00;
unsigned int a,b,c,d,e,f,g,h,i;
unsigned char c1,c2,c3,c4;
Initialize();
UARTInit(800);
while(1)
{
ch = usart_receive();
if((ch & 0xF0) == 0x00)
{
ch1 = usart_receive();
a=ch;
b=ch1;
c = 256*a;
d=c+b;
i = d;
e = d%10;
c1 = func(e);
d = d/10;
f = d%10;
c2 = func(f);
d = d/10;
g = d%10;
c3 = func(g);
d = d/10;
h = d%10;
c4 = func(h);
PORTB = 0x80;
PORTA = c4;
_delay_ms(1);
PORTB = 0x40;
PORTA = c3;
_delay_ms(1);
PORTB = 0x20;
PORTA = c2;
_delay_ms(1);
PORTB = 0x10;
PORTA = c1;
_delay_ms(1);
}
else
{
PORTB = 0x80;
PORTA = 0xFC;
_delay_ms(1);
PORTB = 0x40;
PORTA = 0xFC;
_delay_ms(1);
PORTB = 0x20;
PORTA = 0xFC;
_delay_ms(1);
PORTB = 0x10;
PORTA = 0xFC;
_delay_ms(1);
}
}
}
func(unsigned int e)
{
unsigned char j;
switch(e)
{
case 0:
j = 0xFC;
break;
case 1:
j = 0x60;
break;
case 2:
j=0xDA;
break;
case 3:
j=0xF2;
break;
case 4:
j=0x66;
break;
case 5:
j=0xB6;
break;
case 6:
j=0xBE;
break;
case 7:
j=0xE0;
break;
case 8:
j=0xFE;
break;
case 9:
j=0xF6;
break;
default :
j=0xFC;
break;
}
return j;
}
Thanks
Ruchir
Last edited by a moderator: