|
|
View previous topic :: View next topic |
Author |
Message |
Leef_me
Joined: 14 Mar 2006 Posts: 45
|
software serial port baudrate vs oscillator frequency |
Posted: Tue Mar 14, 2006 1:48 am |
|
|
I am using a 16F630 with internal RC oscillator.
I am trying to use the PIC with a software uart by the USE RS232
statement. I tried this, and it appears to have the right bit timing, but the resulting data coming from the PIC into my PC seems to garbled.
Does anyone have information on the usable bit-banged baudrate that is possible?
The serial port of my PC is a TTL level to USB serial port emulator.
Thanks for any info. |
|
|
Ttelmah Guest
|
|
Posted: Tue Mar 14, 2006 5:28 am |
|
|
Do you know whether this USB emulator, gives positive or negative serial logic?. If you don't know for sure, post a part number.
What version is your compiler?. There have been timing 'issues', with some compiler versions, and software serial.
Now there are three seperate 'issues'. The first is the basic clock accuracy of the chip itself, the second is how accurately, the software serial can be, and the final one, is the serial timing accuracy of the USB adapter. The first is given in the data sheet (look very carefully, at the supply voltage limits). The second is dependant on the selected baud rate, and how closely this can be generated in instruction times. If (for instance) you choose 115200bps, with a 4MHz clock, then the possible emulation 'rates', are with 9 instructions, 111111.11bps, and with 8 instructions, 125000bps. The former is in error by 3.7%, and the latter by 8.5%. The maximum error allowed will depend slightly on the word length etc., but a total error of 4%, is a good guideline. Hence you can see that even if everything else is 'exact', this sort of rate, is borderline. You should also be aware, that the serial port on a PC, is not guaranteed to give accurate timings. Often 1% or more error, is common, and in some cases much worse (I have seen a number of 'brand name' laptops, return timings in error by over 3%..). How accurate the USB adapter is, will depend on the unit, but quite a few USB peripherals use ceramic resonators, that go significantly out of spec, if in cool enviroments...
Now the internal oscillator, if your supply range is 'in spec', is warranted to 1%. I you tried 115200bps, and had 3.7% error in the timings, then the oscillator happened to be out, in the same direction, and further the USB adapter itself had another 1% timing error,you could have a total error of just under 6%. Unlikely to work. Conversely, at 38400 bps, the bit timing error, would drop to just 0.1%, and everything ought to work.
As a general comment, I'd suggest that any rate, which has a bit time below perhaps 25 instruction cycles, is likely to give trouble. So for the 4MHz clock, perhaps a limit at around 40000bps.
Best Wishes |
|
|
Leef_me
Joined: 14 Mar 2006 Posts: 45
|
|
Posted: Tue Mar 14, 2006 8:05 pm |
|
|
Hi Ttelmah, thanks for the reply.
Pololu USB-to-Serial Adapter
http://www.pololu.com/products/pololu/0391/
Seems to be normal positive logic.
Compiler is PCWH version 3.180
I wanted just a standard low rate debugging port at 9600 or less
My supply voltage is probably 4.7V, 6 inch leads from a 7805 regulator.
Perhaps that seems a bit low, but the specs seem to allow lower than 3.5V
for 4mhz at 0*C to 85*C
I'll be checking the other details you suggested, possible tomorrow. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Mar 15, 2006 2:30 am |
|
|
From the Pololu website Quote: | The TX and RX lines use 3.3-volt levels, but the USB adapter input lines will tolerate up to 5.5 volts. Therefore, a direct connection to a microcontroller's I/O lines is usually possible. |
Running at 4.7V the PIC16F630 accepts:
- logic low: Vss - 0.8V
- logic high: 2.0V- Vdd
This seems OK, so you should have no problems here, except....
when you are connected to a Schmitt Trigger input the voltage levels are quiet different:
- logic low: Vss - 0.2Vdd
- logic high: 0.8Vdd- Vdd --> at 4.7V this equals 3.76V to 4.7V. Problem!
Most pins of the PIC16F630 are normal inputs, except for RA2. Which PIC pin do you have the Rx from the USB converter connected to? |
|
|
Ttelmah Guest
|
|
Posted: Wed Mar 15, 2006 4:37 am |
|
|
Leef_me wrote: | Hi Ttelmah, thanks for the reply.
Pololu USB-to-Serial Adapter
http://www.pololu.com/products/pololu/0391/
Seems to be normal positive logic.
Compiler is PCWH version 3.180
I wanted just a standard low rate debugging port at 9600 or less
My supply voltage is probably 4.7V, 6 inch leads from a 7805 regulator.
Perhaps that seems a bit low, but the specs seem to allow lower than 3.5V
for 4mhz at 0*C to 85*C
I'll be checking the other details you suggested, possible tomorrow. |
There could be significant problems receiving data from the unit (the voltage input problem that Ckielstra points out), but sending, should be OK.
Now, your amount of voltage drop, suggests that you will need to be _very_ careful about decoupling close to the processor. Actual voltage is not a problem (the chip will run happily off less volts than this), but _variation_ is. If there are sudden changes in the voltage level, as data is sent, or other operations are performed inside the processor, this can lead to momentary changes in the oscillator frequency, and/or other 'glitches' in the processor's operation.
3.180, could be in the area, where there were software serial timing problems. Run your code up in the MPLAB simulator, and use the 'stopwatch' function, to actually time how long bits take. There certainly were timing issues at about this time. A search here, should find some of the posts about this.
Best Wishes |
|
|
Leef_me
Joined: 14 Mar 2006 Posts: 45
|
|
Posted: Fri Mar 24, 2006 2:27 pm |
|
|
Hi Gang!
I finally got back to checking out the problem.
What I failed to state in various replys was that I am using Microchip's ICD2 with the AC162052 ICD header to debug pic16F630 code.
When I write a simple loop
[code]
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=pin_C3,rcv=pin_A2,stream=COM)
do {
delay_ms(100);
fputc('U',COM); // alternate 1 and 0 for debugging
} while (TRUE);
[/code]
and program it in a pic16F630 it works just fine.
When I use the ICD2 and the header, the output is gibberish.
I scoped the output for the pic16F630 and get about 100us per bit time.
I scoped the output for the ICD2 setup and get about 80us per bit time.
If I change the ICD2 code to #use delay(clock=4500000) then the bit times are closer to 100us and the Pololu USB-serial adapter can receive the data at 9600 bps. YMMV.
Thanks for your assistance.
Leef_me |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Mar 24, 2006 4:13 pm |
|
|
What are your #fuses settings and compiler version? |
|
|
imad84 Guest
|
the problem is with the RC oscillator |
Posted: Mon Apr 03, 2006 3:22 am |
|
|
Hello, u must don t use the RC oscillator
it is not precise, the communication with the RS232 need a BER less than 3%, try to use a quartz which is more precise
Rgardless |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|