View previous topic :: View next topic |
Author |
Message |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Tue Jul 22, 2025 4:53 pm |
|
|
PrinceNai wrote: | 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? |
If it solves like the part I drew in the picture, the code above is correct for me.
 |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 554 Location: Montenegro
|
|
Posted: Tue Jul 22, 2025 11:51 pm |
|
|
As I said, I do not believe that what is shown on the picture represents correctly decoded input stream. Bits are decoded ok, how they are combined into bytes is not. You show 65 Manchester symbols (1-0 or 0-1 combination) and 8 bytes, using only 64 of them. Why would one extra symbol be transmitted at the end of the stream?
Last edited by PrinceNai on Wed Jul 23, 2025 1:22 am; edited 1 time in total |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19928
|
|
Posted: Wed Jul 23, 2025 1:05 am |
|
|
My guesses would be that perhaps this is Thomas Manchester (the original
form), rather than IEEE Manchester. If so all the edges have opposite
polarity so the initial setup of the IOC would have to be for the opposite
edge, and the reversals at different points.
As I have already said, you do not show us the setup code (hoe the IOC is
set, how the tOC is programmed etc.), so we have no way of knowing if
the settings or timings are even remotely right (also would need an
expanded view of a a few bits so we can measure the timings accurately).
However the big problem for me, is that you arrive on an edge (we don't
know which one this is, since you have not posted the setup), and then
you do not change the sample edge till you get to the sample data
part of the handler. You also have not shown how the toggle int edge
code is actually being performed (presumably 'INTEDG', is setup as a
bit controlling the detection edge for the IOC), but we do not know since
you gave not posted the settings for this.
What you post has essential parts missing. We cannot help unless you
post something that could work. |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 554 Location: Montenegro
|
|
Posted: Wed Jul 23, 2025 1:21 am |
|
|
So far no one knows even which PIC is used :-) |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Wed Jul 23, 2025 4:48 am |
|
|
Ttelmah wrote: | My guesses would be that perhaps this is Thomas Manchester (the original
form), rather than IEEE Manchester. If so all the edges have opposite
polarity so the initial setup of the IOC would have to be for the opposite
edge, and the reversals at different points.
As I have already said, you do not show us the setup code (hoe the IOC is
set, how the tOC is programmed etc.), so we have no way of knowing if
the settings or timings are even remotely right (also would need an
expanded view of a a few bits so we can measure the timings accurately).
However the big problem for me, is that you arrive on an edge (we don't
know which one this is, since you have not posted the setup), and then
you do not change the sample edge till you get to the sample data
part of the handler. You also have not shown how the toggle int edge
code is actually being performed (presumably 'INTEDG', is setup as a
bit controlling the detection edge for the IOC), but we do not know since
you gave not posted the settings for this.
What you post has essential parts missing. We cannot help unless you
post something that could work. |
Okay. I'll give you a detailed explanation.
1_ I'm attaching images of the TE times.
2_ The preamble time is 1.6 ms.
3_ I don't know why you're showing the logic analyzer as 65 bits, but it's standard Manchester.
4_ I've posted the logic analyzer settings above.
5_ I want to see the same data I see on the logic analyzer when I decode the incoming data.
code:
#include <16F1824.h>
#device ADC = 8
//
#fuses BROWNOUT //voltaj koruması 1.9v altına inince resetliyor
#fuses BORV19 //bu bölüm eeprom korumak için aktif
#fuses PUT
//
#FUSES NOMCLR
#FUSES NOLVP
#FUSES NOSTVREN
#FUSES NOIESO
#FUSES NOFCMEN
#FUSES NOWRT
#FUSES NOWDT
#FUSES NODEBUG
#use delay(internal = 32M)
//
#use fast_io(A)
#use fast_io(C)
//
#OPT 9
///////////
/////////////////////////// DEFINES ///////////////////////////////////////////
#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
////////////////////////// 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;
}
////
void reset_receiver(void){
DecodeSwitch = GotRisingEdge; // Durumu sıfırla
InputByteCounter = 0;
BitPosition = 0;
CurrentByte = 0;
TMR1_Overflow = 0;
set_timer1(0); // Timer'ı sıfırla
ClearBuffer(); // Buffer'ı temizle
INTEDG = 1;
}
// ****************************************************************************
// 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){
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:
{
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++){
paket[i] = DecodedInputData[i];
}
//
ready = 1;
DecodeSwitch = GotRisingEdge;
}
}
}
else if(TMR1_Overflow == 0 && TimerValue < TRANSITION_MIN_TIME){
delay_cycles(1);
}
else{
DecodeSwitch = GotRisingEdge;
}
break;
}
}
ToggleIntEdge();
/////////////////////////////////////////////////////////////
void main()
{
setup_comparator(NC_NC_NC_NC);
//
SETUP_ADC_PORTS(sAN3, VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64);
//
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64 | RTCC_8_BIT); //2 ms
enable_interrupts(INT_TIMER0);
set_timer0(0);
//
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); //65.5 ms overflow
enable_interrupts(INT_TIMER1);
set_timer1(0);
//
ClearBuffer();
//
enable_interrupts(INT_IOC_A1); //ioc kesmesi
clear_interrupt(INT_IOC_A1);
//
setup_ccp1(CCP_PWM);
setup_timer_2(t2_div_by_64 , 110 , 16);
set_pwm1_duty(0);
//
ENABLE_interrupts(GLOBAL);
//
set_tris_a(0b0010010);
set_tris_c(0b0010000);
//
output_a(0x00);
output_c(0x00);
//////////////////////////////////////////// finish code
Since I am not familiar with this code, I am only asking if the prediction is out of synchronization or not provided correctly and what precautions should I take against this?
If I set TRANSITION_MIN_TIME 1* TE (400 US) and hold the remote control down, if 30-40 packets of data come, it decodes only once but it decodes correctly.
#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 * TE
#define TRANSITION_MAX_TIME 2.5 * TE
 |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 554 Location: Montenegro
|
|
Posted: Wed Jul 23, 2025 5:07 am |
|
|
Quote: | I don't know why you're showing the logic analyzer as 65 bits, but it's standard Manchester. |
How? I counted the decoded ones and zeroes on the first picture YOU sent. |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Wed Jul 23, 2025 5:30 am |
|
|
PrinceNai wrote: | Quote: | I don't know why you're showing the logic analyzer as 65 bits, but it's standard Manchester. |
How? I counted the decoded ones and zeroes on the first picture YOU sent. |
I understand that. I don't know if the remote control or logic analyzer is reading 65 bits why. What should I do to decode it correctly in light of this information?
When I set the TRANSITION_MIN_TIME value to 1* TE (400 US) and hold down the remote control, if 30-40 packets of data arrive, it only decodes once, but it decodes correctly. How do you explain this? |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Wed Jul 23, 2025 5:35 am |
|
|
Is the reason why this code doesn't work stably because of 64 + 1 bits, that is, 1 extra bit? |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 554 Location: Montenegro
|
|
Posted: Wed Jul 23, 2025 5:40 am |
|
|
It doesn't work because it was not written to decode this shape of the input signal. Try to set your Manchester analyzer to 1 or 2 bit preamble and see what comes out. |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Wed Jul 23, 2025 6:11 am |
|
|
PrinceNai wrote: | It doesn't work because it was not written to decode this shape of the input signal. Try to set your Manchester analyzer to 1 or 2 bit preamble and see what comes out. |
 |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9568 Location: Greensville,Ontario
|
|
Posted: Wed Jul 23, 2025 6:20 am |
|
|
OK, easy question but is that 'manchester data' data exactly what you expect to decode ?
IE it's always the same 8 byte sequence. |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Wed Jul 23, 2025 6:45 am |
|
|
temtronic wrote: | OK, easy question but is that 'manchester data' data exactly what you expect to decode ?
IE it's always the same 8 byte sequence. |
YES true My code should solve Manchester in the same way as the logic analyzer does. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9568 Location: Greensville,Ontario
|
|
Posted: Wed Jul 23, 2025 8:07 am |
|
|
your program doesn't show printing of the decoded incoming data.....only capturing it. |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 317
|
|
Posted: Wed Jul 23, 2025 9:09 am |
|
|
temtronic wrote: | your program doesn't show printing of the decoded incoming data.....only capturing it. |
When ready is 1, I send a packet index UART. As you can see from the logic analyzer blue data above, as I said, I need to run this code according to this Manchester format.
code:
for(int i = 0; i < NUMBER_OF_BYTES; i++){
paket[i] = DecodedInputData[i];
}
////
ready = 1;
///////////
void ready_()
{
putc(paket[0]);
putc(paket[1]);
putc(paket[2]);
putc(paket[3]);
putc(paket[4]);
putc(paket[5]);
putc(paket[6]);
putc(paket[7]);
//
//eeprom_write_flag = 1;
//
output_toggle(led);//
ready = 0;
}
/////////////////////////////////
while(true){
..................................
..................................
if(ready == 1){
ready_();
} |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 554 Location: Montenegro
|
|
Posted: Wed Jul 23, 2025 9:17 am |
|
|
This is the image of the data how my (real hardware) transmitter sends data out. Now we just need to decode that back. Steps to do that (I'm sure there are other ways, this is mine):
1. detect preamble somewhere in the range of 4Te
2. detect and forget the first 0 - 1 combo (symbol). This is the part that is missing in the code you are using and the reason it is not working, because it was only a single 0 at the beginning of the stream you were trying to decode back then
3. Go through data portion of the stream and decode on the fly
My mind is set on state machines (switch statement), so I try to push every problem into that solution.
I do not intend to write a ready made code for you, but I'm willing to help you do it. Experience teaches me that you'll find another remote very soon, so it's better to understand what you are doing and why. The same goes for me, it wasn't meant in a bad way :-)
https://ibb.co/21vW9zBG |
|
 |
|