View previous topic :: View next topic |
Author |
Message |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
manchester decode question |
Posted: Tue Jul 22, 2025 1:28 am |
|
|
hello form but I would like to ask something. I have a Manchester code with an 8-byte decode. The TE time is 416 us. What is the reason why this code is not decoded correctly? Timer1 is set to 65.5 ms and the IOC interrupt is working. PREAMBLE time 1.6 ms
decoded data is always 0xAA.
Code: | #define NUMBER_OF_BYTES 8 //7
#define TE 400
//
#define PREAMBLE_MAX_TIME 5 * TE
#define PREAMBLE_MIN_TIME 4 * TE
//
#define TRANSITION_MIN_TIME 0.8 * TE
#define TRANSITION_MAX_TIME 2.5 * TE
////////////////////////// VARIABLES //////////////////////////////////////////
char DecodedInputData[8]; //7
char CurrentByte = 0;
//
int8 InputByteCounter = 0;
int8 BitPosition = 0;
//
enum {GotRisingEdge = 1, GotFallingEdge, SampleData};
int8 DecodeSwitch = GotRisingEdge;
int16 TimerValue;
int8 TMR1_Overflow = 0;
////////////////////////// FUNCTIONS /////////////////////////////////////////
void ToggleIntEdge(void){
if(INTEDG == 1){
INTEDG = 0;
}
else{
INTEDG = 1;
}}
// ----------------------------------------------------------------------------
void ClearBuffer (void){
DecodedInputData[0] = 0x00;
DecodedInputData[1] = 0x00;
DecodedInputData[2] = 0x00;
DecodedInputData[3] = 0x00;
DecodedInputData[4] = 0x00;
DecodedInputData[5] = 0x00;
DecodedInputData[6] = 0x00;
DecodedInputData[7] = 0x00;
}
// ****************************************************************************
// INTERRUPTS
// ****************************************************************************
#INT_TIMER1
void TIMER1_isr(void)
{
TMR1_Overflow ++;
}
//----------------------------------------------------------------------------- MANCHESTER DECODE
#INT_IOC
void IOC_isr(void)
{
clear_interrupt(INT_IOC_A1);
////
switch(DecodeSwitch)
{
case GotRisingEdge: //RESET
{
if(input_state(data_inputs) == 1){ //ext_int kesmesi kullanılırsa pasif et
set_timer1(0);
TMR1_Overflow = 0;
BitPosition = 0;
InputByteCounter = 0;
CurrentByte = 0;
DecodeSwitch = GotFallingEdge;
}
break;
}
// ----------------------------------------------------------------------------
case GotFallingEdge:
{
TimerValue = get_timer1();
if(TMR1_Overflow == 0 && TimerValue > PREAMBLE_MIN_TIME && TimerValue < PREAMBLE_MAX_TIME){
set_timer1(0);
TMR1_Overflow = 0;
DecodeSwitch = SampleData;
}
else{
DecodeSwitch = GotRisingEdge;
}
break;
}
//-----------------------------------------------------------------------------
case SampleData:
{
ToggleIntEdge();
TimerValue = get_timer1();
if(TMR1_Overflow == 0 && TimerValue >= TRANSITION_MIN_TIME && TimerValue <= TRANSITION_MAX_TIME){
set_timer1(0);
if(input_state(data_inputs) == 0){
//if(input_state(inputs) == 1){
bit_set(CurrentByte, BitPosition);
}
else{
bit_clear(CurrentByte, BitPosition);
}
BitPosition ++;
if(BitPosition > 7){
BitPosition = 0;
DecodedInputData[InputByteCounter] = CurrentByte;
CurrentByte = 0;
InputByteCounter ++;
if(InputByteCounter == NUMBER_OF_BYTES){
//
for(int i = 0; i < NUMBER_OF_BYTES; i++){ //7
paket[i] = DecodedInputData[i];
}
//
ready = 1;
DecodeSwitch = GotRisingEdge;
}
}
}
else if(TMR1_Overflow == 0 && TimerValue < TRANSITION_MIN_TIME){
}
else{
//ext_int_edge(0, L_TO_H); //ext_int kesmesi kullanılırsa aktif et
DecodeSwitch = GotRisingEdge;
}
break;
}
}
} |
mathematical symbols |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19928
|
|
Posted: Tue Jul 22, 2025 8:15 am |
|
|
I suspect you have taken some code designed to work off INT_EXT,
and have bodged it to try to work on the IOC?. You don't show us how you
have set this up, but to work you need to be re-programming the edge
where the EXT_INT_EDGE call was. If the edge setting is wrong. this is not
going to work.
There seem to be bits removed that I'd expect, and without seeing the
clock setup and a real value for the bit width, it is hard to know how the
code could work. |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Tue Jul 22, 2025 2:13 pm |
|
|
Ttelmah wrote: | I suspect you have taken some code designed to work off INT_EXT,
and have bodged it to try to work on the IOC?. You don't show us how you
have set this up, but to work you need to be re-programming the edge
where the EXT_INT_EDGE call was. If the edge setting is wrong. this is not
going to work.
There seem to be bits removed that I'd expect, and without seeing the
clock setup and a real value for the bit width, it is hard to know how the
code could work. |
incoming data standard manchester.I was using this code in a different Manchester code. This incoming data is slightly different in Manchester. The friend who wrote this code works through the IOC interrupt. I have never used it in the ext_ interrupt. When the code decodes in its current state, it outputs 0xAA. I want to see the red data in the logic decode image, but it decodes incorrectly and the output is always 0xAA.
ClearBuffer();
enable_interrupts(INT_IOC_A1); //ioc kesmesi
clear_interrupt(INT_IOC_A1);
manchester settings.
 |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 554 Location: Montenegro
|
|
Posted: Tue Jul 22, 2025 2:15 pm |
|
|
The code he has is ok for IOC, there were two versions, one with external interrupt and the other with IOC. The code was designed to take sample after the transition in the middle of the Manchester pair. For that reason TRANSITION_MIN_TIME definition absolutely MUST be bigger than one TE or you end up sampling after the wrong edge. OP says TE is 416us, definition in the code is 400us. Preamble catching is on the edge, defined as 4-5 TE. And lastly, the data here is stored LSB first, while in my original code it gets stored MSB first. But I wrote all that earlier today. |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Tue Jul 22, 2025 2:21 pm |
|
|
PrinceNai wrote: | The code he has is ok for IOC, there were two versions, one with external interrupt and the other with IOC. The code was designed to take sample after the transition in the middle of the Manchester pair. For that reason TRANSITION_MIN_TIME definition absolutely MUST be bigger than one TE or you end up sampling after the wrong edge. OP says TE is 416us, definition in the code is 400us. Preamble catching is on the edge, defined as 4-5 TE. And lastly, the data here is stored LSB first, while in my original code it gets stored MSB first. But I wrote all that earlier today. |
When I set TRANSITION_MIN_TIME above 416 us, the code does not work. That's why I'm sharing it here. I don't know how to make it work according to the IOC interrupt. So, where do I need to change the code to decode this incoming data correctly?
Decoding does not work with these settings
#define NUMBER_OF_BYTES 8
#define TE 400
//
#define PREAMBLE_MAX_TIME 5 * TE
#define PREAMBLE_MIN_TIME 4 * TE
//
#define TRANSITION_MIN_TIME 1.5 * TE
#define TRANSITION_MAX_TIME 2.5 * TE |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9568 Location: Greensville,Ontario
|
|
Posted: Tue Jul 22, 2025 2:43 pm |
|
|
hmm all 8 bytes are the same.....seems odd, like a 'counter' isn't incrementing.
So.... can anyone see where 'CurrentByte' gets incremented ?
light green on white isn't easy on my eyes.....
ahh the joys of aging.....
Jay |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Tue Jul 22, 2025 2:54 pm |
|
|
temtronic wrote: | hmm all 8 bytes are the same.....seems odd, like a 'counter' isn't incrementing.
So.... can anyone see where 'CurrentByte' gets incremented ?
light green on white isn't easy on my eyes.....
ahh the joys of aging.....
Jay |
This code works on a different version of the standard Manchester. This did not work on the incoming data.
I can't comment much on this code because I don't have much knowledge of it, so I need help. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9568 Location: Greensville,Ontario
|
|
Posted: Tue Jul 22, 2025 3:07 pm |
|
|
well my though of the code as presented ,doesn't increment ,so all the bytes would be the same. |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Tue Jul 22, 2025 3:14 pm |
|
|
temtronic wrote: | well my though of the code as presented ,doesn't increment ,so all the bytes would be the same. |
The whole process ends in the code here. The bit_set process is performed by incrementing the bitposition counter. After detecting the preamble, it doesn't decode correctly due to synchronization. I don't know what precautions to take for this.
if(input_state(data_inputs) == 0){
//if(input_state(inputs) == 1){
bit_set(CurrentByte, BitPosition);
}
else{
bit_clear(CurrentByte, BitPosition);
}
BitPosition ++;
if(BitPosition > 7){
BitPosition = 0;
DecodedInputData[InputByteCounter] = CurrentByte;
CurrentByte = 0;
InputByteCounter ++ |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9568 Location: Greensville,Ontario
|
|
Posted: Tue Jul 22, 2025 3:46 pm |
|
|
It's probably best to ask the friend who wrote the code !
what you show isn't a complete program so no idea if somewhere in 'main()' something happens to make all 8 bytes 0xAA
for test purposes, I'd have a 2nd PIC send known Manchester data to your 'receiving' PIC. that's be 8 known bytes, then a delay, then 8 null bytes, then a delay, then loop back to start..... |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 554 Location: Montenegro
|
|
Posted: Tue Jul 22, 2025 3:55 pm |
|
|
Input format is different, so I'm pretty sure it can't work as it is. Question: do you know the input data that gets Manchester coded and sent out? Or better, do you know what the result of decoding should be?
At the first glance your analyzer interprets the code incorrectly. Have you noticed that there are 65 decoded bits and 8bytes? I have a feeling that the first 0-1 combo (or symbol) after the preamble is kind of a start bit. Why I think that? Imagine that the first byte after the preamble would be 1-0 symbol. How would you know the data transmission started? It would just look like a longer preamble. You need something to separate preamble and data. I think that the first 1 is also part of this separator because only in that case next bits form correct Manchester symbols. |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 554 Location: Montenegro
|
|
Posted: Tue Jul 22, 2025 4:00 pm |
|
|
Quote: | it doesn't decode correctly due to synchronization. I don't know what precautions to take for this |
None in this case. MinTe in the range 1,5TE - 2,5TE is there to ensure that data will get sampled every second bit, no matter the kind of transition. Yours is set below 1TE, meaning it will fall out of sync. But even if you correct that it won't work for this input data. |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Tue Jul 22, 2025 4:01 pm |
|
|
PrinceNai wrote: | Input format is different, so I'm pretty sure it can't work as it is. Question: do you know the input data that gets Manchester coded and sent out? Or better, do you know what the result of decoding should be?
At the first glance your analyzer interprets the code incorrectly. Have you noticed that there are 65 decoded bits and 8bytes? I have a feeling that the first 0-1 combo (or symbol) after the preamble is kind of a start bit. Why I think that? Imagine that the first byte after the preamble would be 1-0 symbol. How would you know the data transmission started? It would just look like a longer preamble. You need something to separate preamble and data. I think that the first 1 is also part of this separator because only in that case next bits form correct Manchester symbols. |
Yes, the format is different, so it doesn't solve it. What changes can I make to the code to solve this code? My target is the correct solved version of the logic red image. The red data should be the same. |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Tue Jul 22, 2025 4:04 pm |
|
|
PrinceNai wrote: | Quote: | it doesn't decode correctly due to synchronization. I don't know what precautions to take for this |
None in this case. MinTe in the range 1,5TE - 2,5TE is there to ensure that data will get sampled every second bit, no matter the kind of transition. Yours is set below 1TE, meaning it will fall out of sync. But even if you correct that it won't work for this input data. |
Where do I need to change the code to overcome this issue? |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 554 Location: Montenegro
|
|
Posted: Tue Jul 22, 2025 4:45 pm |
|
|
Quote: | What changes can I make to the code to solve this code? My target is the correct solved version of the logic red image. The red data should be the same. |
What is the correct solution? |
|
 |
|