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

 
 
> 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
Ответов (1 - 12)
TVF
сообщение Apr 2 2011, 04:49
Сообщение #2


Участник
*

Группа: Участник
Сообщений: 16
Регистрация: 5-12-09
Пользователь №: 54 076



Datasheet page 214: "ADCL must be read first, then ADCH"


Цитата(vanduongbk @ Apr 2 2011, 06:49) *
and I want to ask how I can transfer this 10 bit once time to pc through rs232

impossible

Сообщение отредактировал TVF - Apr 2 2011, 04:51
Go to the top of the page
 
+Quote Post
Son Of Stone
сообщение Apr 2 2011, 07:35
Сообщение #3


Участник
*

Группа: Участник
Сообщений: 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
_Pasha
сообщение Apr 3 2011, 04:38
Сообщение #4


;
******

Группа: Участник
Сообщений: 5 646
Регистрация: 1-08-07
Пользователь №: 29 509



BTW avr DLL is slightly mature in your installation, most recent is 7.7SP0 build 9076.
But, as mentioned before, the key problem is an order of reading ADCL:ADCH
Go to the top of the page
 
+Quote Post
vanduongbk
сообщение Apr 3 2011, 06:19
Сообщение #5


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

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




thank you very much for your best reply
yes ,i come from vietnamese , your id is KT829A
thank again

Цитата(_Pasha @ Apr 3 2011, 11:38) *
BTW avr DLL is slightly mature in your installation, most recent is 7.7SP0 build 9076.
But, as mentioned before, the key problem is an order of reading ADCL:ADCH


i am using protues 7.5 sp3
i dont know where i can download 7.7 full ,please help me

Сообщение отредактировал IgorKossak - Apr 3 2011, 18:34
Причина редактирования: ridiculous quoting
Go to the top of the page
 
+Quote Post
_Pasha
сообщение Apr 3 2011, 07:26
Сообщение #6


;
******

Группа: Участник
Сообщений: 5 646
Регистрация: 1-08-07
Пользователь №: 29 509



Check your private mail box
Go to the top of the page
 
+Quote Post
vanduongbk
сообщение Apr 5 2011, 07:08
Сообщение #7


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

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



and now i only use adc bit ,i transmit data to pc but how i can plot graph from this data which x -axis is time and y -axis is data in voltage
please help me in any programming as VB,VC ,matlab .....
Go to the top of the page
 
+Quote Post
_Pasha
сообщение Apr 5 2011, 08:25
Сообщение #8


;
******

Группа: Участник
Сообщений: 5 646
Регистрация: 1-08-07
Пользователь №: 29 509



Цитата(vanduongbk @ Apr 5 2011, 10:08) *
please help me in any programming as VB,VC ,matlab .....

Maybe you can store data in *.csv format and then import in excel or open office calc to build diagram. That's the simplest way. But...Are you need to plot in a realtime?
P.S. I found in my archives the following link oscilloscope lib
Look at this. Perhaps it is very helpful
Go to the top of the page
 
+Quote Post
vanduongbk
сообщение Apr 6 2011, 05:04
Сообщение #9


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

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



yes i need to plot it in real time ,please help me ,if can please in vc or vb thank again

you can help me about using Universal Real-Time Software Oscilloscope GUI DLL Library

Сообщение отредактировал vanduongbk - Apr 6 2011, 05:05
Go to the top of the page
 
+Quote Post
fest
сообщение Apr 6 2011, 06:34
Сообщение #10





Группа: Новичок
Сообщений: 5
Регистрация: 5-10-10
Пользователь №: 59 936



i have code work with rs232 in borland delphi. you can translate it to whatever you need.
CODE

unit Unit33;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
Label2: TLabel;
Label1: TLabel;
Timer2: TTimer;
Image1: TImage;
procedure FormCreate(Sender: TObject);
procedure q(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
hcom,houtfile: thandle;
dcb: tdcb;
stat: tcomstat;
lock: bool;
bytecount: dword;
databuf, x: byte;
const bufsize=sizeof(databuf);
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
x:=0;
stat.cbInQue:=0;
bytecount:=0;
lock:=true;
hcom:=createfile('com3',generic_read or generic_write,0,nil,open_existing,file_attribute_normal,0);
if hcom=invalid_handle_value then begin
showmessage('can''t open port');
application.Terminate;
end;
setupcomm(hcom,1600,1600);
with dcb do begin
baudrate:=57600;
bytesize:=8;
parity:=noparity;
stopbits:=onestopbit;
end;
if not setcommstate(hcom,dcb) then begin
showmessage('can''t set port');
application.Terminate;
end;
houtfile:=createfile('out.txt',generic_read or generic_write,0,nil,open_always,
file_attribute_normal,0);
if houtfile=invalid_handle_value then begin
showmessage('can''t open out file');
application.Terminate;
end;
lock:=false;
end;

procedure TForm1.q(Sender: TObject; var Action: TCloseAction);
begin
closehandle(houtfile);
closehandle(hcom);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var i,blocks,errors,bytes: dword;
begin
if not lock then begin
lock:=true;
clearcommerror(hcom,errors,@stat);
blocks:=stat.cbInQue div bufsize;
if blocks>0 then begin
for i:=1 to blocks do begin
if not readfile(hcom,databuf,bufsize,bytes,nil)
then beep;
writefile(houtfile,databuf,bufsize,bytes,nil);
inc(bytecount,bytes);
image1.Canvas.Pixels[x, 255-databuf]:=0;
inc(x);
if (x > 340) then x:=0;
end;
flushfilebuffers(houtfile);
end;
label1.Caption:='read '+inttostr(blocks)+
' blocks. write in file '+inttostr(bytecount)+' bytes';
form1.Caption:=datetimetostr(date+time);
lock:=false;
end;
end;

end.


Сообщение отредактировал IgorKossak - Apr 6 2011, 07:06
Причина редактирования: Use [codebox] tags
Go to the top of the page
 
+Quote Post
_Pasha
сообщение Apr 6 2011, 06:48
Сообщение #11


;
******

Группа: Участник
Сообщений: 5 646
Регистрация: 1-08-07
Пользователь №: 29 509



Цитата(vanduongbk @ Apr 6 2011, 08:04) *
you can help me about using Universal Real-Time Software Oscilloscope GUI DLL Library

I didn't test it, but it's time to read examples attached sm.gif
Go to the top of the page
 
+Quote Post
vanduongbk
сообщение Apr 7 2011, 02:26
Сообщение #12


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

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



Цитата(fest @ Apr 6 2011, 13:34) *


thank you for this help but i cant know borland delphi language because i am not learnt this language

Сообщение отредактировал IgorKossak - Apr 7 2011, 07:19
Причина редактирования: overquoting
Go to the top of the page
 
+Quote Post
defunct
сообщение Apr 7 2011, 21:44
Сообщение #13


кекс
******

Группа: Свой
Сообщений: 3 825
Регистрация: 17-12-05
Из: Киев
Пользователь №: 12 326



Цитата(vanduongbk @ Apr 7 2011, 05:26) *
not learnt this language

Time to learn it then sm.gif
Borland C++ Builder uses the same set of VCL components as Delphi. I'd suggest to get Borland C++ Builder 6.0 and to have a look at the "chart" component example there.
Its pretty simple to draw graphics with it. Much simpler than in stupid vc.
All what you'd need to get done is to launch C++ Builder, find "Chart" component on the components toolbar in "Additional" section, put "Chart" component on the application form, setup needed parameters width/ height / color / font size etc, then periodically re-load actual values gotten from COM port into it in real time. It shall draw graphic and scale automatically.

If you'd find "Chart" is not what you're looking for (e.g. too slow or too smart sm.gif ), you may refer to more stupid "Image" component example. In the "Image" you're allowed to draw graphic primitives(pixels, lines, circles etc) manually, like follows:

Image1->Canvas->pixels[x, y] = color;

note: referring directly to pixels[] array would work slower compared to drawing graphic with advanced func primitives - line(), rect(), arc() etc.

fest already showed how simple the program may be on Delphi. Same size program will be in C++ Builder just different lang.
btw, there is nothing complex in reading Delphi, below are several compliances b/w those langs, which would allow you to read fest's example:

Код
deplhi               C

begin              -  {
end                -  }
:=                 -  =
integer(x)         -  (int)x
var x,y : integer; -  int x, y;

if condition then  -  if (condition)
  operator1              operator1;
else                  else
  operator2;             operator2;

Form1.Image1       -  Form1->Image1
not                -  !
or                 -  ||
and                -  &&
Go to the top of the page
 
+Quote Post

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

 


RSS Текстовая версия Сейчас: 20th July 2025 - 22:47
Рейтинг@Mail.ru


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