PDA

View Full Version : 16F84/16F628 and Manchester



Navaidstech
- 11th March 2009, 03:17
Hi all...

OK, OK... I realize that the Manchester topic has been beaten to death here. I promise you that I've read pretty much every post on it but I still have questions and I hope some of you will steer me in the right direction.

Here is the deal: I'm trying to design a wireless link between two PIC devices using a 433 MHz RF module. Device1 will be sending information such as temperature, garage door status, garage lights status, etc, to Device2.

Initially I was going to make life simple and modulate the RF TX by a PIC serial port and send out your typical ASCII type data, but then I stumbled across some information on the benefits of Manchester coding and decided to go with that instead.

Since I have an abundance of 16F84 and 16F628 chips, I'd prefer to concentrate on those as much as possible.

Here are some of the questions that linger:

1. I've noticed some examples here make use of HSEROUT/HSERIN commands. I tried writing the code using these and the program (Microcode Studio with PBP) would not compile it. Subbing these commands for SEROUT/SERIN eliminated these problems. I'm assuming my chips do not support these commands. Am I correct?

2. OK...old school thinking here. Since each Manchester data word is 16 bits long.... how do I send it out of the PIC that has a start, 8 data byta, stop , parity bits? Some examples here were using SEROUT2 as opposed to SEROUT command and I did some research on those in the Microcode Help file. Am I correct in assuming that SEROUT2 allows to transmit longer data and is not limited to just 8 bits?

3. I understand that one needs to send out a preamble allowing the receiver to stabilize before it accepts good data. Does the preamble need to be sent out before every data word, or just at the beginning of the entire data sequence?
If the latter, how does the receiver distinguish between each data word, other than couting the incoming bits? Would it be wise to insert some sort of a control character in front of each data word so the receiver has better time separating one data word from the next?

I think this is it for now. I'm sure there will be more questions but these three should be enough to get me started.

Any help would be greatly appreciated.
Thanks!

Alex

Ioannis
- 11th March 2009, 07:38
I promise you that I've read pretty much every post on it


Seems not...



1. I've noticed some examples here make use of HSEROUT/HSERIN commands. I tried writing the code using these and the program (Microcode Studio with PBP) would not compile it. Subbing these commands for SEROUT/SERIN eliminated these problems. I'm assuming my chips do not support these commands. Am I correct?


Correct. Have you read the chips data sheets???




2. OK...old school thinking here. Since each Manchester data word is 16 bits long.... how do I send it out of the PIC that has a start, 8 data byta, stop , parity bits? Some examples here were using SEROUT2 as opposed to SEROUT command and I did some research on those in the Microcode Help file. Am I correct in assuming that SEROUT2 allows to transmit longer data and is not limited to just 8 bits?


No. You still send bytes but every data byte is encoded in two Manchester bytes.



3. I understand that one needs to send out a preamble allowing the receiver to stabilize before it accepts good data. Does the preamble need to be sent out before every data word, or just at the beginning of the entire data sequence?


Only at the start of the data sequence.

Ioannis

Navaidstech
- 11th March 2009, 16:51
Obviously I missed a few posts.
;)

Thanks for the info there Ioannis.


I searched the forum some more this morning and I was able to whip out a tx/rx pair that ALMOST works, based on code tidbits I found..
At the moment the two modules are connected with wires but once I get the code rectified a bit, I'll move up to RF modules.

I say "ALMOST" because the tx part seems to be working ok, however the receiver isn't quite there yet.

Here is the code that I'm using for transmitting (I have observed it on the oscilloscope and it appears to be working):

dataport var PORTB.0

START:
serout2 PORTB.0,813,[$55, $55, $55, $AA]
mydata = "T"

dataport = $00
pause 1000
goto start


ENCODEMANCHESTER:
ManchesterWord=0
For CounterA=0 to 7
If MyData.0=0 then
ManchesterWord.14=1
else
ManchesterWord.15=1
endif
If CounterA<7 then ManchesterWord=ManchesterWord>>2
MyData=MyData>>1
Next CounterA
serout2 dataport,396,[manchesterword.lowbyte, manchesterword.highbyte]

Return


And here is the receiver code:



RECEPTION var PORTB.0
INFO VAR PORTB.2
ERROR var PORTB.1



START:
manchesterword=0

SERIN2 reception, 813, [WAIT($AA),ManchesterWord.LowByte,ManchesterWord.Hi ghByte]
gosub ManchesterDecode

goto start

ManchesterDecode:
ErrorFlag=0
For CounterA=0 to 7
If ManchesterWord.1=0 then
MyData.7=0
ERROR = 0
If ManchesterWord.0=0 then
ErrorFlag=1
ERROR = 1
endif
else
MyData.7=1
ERROR = 0
If ManchesterWord.0=1 then
ErrorFlag=1
ERROR = 1
endif
endif
ManchesterWord=ManchesterWord>>2
If CounterA<7 then MyData=MyData>>1
NEXT COUNTERA
serout2 info, 813, [Mydata]

Return

I set PORTB.1 as an indicator telling me whether or not the Manchester code has errors in it... I was monitoring that pin with a scope and not once did it light up, yet I'm getting garbage coming out on pin 2.

Somehow I'm thinking that the receiver code is missing something but I'm hoping if you guys could point out where the problem lies.

thanks

Alex

Ioannis
- 11th March 2009, 19:06
I cannot see how these two pieces of code (tx and rx) can work together.

Read your code again,or post the working code.

Or try the untested one that is attached.

Rename to .bas and burn it.

Ioannis

Navaidstech
- 11th March 2009, 20:31
Of course!

I'm sending the preamble at a wrong baud rate! DOH!

Changed it and it works ok now....

thanks!!!

Alex

Navaidstech
- 12th March 2009, 02:45
Ioannis...

looks like I jumped the gun there. Your code seems to be working much better than the one I used.

Thank you for your help. Hopefully I'll be ok from hereon.

Alex

Ioannis
- 12th March 2009, 07:33
...looks like I jumped the gun there...

? I am not sure i follow...

You are welcome!

Ioannis

Navaidstech
- 12th March 2009, 15:28
In my previous message I indicated that once the baud rate was changed, the original program that I posted was working ok.
Then I noticed some errors popping up so I decided to delve further into the program... it didn't look right so I decided to use your untested routines and they worked great.

Thanks again!