PDA

View Full Version : fast + accurate packet and baud rate



mbw123
- 26th October 2006, 01:48
Thanks to mister_e and keithdoxey (and many others) I was able to make the following code that allows to PIC16F628A's to communciate serially. There are four buttons on the transmitter that turn on four pins on the receiver. The code works, but does anyone have any suggestions on making it faster and more accurate (many packets are lost and sometimes there are delays between packets)? Thanks for the help. (I need the $A5 and the "~" as a synch byte because it will eventually be hooked up to a rf link)

-Mike

Transmitter code:
-----------------

DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 2400

cmcon = 7

Current var byte
Laststate var byte
input PORTA.0
input PORTA.1
input PORTA.2
input PORTA.3

Main:

current.0 = PORTA.0
Current.1 = PORTA.1
Current.2 = PORTA.2
Current.3 = PORTA.3

if (Current <> Laststate) then
hserout [$A5,"~",Current]
Laststate = Current
endif

goto main

-------------
Receiver code
-------------
define HSER_CLROERR 1
define HSER_RCSTA 90h
define HSER_BAUD 9600

cmcon = 7

Current var byte
output PORTA.0
output PORTA.1
output PORTA.2
output PORTA.3
low PORTA.0
low PORTA.1
low PORTA.2
low PORTA.3

Main:

Hserin 20,Main,[WAIT("~"),Current]

Current = ~ Current

PORTA.0 = Current.0
PORTA.1 = Current.1
PORTA.2 = Current.2
PORTA.3 = Current.3

goto main

mister_e
- 26th October 2006, 15:51
i'm sure you already know but your baudrate don't match on both side.

With RF, using higher baudrate may work... or not. Tell us what kind of RF stuff you're using.



current.0 = PORTA.0
Current.1 = PORTA.1
Current.2 = PORTA.2
Current.3 = PORTA.3




current = PORTA & $0F

mbw123
- 26th October 2006, 22:43
Sorry, the mismatching baud rates was just a typo. I am going to use the RX433 and TX433 duo from Qkits.

http://store.qkits.com/moreinfo.cfm/RX433
http://store.qkits.com/moreinfo.cfm/tx433

I have 4Mhz oscillators. Can I go at a faster baud rate?
Thanks.

-Mike

dhouston
- 26th October 2006, 23:08
You need to check the manufacturer's datasheets for that transmitter and receiver to see the maximum bps they can handle. If QKits doesn't have the data sheet check the Wen Shing web page (Wen Shing manufactures the RF modules.)http://www.wenshing.com.tw/english/index.aspThe receiver max is 4800bps.