CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Simple RS-232 help w/oscilloscope

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
g159
Guest







Simple RS-232 help w/oscilloscope
PostPosted: Sat Oct 20, 2007 4:33 pm     Reply with quote

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!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Oct 20, 2007 4:43 pm     Reply with quote

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.
g159
Guest







PostPosted: Sat Oct 20, 2007 5:17 pm     Reply with quote

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!
Ttelmah
Guest







PostPosted: Sun Oct 21, 2007 2:23 am     Reply with quote

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
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Sun Oct 21, 2007 3:59 am     Reply with quote

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.
Ttelmah
Guest







PostPosted: Sun Oct 21, 2007 6:54 am     Reply with quote

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
g159
Guest







PostPosted: Mon Oct 22, 2007 3:16 pm     Reply with quote

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!
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Oct 25, 2007 1:35 am     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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