![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
g159 Guest
|
Simple RS-232 help w/oscilloscope |
Posted: Sat Oct 20, 2007 4:33 pm |
|
|
I am a VERY new user to the Microchip PICs and am using the 16F877A. I'm trying to test out the serial output capabilities of the PIC and to start I've been trying to test output of the character 'A' with the following code:
#include <16F877A.h>
#use delay(clock=20000000) // we have a 20 MHz oscillator
#use standard_io(B)
#use standard_io(C)
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use rs232(baud=1200, parity=N, bits=8, xmit=PIN_C6, rcv=PIN_C7)
void main () {
while (TRUE)
{
putchar('A');
delay_ms(2000);
}
}
When i try to connect the oscilloscope to pin C6 it only shows a constant +5V signal that spikes down to 0 V every 2000 ms due to the delay statement. Shouldn't I be seeing some ASCII bitstream representation of the character 'A' ?
Anybody know what's wrong with this?
Thanks all! |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sat Oct 20, 2007 4:43 pm |
|
|
Your code looks OK to me. How long does the "spike" last? Your 'A' should last about 8ms. Try 'U' which should give you a square wave. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
g159 Guest
|
|
Posted: Sat Oct 20, 2007 5:17 pm |
|
|
Thanks for that quick reply SherpaDoug.
You said that my 'A' should last about 8ms? Perhaps something might be up with the horizontal scale I'm using on the o-scope then. The lowest I can get it to is 500 ms/div. Even then, it doesn't look like the signal ever drops to 0V in the duration of the signal 'A' (which i assume there should be at least a couple of in the bitstream for 'A').
The spikes are really just spikes that are very, very momentary, probably 1ms. It goes down for as long as the while() loop takes to re-run, i would say.
I'll try the 'U' and see if there's a way to get a smaller time scale on the o-scope.
Thanks again! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Oct 21, 2007 2:23 am |
|
|
Obvious comment, is that the 'delay', won't have _any effect at all_ on the output. The 'spikes down to 0 V every 2000 ms', are the data. A whole _character_ will be just 8.3mSec wide. At 500mSec/devision, and given that on most scopes, the 'dot' width is at least 1/40th division, you just will not see the data on your scope, at this sort of rate.
The actual 'pattern', will be:
HHHHHHLHLLLLLHLHHHHHHHHHHHH..........
Each 'letter' here, is 0.8333mSec wide.
What you need to do, is massively raise the scan rate of your scope (you want something like 1mSec/dic, to 5mSec/div _maximum_), and change how the scope is triggered, to 'normal', as opposed to 'auto' (the actual 'naming' of this depends on the scope manufacturer, but this means the scope won't actually draw a trace _at all_, till it is triggered). Triggering off the falling edge of the signal. This way, the trace will start with the first falling edge, and you will see the bit pattern for your character.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Sun Oct 21, 2007 3:59 am |
|
|
I suppose / in case you are using a plain analogue (not a storage) oscilloscope: These oscilloscopes can only show repeating, same patterns. (they cannot show you a one-time event after it has happened, neither they can show you a waveform repeating to rarely). Though your pattern is repeating, the repeat rate is too long compared to the duration of one character.
I suggest to make a much smaller delay (e.g. 50-100 msec) better suited to the character's duration, and/or make the baudrate much slower, so you'll be able to continuously see the repeating waveform with enough horizontal (time domain) resolution. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Oct 21, 2007 6:54 am |
|
|
Even at once every two seconds, the trace should be visible on a normal 'non storage' scope. The persistence of the tube, and human 'persistence of vision' normally allows things down to a few seconds repeat rate to be seen, but it gets ever harder, and will be a lot easier to see at a higher rate.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
g159 Guest
|
|
Posted: Mon Oct 22, 2007 3:16 pm |
|
|
hey guys,
I was able to get the serial data to show up by using normal, falling edge triggered as Ttelmah mentioned. One question, when you want to output something like, say, 'C' which is 100 0011 according to wikipedia, is the data supposed to be [start bit]01000011[stop bit] or [start bit]11000010[stop bit]? If we wanted to do something like say "FE" then would we have to program the output as reverse as "EF" instead?
Thanks for the help guys! |
|
![](templates/subSilver/images/spacer.gif) |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Oct 25, 2007 1:35 am |
|
|
The LSB Least Significant Bit is sent first.
1000011 will be sent as 1 1 0 0 0 0 1
Be carefull, Reversing the HEX is NOT the same as reversing the bits!
The letter 'C' is defined in the ASCII standard NOT Wikipedia!
ASCII = American Standard Code for Information Interchange
A 1 on the output should be -12v after going through the line driver and a 0 should be +12v although you will find most will be +9 upwards and possibly 0v down! |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|