Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Adc Pic16f877a

Status
Not open for further replies.
Try page 113 of the datasheet of PIC16F87xA.
I think there is no different between 877 and 877A in USART feature.

BTW, 50 Hz is not that high. You need to have at least 100 samples per second.
I've tried with 16F88, at 10 kHz and above, the quality start reducing because the acquisition time has already taken nearly 20 us, plus the conversion time taken nearly 12 x Tad.
 
bananasiong said:
Try page 113 of the datasheet of PIC16F87xA.
I think there is no different between 877 and 877A in USART feature.

BTW, 50 Hz is not that high. You need to have at least 100 samples per second.
I've tried with 16F88, at 10 kHz and above, the quality start reducing because the acquisition time has already taken nearly 20 us, plus the conversion time taken nearly 12 x Tad.

What baudrate did you use, and what XT are you using?
10khz for a sinewave is really big and i can't get 100 samples persecond if i am using 9600baudrate with 4Mhz crystal.. i have followed the page 113... for correct adc conversion
 
I was using the internal oscillator of 16F88, 8 MHz and baud rate set to 100k (I was doing UART from PIC to PIC). But I think with a 4 MHz crystal, the baud rate can be up to 250 k. Check page 113 for the baud rate calculation.
 
1)can it be said that the higher the baudrate, the higher my samples/second?

2)is there any reference or any link which i can get to check out my the relationship of baudrate with sampling time, etc.. using a pic?
 
i have changed my baudrate to 250k but then the serial com port of my pc cannot be opened, the com port baudrate is 230400 which is way lower than the 250k baudrate i set... how come the com port cannot be opened??
 
With the 877 you will only manage 19.2K baud (maybe 28.8) before the errors start getting too big. If you can you get hold of a 16F887 you will be able to run at 57.6K baud using the internal oscillator, possibly 115.2K. It is pin compatible with the 877.

Mike.
 
hi pommie,

so you were saying that with the 877, i can only manage up to 19.2k baud before the errors start to be big. This is when i'm using either one of the 20Mhz or a 4Mhz crystal?
 
Oh ya, the standard baud rate of the hyperterminal. I didn't use that.

derrick826 said:
1)can it be said that the higher the baudrate, the higher my samples/second?
No, they are two different things. Baudrate is the speed of USART/UART in PIC while the num. of sample/second is how fast can the PIC sample the analog signal of ADC.
 
derrick826 said:
hi pommie,

so you were saying that with the 877, i can only manage up to 19.2k baud before the errors start to be big. This is when i'm using either one of the 20Mhz or a 4Mhz crystal?

With a 20Mhz crystal you would probably be alright at 57.6K as the error is borderline at 3.3%. With the 887, 57.6K has an error of just 0.2%.

How are you receiving the values on the PC. Sending the values as hexadecimal followed by a cr would mean you could send 57600/10/4=1440 samples per second. Sending as binary would allow double this rate.

Mike.
 
I'm partial to using crystals that work really well with USARTs for the 16F877A 19.6608MHz is great for both RS232 and also an easy divisor for a real time clock. It's also a common crystal frequency.
 
Pommie said:
With a 20Mhz crystal you would probably be alright at 57.6K as the error is borderline at 3.3%. With the 887, 57.6K has an error of just 0.2%.

How are you receiving the values on the PC. Sending the values as hexadecimal followed by a cr would mean you could send 57600/10/4=1440 samples per second. Sending as binary would allow double this rate.

Mike.

well, what is being displayed in the hyper terminal is something like this:
1014

1002

0984

0963

as my TX code is in the following:

send
MOVFW thirty
ADDWF digit0,w
CALL TXRDY
MOVFW thirty
ADDWF digit1,w
CALL TXRDY
MOVFW thirty
ADDWF digit2,w
CALL TXRDY
MOVFW thirty
ADDWF digit3,w
CALL TXRDY
MOVLW .13 ;crlf
CALL TXRDY
MOVLW .10
CALL TXRDY

TXRDY:
BTFSS PIR1,TXIF
GOTO TXRDY;busy,so loop
XMIT1:
MOVWF TXREG;send
RETURN

YOU WERE SAYING about :With a 20Mhz crystal you would probably be alright at 57.6K as the error is borderline at 3.3%

but in my calculations, if i put SPBRG as 21,

20MHz / 16(21+1) = 56818 and my error is about 1.35%, how did you get 3.3%?

is the maximum error you can have is 3.3%, which is one third of the error percentage??
 
derrick826 said:
1)can it be said that the higher the baudrate, the higher my samples/second?

'Sort of' - the higher the baudrate the faster you can transfer the data.

2)is there any reference or any link which i can get to check out my the relationship of baudrate with sampling time, etc.. using a pic?

You hardly need a reference, the calculation is trivial!.

9600 baud is 9600 bits per second, each byte takes a minimum of ten bits - so that's a maximum of 960 bytes per second. Assuming you're taking 10 bit samples, you need two bytes to transfer it, which takes your maximum transfer rate to only 480 10 bit samples per second (unless you packet your samples).

Sampling time isn't a consideration, as you can sample while you're sending the previous data.
 
Nigel Goodwin said:
'Sort of' - the higher the baudrate the faster you can transfer the data.



You hardly need a reference, the calculation is trivial!.

9600 baud is 9600 bits per second, each byte takes a minimum of ten bits - so that's a maximum of 960 bytes per second. Assuming you're taking 10 bit samples, you need two bytes to transfer it, which takes your maximum transfer rate to only 480 10 bit samples per second (unless you packet your samples).

Sampling time isn't a consideration, as you can sample while you're sending the previous data.

Yea nigel, i get what you mean now, may i ask what is the max error you can get from the formula:

baudrate= OSC/ 16(SPBRG+1) for 1= BRGH

when compare to the original baudrate of the serial port?
 
derrick826 said:
Yea nigel, i get what you mean now, may i ask what is the max error you can get from the formula:

baudrate= OSC/ 16(SPBRG+1) for 1= BRGH

when compare to the original baudrate of the serial port?

It doesn't matter, it's not that critical - 9600 baud is even completely reliable using the internal 4MHz oscillator. If you want to know the error, just look in the datasheet where it lists them - the whole point of RS232 is that it syncronises every byte - so a slight error is no problem at all.
 
Nigel Goodwin said:
- the whole point of RS232 is that it syncronises every byte - so a slight error is no problem at all.

Only true if the bytes are sent one after another, with some spare times in between after the stop bit(s) and another start bit.

Otherwise, error in baudrate will be accumulative and eventually the UART sampling clocking will be off.

@derrick826: I get the same result of 1.3% error for 57.6K baud at 20MHz clock.
 
Last edited:
Nigel, i want to ask if let's say i were to change to channel 2 after using the channel 1, in my program, after the conversion of ADC in channel one, do i have to set a delay for initializing my channel 2 or straight away initialize my channel 2 after my adc conversion of channel 1 for better sampling and performance for both the channels?
 
When you chnage channels you need to allow the capacitor in the sample and hold enough time to charge/discharge, this depends on the source imedance feeding the PIC pin.
 
eblc1388 said:
Only true if the bytes are sent one after another, with some spare times in between after the stop bit(s) and another start bit.

Otherwise, error in baudrate will be accumulative and eventually the UART sampling clocking will be off.

@derrick826: I get the same result of 1.3% error for 57.6K baud at 20MHz clock.

Yea i thought i was wrong, thanks a bunch,
 
Nigel Goodwin said:
When you chnage channels you need to allow the capacitor in the sample and hold enough time to charge/discharge, this depends on the source imedance feeding the PIC pin.

A delay have to be set for both the channels before starting the conversion to allow the charging in the capacitor to charge, but when comes to channel selection, i just have to initialize which channel i want from the CHS2- CHS0 after each conversion from the respected channel has been done. Am i correct, Nigel?:confused:
 
It doesn't matter when you when you do the delay as long as the capacitor has time to settle - an obvious 'trick' is to read one channel, switch inputs, then send the first data out via RS232, then read the second channel etc. The time spent sending the RS232 becomes the delay.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top