Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC UART Manchester in C help!

Status
Not open for further replies.

Jsterz

New Member
Hi,

I'm still very new to PIC and have some some problem with RF module encode/decode programming. I understand how Manchester coding works thanks to Nigel's tutorial but i can not understand the ASM code, i have only learnt and done everything in C. i can right now get like 1 packet randomly, like 1 in 4. I would like to know what else i have to include in order to get it working at 100%.

Software: MPLAB IDE 8.40/Hi-TECH C compiler

Packet structure:...
Sync = 40bit(0x5555555555) // sync RF to correct frequency?
header = 8bit(0x0F) ==> 16bit Manchester(0xAA55) // start byte?
address = 8bit(0x00) ==> 16bit Manchester(0xAAAA) // address byte?
data = 8bit(0xFF) ==> 16bit Manchester(0x5555) // data byte?
checksum = 8bit(0x20) ==> 16bit Manchester(0xA6AA) // total packet byte?

example:
packet[0] = 0xAA // header
packet[1] = 0x55
packet[2] = 0xAA // address
packet[3] = 0xAA
packet[...]


Concept...
* Transmitter: Set a pin to be software UART, then just send bit by bit with delay in between.
example:
while(...)
{
tmpBit <<= packet; // keep looping and bit shift till end of packet
RA0 = tmpBit; // set/clear a pin for sending data
DelayUs(833); // 1200 baudrate = 833uSec/bit
}

* Receiver: Keep receiving data, store in buffer and keep on checking buffer for header?, if this is the right way how to recover the actual clock cycle in C?
example:
while(...)
{
buffer <<= 1; // left shift buffer
buffer += RA0; // get new data
DelayUs(833); // baudrate delay
if(buffer[0] == 0xAA && buffer[1] == 0xFF)
break;
}

// continue on with decoding rest of packet
 
Last edited:
You seem confused by what Manchester is?, it's dead easy to transmit (although you don't seem to be doing it?), and easily done by something similar (but not the same) as a software UART. You're not just sending the bits (like your example seems to be doing), you're sending a transition from 0 to 1, or 1 to 0, for each bit, it's the transition which is the data, NOT the bits themselves.

Receiving is difficult, you can't just use UART type timing because the data isn't accurately timed, as the RF (or IR) transmission and reception alters it. You have to detect the transitions, and signal an error if the transitions come too soon or too late, over a reasonably large range.
 
Thank you for replying :), i'm still fairly new to PICs at the moment.

So Manchester coding isn't just simply a software transform of original packet into a new encoded/decoded a packet right, not simply 0000 -> 1010 1010 then transmit the bit at the transmitter end? If not so, then how is the transition actually done in software? And what is the different between sending each byte here and sending via the software UART in Nigel's tutorial?

* I have never done any programming in ASM with PIC, so doing everything in C. The ASM tutorials are kinda hard to follow at the moment, still learning how to read it yet.
 
Well I don't write C, and assembler is far easier to understand :D

My tutorials explain the format, a direct quote from it:

a bit 1 is a transition from 0 to 1, and a bit 0 is a transition from 1 to 0

Why have you editted your original post?, it now makes no sense at all?.
 
Oh!! I thought the original post was too long with repeated codes so maybe just leave out the junks and left with how i'm actually 'transmitting the bits by setting/clearing a pin after baudrate delay'. All the other codes were just left/right bits shifting from the data in the packet structure defined at the start. The actual RF part was just what i'm confused at the moment. :( I find the assembly code harder to understand, guess will try to learn at least some basics of PIC assembly before i go on. RF programming is the only thing i can't find a tutorial/examples in C so far. I'll post an example in C after i fully understanding and be able to convert it to C.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top