реклама на сайте
подробности

 
 
> AVR ADC 10 bit ,help me
vanduongbk
сообщение Apr 2 2011, 03:49
Сообщение #1


Частый гость
**

Группа: Участник
Сообщений: 82
Регистрация: 22-12-10
Пользователь №: 61 811



I write program convert adc 10 bit and results to led ,it operates accuracy but i have a problem while simulation by protues ,it appears warning as below ,i dont know it operate or not in real circuit ,please help me

this is warning

Прикрепленное изображение


and this is code

Прикрепленное изображение


and I want to ask how I can transfer this 10 bit once time to pc through rs232
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
Son Of Stone
сообщение Apr 2 2011, 07:35
Сообщение #2


Участник
*

Группа: Участник
Сообщений: 36
Регистрация: 29-01-09
Пользователь №: 44 106



Цитата
how I can transfer this 10 bit once time to pc through rs232

ATmega's UART allows sending from 5 to 9 data bits at once (in one frame). Best frame format for communication with PC (using hardware RS232 or USB-TO-COM adapter) is 8 data bits and 1 stop bit. You should send ADC conversion result in two frames using "USART Data Register
Empty (UDRE) Interrupt" (Page 150 in datasheet). Example:

Код
/*****************************************************
Chip type           : ATmega16
Program type        : Application
Clock frequency     : 14,745600 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/
#include <mega16.h>
register unsigned char ADCH_, ADCL_; //Plase variables in working registers for fast access to them

// ADC interrupt service routine
interrupt [ADC_INT] void adc_isr(void)
{
ADCL_ = ADCL;
ADCH_ = ADCH; //Right order to read ADC result!
//Preparing data to transmission
ADCH_<<=3;
ADCH_|=ADCL_>>5;
ADCL_&=0x1F;
//Now we have 5 higher bits of the result in ADCH_ and 5 lower bits of result in ADCL_;
ADCH_|=0x80; //Set MSB in ADCH_ in 1 for correct handling recived data on PC
//Start Transmission!
UDR=ADCH_;
UCSRB=0x28;//UDRE interrupt enabled
}

// USART Transmitter interrupt service routine
interrupt [USART_DRE] void usart_tx_udre(void)
{
UDR=ADCL_;
UCSRB=0x08;   //UDRE interrupt disabled
ADCSRA|=0x40; //Start next ADC conversion!!;
}

void main(void)
{
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On, UDRE int. On
// USART Mode: Asynchronous
// USART Baud Rate: 57600
UCSRA=0x00;
UCSRB=0x08; //TXEN=1;
UCSRC=0x86; //8-bit frame
UBRRH=0x00;
UBRRL=0x0F;
//ADC initialization
ADMUX=0xC0; // ADC Voltage Reference: Int., cap. on AREF, INPUT=PORTA.0
ADCSRA=0xCF; // ADC Clock frequency: 115,200 kHz, START FIRST CONVERSION
#asm("sei")
while (1);
}


P. S. Van Duong, are you from Vietnam? I glad to see vietnamese man on this forum!
My e-mail is KT829A[dog]yahoo[dot]com. Also i use YahooMessanger with this Yahoo ID. Any messages welcome!
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 31st July 2025 - 21:14
Рейтинг@Mail.ru


Страница сгенерированна за 0.01398 секунд с 7
ELECTRONIX ©2004-2016