|
|
View previous topic :: View next topic |
Author |
Message |
hollajo
Joined: 21 Jun 2010 Posts: 13 Location: France
|
How can i send data via rs232 ? |
Posted: Mon Jun 21, 2010 6:43 am |
|
|
Hi everybody
I'm new with CCs and i would like to know how work the sending via the rs232 com.
I use PIC16f870
I just wrote this
#use (delay=4000000)
#use rs232(baud=300, xmit=PIN_C6, rcv=PIN_C7)
I want to send some data like a pwm signal with 20 ms on and 20 ms off for example.
Is it possible to make this kind of thing ? or RS232 is just used to send some character like the famous "hello world"
thank's for your help |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Mon Jun 21, 2010 8:27 am |
|
|
Async serial comms, sends data (text is a 'subset' of this), using a series of logic pulses.
The format, is basically:
Line idles high.
Each bit is 1/baud seconds 'wide'.
There is always one 'low' start bit.
There are then normally 8 data bits (the PIC hardware doesn't support many of the other formats).
Optional parity bit (the hardware doesn't support this),
One 'high' stop bit.
Now, the default then is ten bits of data for one 'character'.
If you wanted to control the hardware to produce a 20mSec low, and a 20mSec high, you would really need the total 'character' time (ten bits) to be 40mSec. 4mSec/bit. So start by selecting 250baud.
Then you could produce equal mark/space, by sending 4 low bits, followed by 4 high. Your options would be:
0111111111 (send 0xFF) 90% - maximum
0011111111 (send 0x7F) 80%
0001111111 (send 0x3F) 70%
0000111111 (send 0x1F) 60%
0000011111 (send 0x0F) - 20mSec on/off
0000001111 (send 0x07) 40%
0000000111 (send 0x03) 30%
0000000011 (send 1) 20%
0000000001 (send 0) 10% - minimum
The code would need to ensure that a new transmit byte was loaded as soon as one finishes clocking out (could be done efficiently with the interrupt). There is one character of buffering, so there would be no gaps if this was done.
So if you select 250baud, and keep sending 0x0F, you would get the 20mSec on/off you ask for.
However there are hardware parts much better suited to doing this. The obvious one is the PWM, which is designed exactly for this. At low speeds like you describe, the CCP, or a simple delay, and output loop.
It can 'sort of' do this, but not terribly 'well'...
Best Wishes |
|
|
hollajo
Joined: 21 Jun 2010 Posts: 13 Location: France
|
|
Posted: Tue Jun 22, 2010 5:16 am |
|
|
Thanks for your help. I understand a little more how work the data transmission and is not easy that much So I'm going to study the PIC datasheet with the CCS datasheet. |
|
|
|
|
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
|