The decoder reverses the effect of the encoder returning the information to it’s original form; that was easy.
Somebody else can jump in an explain what an encoder does. Only kidding! The encoder formats the information in a way that the medium being used can effectively convey it. As an example. I want to turn on and off a light bulb. In my house I can sent a voltage over a wire to turn it on and stop sending voltage to turn it off. If I’m transmitting via RF (the medium) things have to be different. If I constantly transmit a carrier at 433 Mhz to hold the light on I’m jamming my neighbors garage door opener. If I transmit a pulse at 433 Mhz I can have the uC turn on the light, but how do I turn it off? Following the the household wiring analogy, I just stop transmitting pulses. But if I use that as my encoding my light only flashes momentarily as all pulses are followed by an off time or they wouldn’t be pulse. Let’s say I decide to have 1 pulse turn on my light and 2 pulse turn it off. How long should I wait for the second pulse before deciding The transmitter was sending a single pulse? This is your encoding scheme, it has to effectively communicate the information to the receiver. So you would need to send 2 pulse in a certain time frame to command off and your receiver, when receiving a pulse it should see if one has already been received in a certain time frame and if so interpret it as the second of a pair and if not, entertain the possibility that it may be the first of a pair and wait certain time frame for a 2nd pulse and if received interpret it as a pair. Otherwise It must be a single pulse and the command was on. There are many encoding / decoding schemes, you can look some up on Wikipedia.
I thought one up once I called a “quadrature clock code” where if I remember correctly, I set a timer to 4 times the desired bit rate and used p/w modulation where all info was a logic hi to the transmitter (OOK transmission):
“invalid” was 1 out of 4 clock width,
binary 0 was 2 out of 4 clock widths
binary 1 was 3 out of 4 clock widths
and the between byte gap was 4 lows (I’m fuzzy on whether it was 4 or 8)
After receiving a CR terminated message over my uart port I did the following:
1.) counted the number of bytes in the message and generated a check-sum bit
2.) sent n bytes of “invalid” to wake up and settled the AGC in the receiver.
3.) created a new message consisting of the # of bytes being transmitted, the original message and a checksum byte.
4.) took each byte and for each bit, did a bitwise shift to into a bit variable and called a subroutine that generated either a 2 clockwidth pulse or a 3 clockwidth pulse and outputed it via the transmitter. After all 8 pulses in the byte were sent I when low for 4 ( or maybe 8?) clock cycles as an interbyte gap.
it was up to the decoder attached to the receiver to measure the length of the incoming pulses and:
1.)ignore the “invalid” bits in the header
2.) identify 2/4 and 3/4 width and bit shift them into bit positions in a byte.
3.) identify the 4 ( or 8?) bit gap in transmission as a end of byte signal and add the byte to the incoming message string and increment the byte count. If it was the first byte, interpret it as the message length and calculate the time the transmission should take and set a timer to underflow at after that (plus a small amount for various system errors)
4.) after the message byte count of received bytes reached the limit, a checksum was created from the message and compared to the last byte. Message was discarded on checksum fail If. The message byte count had not been achieved by the time the timer underflowed then the message was also discarded.
that was my “encoder / decoder” in a nutshell. There was no protocol for what to do on errors other than discard.
I’ve never used PICBasic, but love Oshon Basic for PICs, for it’s phenomenal user interface. If you haven’t spent $$ yet, go to the Oshonsoft web page and check it out. It has a 30 day free trial. Just finished a PIC12F675 design for a uninterruptable P/S controller using supercaps in under a day with it. 2 A/D converters, 2 relay control lines and 2 HZ timer for a backup in use status/power failure alarm line. Oshon basic’s IDE made it “easy”; and I’m not paid to say that.