|
|
View previous topic :: View next topic |
Author |
Message |
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
manchester decode |
Posted: Sun Jan 26, 2025 4:48 pm |
|
|
Good day forum friends, I need a Manchester decode code. I looked at the form and couldn't find anything useful. Can anyone who has a code share it here? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1946 Location: Norman, OK
|
|
Posted: Sun Jan 26, 2025 5:04 pm |
|
|
Out of 106 hits on the word Manchester you couldn't find anything useful? _________________ Google and Forum Search are some of your best tools!!!! |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sun Jan 26, 2025 5:12 pm |
|
|
Unfortunately I couldn't find it, most of them are half missing |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Sun Jan 26, 2025 5:58 pm |
|
|
To get help, you really need to supply which PIC you want to use as well as compiler version.
Also should say where the data is coming from, how large a 'frame',etc.
hmm 'decode', so is this just a TTL signal or from some 'module' ? Curious since most 'modules' are 3 volt devices, PICs are usually 5volt, so from a hardware aspect this is important. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sun Jan 26, 2025 6:13 pm |
|
|
mcu 16f1824 rf module 433 mhz reading data receiving 10 byte data frame sending remote control keeloq manchester 1500 baund communication speed.
ccs c last version |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 502 Location: Montenegro
|
|
Posted: Sun Jan 26, 2025 6:47 pm |
|
|
Keeloq? It uses way more data bits + preamble + sync. What about start and stop bits? On what pin is this stream coming to?
One more thing. To avoid potential confusion later on, baud rate and the actual bit rate are not the same thing in this case.
Last edited by PrinceNai on Sun Jan 26, 2025 7:01 pm; edited 1 time in total |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sun Jan 26, 2025 6:54 pm |
|
|
It communicates with UART. Keeloq sends it by encoding Manchester. I need Manchester decode code. The time between bits is 640 us.
top 66 bits. data |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19649
|
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 502 Location: Montenegro
|
|
Posted: Mon Jan 27, 2025 4:54 am |
|
|
This is a test code for decoding the input Manchester stream on the fly. It works as expected in MPLAB simulator.
Code: |
#include <18F46k22.h>
#FUSES NOWDT,NOPROTECT, NOPUT , NOLVP
//#device PASS_STRINGS = IN_RAM //copy all the strings to RAM to allow access with pointers
#device ADC=8
#use delay(internal=32000000)
#use rs232(baud = 115200, BITS = 8, PARITY = N, UART1, STREAM = PORT1, ERRORS)
#use rs232(baud = 115200, BITS = 8, PARITY = N, UART2, STREAM = DEBUG, ERRORS)
#use i2c(Master, Fast, sda=pin_c4, scl=pin_c3, force_hw)
/////////////////////////// DEFINES /////////////////////////////////
#define DATA_BYTES 20
/////////////////////////// VARIABLES ///////////////////////////////
char DecodedInputData[DATA_BYTES/2 + 1]; // buffer where decoded data will go. +1 provides space for null string terminator, if needed
int8 ByteCounter = 0; // keeps track of which byte was received
int8 DataReceived = 0; // flag to inform main data is ready
char Decoded = 0; // variable used when decoding input stream
int8 Temp = 0b10101010; // test data
////////////////////////// FUNCTIONS ////////////////////////////////
void Manchester(void){
// Count of received bytes starts from 0. That is why the first byte is considered even and the second byte odd!!!
// Rules of whole number division are at work here. For example, both 0 and 1 divided by 2 will equal 0. Same goes for 2 and 3 (1) and so on.
signed int8 i; // i keeps track of the bit that needs to be extracted. ByteCounter keeps track whether top or low nibble was received
// top nibble (even received byte)
if (ByteCounter%2 == 0){ // test which byte was received (even byte or odd byte)
for(i=7; i>=1; i=i-2){ // even input byte was received
if(bit_test (Temp, i) == 1){ // take out bits 7,5,3 and 1 that are our data
bit_set(Decoded, i/2 + 4);
}
else{ // and fill top four bits of variable Decoded with extracted data
bit_clear(Decoded, i/2 + 4);
}
} // end for
Temp = 0b01010101; // reverse data for testing purposes.Remove this line.
} // end if
// bottom nible (odd received byte)
else{ // odd input byte was received (bytes 1,3,5, ....)
for(i=7; i>=1; i=i-2){
if(bit_test (Temp, i) == 1){ // take out bits 7,5,3 and 1 that are our data
bit_set(Decoded, i/2);
}
else{ // and fill bottom four bits of variable Decoded with extracted data
bit_clear(Decoded, i/2);
}
} // end for
DecodedInputData[ByteCounter/2] = Decoded; // one byte of data was decoded, move it to some buffer
} // end else
ByteCounter++; // increment counter
if(ByteCounter >= DATA_BYTES){ // compare it to whatever number of data bytes expected
ByteCounter = 0; // reset counter
DataReceived = 1; // signal to main data is ready
}
}
/////////////////////////////////////////////////////////////////////
////////////////////// END OF FUNCTIONS /////////////////////////////
/////////////////////////////////////////////////////////////////////
// ******************************************************************
// INTERRUPTS
// ******************************************************************
#INT_TIMER1
void TIMER1_isr(void)
{
}
#INT_RDA
void RDA_isr(void)
{
// Temp = getc(); // un-comment and put the contents of Manchester function in after this
}
// ------------------------------------------------------------------
// ******************************************************************
// END OF INTERRUPTS
// ******************************************************************
void main()
{
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); // 1us resolution at 32Mhz
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
DecodedInputData[0] = 0; // to see change when tested. Not needed.
delay_cycles(1);
Manchester(); // call it twice for testing purposes, since we need two input bytes
Manchester();
// ..................................................................
while(TRUE)
{
} // while(TRUE)
} // main
|
|
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Mon Jan 27, 2025 7:39 am |
|
|
@PrinceNai First of all, thank you for your interest. The code you published does not solve correctly. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Mon Jan 27, 2025 7:50 am |
|
|
I tried the code that our friend Ttelmah published and I couldn't run it. I am not an expert in C. Can you help me? I edited the code and added the logic analyzer in the picture. The blue one is the raw data of the remote control and the purple one is the part that I am trying to convert to Manchester.
Code: | ///////////////////////////////////////////////////////////////////////////////
char manchester[16]={
0b01010101, //0
0b01010110, //1
0b01011001, //2
0b01011010, //3
0b01100101, //4
0b01100110, //5
0b01101001, //6
0b01101010, //7
0b10010101, //8
0b10010110, //9
0b10011001, //A 10
0b10011010, //B 11
0b10100101, //C 12
0b10100110, //D 13
0b10101001, //E 14
0b10101010}; //F 15
static int MANerror;
byte MANencode1(byte ByteIn)
{
return manchester[(ByteIn & 0xf0)>>4];
}
byte MANencode2(byte ByteIn)
{
return manchester[ByteIn & 0x0f];
}
byte MANdecode(byte ByteToDecode1, byte ByteToDecode2)
{
int i, j; //part1, part2;
for(i=0;i<=15;i++)
{
if(manchester[i]==ByteToDecode1)
break;
}
if(i==16)
MANError=1;
for(j=0;j<=15;j++)
{
if(manchester[j]==ByteToDecode2)
break;
}
if(j==16)
MANError=1;
manch = MANdecode;
putc(manch);
return (i*16 + j);
}
///////////////////////////////////////////////////////////////////////////////
#int_rda
void RecieveWireless()
{
static int WirelessData[8];
static int RXModeByte;
int data, checksum;
data=RCREG; //Get Data From USAART RX Buffer
if (OERR) //Buffer Underrun
{
CREN=0; //Reset Usart reciever
CREN=1;
return;
}
if (data == 0x78) // wait for the start byte - anytime the USART Sync Bit is
{
RXModeByte = 1; // encountered, restart the recieve process
return;
}
Switch (RXModeByte)
{
Case 0:
break;
Case 1:
if (data == 0xf8) // Start Byte, now Wait for data
{
RXModeByte = 2; // begin waiting for data bytes
LastRXTime = time;
}
else
RXModeByte = 0; // not start byte, go back to wait for start.
break;
Case 2: //DataByte 0
Case 3:
Case 4: //DataByte 1
Case 5:
Case 6: //DataByte 2
Case 7:
Case 8: //checksum
Case 9:
WirelessData[RXModeByte-2] = data; // Read in bytes, one at a time.
RXModeByte++; // Increment count
if (RXModeByte == 10) //After all eight databytes are recieved
{
RXModeByte = 0; //
MANerror = 0; //reset error bit before decoding
RecieveByte0 = MANdecode(WirelessData[0], WirelessData[1]);
RecieveByte1 = MANdecode(WirelessData[2],WirelessData[3]);
RecieveByte2 = MANdecode(WirelessData[4],WirelessData[5]);
checksum = MANdecode(WirelessData[6],WirelessData[7]);
//Check For Errors:
if (!MANerror && ((int)(RecieveByte0 + RecieveByte1 + RecieveByte2) == checksum ))
{ //When no errors exist:
//USE THIS SPACE TO DO SOMETHING WITH YOUR VALUES
}
else
{ //Errors Exist
}
//Optional:
//output_toggle(LEDwireless); //blink power LED with wireless packet data
}
break;
default:
RXModeByte=0;
break;
}
return;
//
clear_interrupt(int_RDA);
} |
|
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 502 Location: Montenegro
|
|
Posted: Mon Jan 27, 2025 8:51 am |
|
|
Yes, more than likely it doesn't. It depends on how the transmitter is sending the data (MSB or LSB first) and the type of coding used, meaning does 01 represent a 1 or a 0. Would you post a sample 16 bit output signal and what 8 bit data should look like for that? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Mon Jan 27, 2025 9:33 am |
|
|
I'm still trying to figure out how 10 bytes of MANCHESTER data can be received by a UART....
really, MANCHESTER has clock embedded in the data stream, UART is just 'data'.
typical UART is set for 8 bits, + start and stop......
Last edited by temtronic on Mon Jan 27, 2025 11:48 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19649
|
|
Posted: Mon Jan 27, 2025 9:35 am |
|
|
What you post will not run, since it needs the setup fuses etc., for _your_ chip.
If you have not even got to the point of understanding this, you need to step
back and learn how to do basic things like this before trying to do something
like Manchester encoding. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Mon Jan 27, 2025 9:35 am |
|
|
priority msb logic picture above available manchester output data in blue color remote control |
|
|
|
|
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
|