View previous topic :: View next topic |
Author |
Message |
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Sat Feb 01, 2025 11:57 am |
|
|
You cannot take code written for one PIC and expect it to work in another PIC.
You have to read the datasheets and the source code and make appropriate changes.
AN744 was written 20 years ago, and it worked on the PIC it was specifically written for. You have a 'new' PIC, 20 years newer in fact, so LOTS of things are not the same. Back then to erase the PIC, you spent 15 minutes at the water cooler, waiting for the UV eraser to remake a blank PIC ! This gets down to reading a few hundred pages of datasheets, some books on C code,a few 'application notes' and some serious time 'bench testing', and 'playing computer' ( that's YOU single stepping through every line of code to understand what should be happening).
I don't have your remote, PIC or logic analyzer so I can't edit AN744 to make it work for you as I can't test my code. You do have all the tools you need though ! |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sat Feb 01, 2025 12:07 pm |
|
|
This issue has tired me. Do you have a decode code with the logic in the AN744 document? From here I understand that I cannot run the AN744 RXI code. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Sat Feb 01, 2025 12:24 pm |
|
|
decode ?
It returns the data in a buffer called B[7]. That should be the 56 bits of your remote data. It's up to you to 'decode' it .
The contents of the buffer should be the same as what you see on the logic analyzer output. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sat Feb 01, 2025 12:32 pm |
|
|
The code does not go to this section B[7] is always 0, the buffer is always 0. What should I fix in the code to run it? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Sat Feb 01, 2025 1:29 pm |
|
|
last program would not compile...
error..
for(int i = 0; i < 7; i++){
int is not require
also added these variables
char i; //jay added
char led;
char ready;
it now compiles
naturally I can't test as no PIC, no transmitter, no receiver and no logic analyzer.
ALSO critical.. you must delet...
//
for(int i = 0; i < 7; i++){
putc(B[i]);}
}
about 10 lines into the ISR
you cannot print inside and ISR......(takes too long )
Last edited by temtronic on Sat Feb 01, 2025 1:36 pm; edited 1 time in total |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sat Feb 01, 2025 1:35 pm |
|
|
When I debug buffer b[7] the program never branches here. I couldn't find out if it's a problem with the settings or if I'm missing something in the algorithm. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sat Feb 01, 2025 2:29 pm |
|
|
mr. temtronic an744 I need help to translate this code properly according to ccs. I am making a mistake. I need help to translate this properly according to the code in an744. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Sat Feb 01, 2025 2:39 pm |
|
|
post your complete current version |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sat Feb 01, 2025 2:45 pm |
|
|
temtronic wrote: | post your complete current version |
Code: | #include <16F1824.h>
#device ADC = 8
#FUSES NOWDT
#fuses PUT
//
#FUSES NOMCLR
#FUSES NOLVP
#FUSES NOSTVREN
#FUSES NOIESO
#FUSES NOFCMEN
#FUSES NOWRT
#FUSES NODEBUG
#use delay(internal = 4M)
//
#OPT 9
//
#use fast_io(A)
#use fast_io(C)
//
#use rs232(baud = 1600, parity = N, xmit = PIN_a0, rcv = PIN_a1, bits = 8, STREAM = UART1, stop = 1, errors) //uart setup
///////////////////////////////////////////////////////////////////////////////
int8 ready = 0;
///////////////////////////////////////////////////////////////////////////////
#define CLOCK 4 //MHz
#define TE 640 //us
#define OVERSAMPLING 3
#define PERIOD TE / OVERSAMPLING * 4 / CLOCK
#define NBIT 55
int8 B[7];
static int8 RFstate;
static signed int8 RFcount;
static int8 Bptr;
static int8 BitCount;
int16 XTMR;
volatile int1 RFFull;
volatile int1 RFBit;
#define TRFreset 0
#define TRFSYNC 1
#define TRFUNO 2
#define TRFZERO 3
#define HIGH_TO -10
#define LOW_TO 10
#define SHORT_HEAD 20
#define LONG_HEAD 45
/////////////////////////////////////////////////////////////////////////////// manchester decode
#INT_TIMER0
void TIMER0_isr(void){
RFBit = input(pin_a1);
set_timer0(get_timer0() - PERIOD);
set_timer0(0);
//
XTMR++;
if(RFFull)
return;
//
switch(RFstate)
{
case TRFUNO:
if (RFBit == 0)
{
RFstate = TRFZERO;
}
else
{
RFcount--;
if(RFcount < HIGH_TO)
RFstate = TRFreset;
}
break;
case TRFZERO:
if (RFBit)
{
//
RFstate= TRFUNO;
B[Bptr] >>= 1;
//
if(RFcount >= 0){
B[Bptr] += 0x80;
//
}
RFcount = 0;
//
if(( ++BitCount & 7) == 0)
Bptr++;
if(BitCount == NBIT) //finish
{
RFstate = TRFreset;
RFFull = TRUE;
disable_interrupts(int_timer0);
}
}
else
{
RFcount++;
if(RFcount >= LOW_TO)
{
RFstate = TRFSYNC;
Bptr = 0;
BitCount = 0;
}
}
break;
case TRFSYNC:
if (RFBit)
{
//
//
if((RFcount < SHORT_HEAD) || ( RFcount >= LONG_HEAD))
{
RFstate = TRFreset;
break;
}
else
{
RFcount = 0;
RFstate= TRFUNO;
}
}
else
{
RFcount++;
}
break;
case TRFreset:
break;
default:
//
RFstate = TRFSYNC;
RFcount = 0;
Bptr = 0;
BitCount = 0;
break;
}
//
ready = 1;
////
}
///////////////////////////////////////////////////////////////////////////////
void InitReceiver()
{
enable_interrupts(int_timer0);
set_timer0(0);
RFstate = TRFreset;
RFFull = 0;
XTMR = 0;
}
///////////////////////////////////////////////////////////////////////////////
void ready_()
{
for(int i = 0; i < 7; i++){
putc(B[i]);}
ready = 0;
}
///////////////////////////////////////////////////////////////////////////////
void main()
{
setup_comparator(NC_NC_NC_NC);
//
setup_timer_0(T0_INTERNAL | T0_DIV_128 | T0_8_BIT); //32 ms adj
//
disable_interrupts(int_rda);
disable_interrupts(INT_TBE);
enable_interrupts(GLOBAL);
//
set_tris_a(0b0110110);
set_tris_c(0b0010100);
//
output_a(0x00);
output_c(0x00);
//
InitReceiver();
while(true){
///////////////////////////////////////////////////////////////////////////////
if(XTMR < 512)
XTMR=0;
///
if(ready == 1){
ready_();
}
//*****************************************************************************
}}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Sat Feb 01, 2025 5:27 pm |
|
|
hmm...
#define TE 640 //us
should be 604 us ( 1/2 of 1208us )
also
add to your program 1st 2 lines..
// test program for RF project.
// version nnn
that way when posting we can see and compare to previous ones... |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 502 Location: Montenegro
|
|
Posted: Sun Feb 02, 2025 1:28 am |
|
|
Code: | #INT_TIMER0
void TIMER0_isr(void){
RFBit = input(pin_a1);
set_timer0(get_timer0() - PERIOD);
set_timer0(0); |
set_timer0(0) is not OK. In app note the interrupt flag gets cleared, not the timer set to 0. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sun Feb 02, 2025 2:11 am |
|
|
PrinceNai wrote: | Code: | #INT_TIMER0
void TIMER0_isr(void){
RFBit = input(pin_a1);
set_timer0(get_timer0() - PERIOD);
set_timer0(0); |
set_timer0(0) is not OK. In app note the interrupt flag gets cleared, not the timer set to 0. |
Write here what is correct |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sun Feb 02, 2025 3:27 am |
|
|
temtronic wrote: | hmm...
#define TE 640 //us
should be 604 us ( 1/2 of 1208us )
also
add to your program 1st 2 lines..
// test program for RF project.
// version nnn
that way when posting we can see and compare to previous ones... |
#DEFINE TE 604 In this part, all values starting from 600 to 800 were tried. The code does not branch to the ffinish section at all.
Code: | #include <16F1824.h> //RF TEST CODE
#device ADC = 8 //VERSION_1
#FUSES NOWDT
#fuses PUT
//
#FUSES NOMCLR
#FUSES NOLVP
#FUSES NOSTVREN
#FUSES NOIESO
#FUSES NOFCMEN
#FUSES NOWRT
#FUSES NODEBUG
#use delay(internal = 4M)
//
#OPT 9
//
#use fast_io(A)
#use fast_io(C)
//
#use rs232(baud = 1600, parity = N, xmit = PIN_a0, rcv = PIN_a1, bits = 8, STREAM = UART1, stop = 1, errors) //uart setup
///////////////////////////////////////////////////////////////////////////////
int8 ready = 0;
///////////////////////////////////////////////////////////////////////////////
#define CLOCK 4 //MHz
#define TE 604 //us
#define OVERSAMPLING 3
#define PERIOD TE / OVERSAMPLING * 4 / CLOCK
#define NBIT 55
int8 B[7];
static int8 RFstate;
static signed int8 RFcount;
static int8 Bptr;
static int8 BitCount;
int16 XTMR;
volatile int1 RFFull;
volatile int1 RFBit;
#define TRFreset 0
#define TRFSYNC 1
#define TRFUNO 2
#define TRFZERO 3
#define HIGH_TO -10
#define LOW_TO 10
#define SHORT_HEAD 20
#define LONG_HEAD 45
/////////////////////////////////////////////////////////////////////////////// manchester decode
#INT_TIMER0
void TIMER0_isr(void)
{
RFBit = input(pin_a1);
set_timer0(get_timer0() - PERIOD);
set_timer0(0);
//
XTMR++;
if(RFFull)
return;
//
switch(RFstate)
{
case TRFUNO:
if (RFBit == 0)
{
RFstate = TRFZERO;
}
else
{
RFcount--;
if(RFcount < HIGH_TO)
RFstate = TRFreset;
}
break;
case TRFZERO:
if (RFBit)
{
//
RFstate= TRFUNO;
B[Bptr] >>= 1;
//
if(RFcount >= 0){
B[Bptr] += 0x80;
//
}
RFcount = 0;
//
if(( ++BitCount & 7) == 0)
Bptr++;
if(BitCount == NBIT) //finish
{
RFstate = TRFreset;
RFFull = TRUE;
ready = 1;
}
}
else
{
RFcount++;
if(RFcount >= LOW_TO)
{
RFstate = TRFSYNC;
Bptr = 0;
BitCount = 0;
}
}
break;
case TRFSYNC:
if (RFBit)
{
//
//
if((RFcount < SHORT_HEAD) || ( RFcount >= LONG_HEAD))
{
RFstate = TRFreset;
break;
}
else
{
RFcount = 0;
RFstate= TRFUNO;
}
}
else
{
RFcount++;
}
break;
case TRFreset:
break;
default:
//
RFstate = TRFSYNC;
RFcount = 0;
Bptr = 0;
BitCount = 0;
break;
}
//
}
///////////////////////////////////////////////////////////////////////////////
void InitReceiver()
{
enable_interrupts(int_timer0);
set_timer0(0);
RFstate = TRFreset;
RFFull = 0;
XTMR = 0;
}
///////////////////////////////////////////////////////////////////////////////
void ready_()
{
for(int i = 0; i < 7; i++){
putc(B[i]);}
ready = 0;
}
///////////////////////////////////////////////////////////////////////////////
void main()
{
setup_comparator(NC_NC_NC_NC);
//
setup_timer_0(T0_INTERNAL | T0_DIV_128 | T0_8_BIT); //32 ms adj
//
disable_interrupts(int_rda);
disable_interrupts(INT_TBE);
enable_interrupts(GLOBAL);
//
set_tris_a(0b0110110);
set_tris_c(0b0010100);
//
output_a(0x00);
output_c(0x00);
//
InitReceiver();
while(true){
///////////////////////////////////////////////////////////////////////////////
if(XTMR < 512){
XTMR=0;
}
///
if(ready == 1){
ready_();
}
//*****************************************************************************
}}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19649
|
|
Posted: Sun Feb 02, 2025 3:57 am |
|
|
You are ignoring what I told you.
The data stream here is a _modified_ Manchester encoding system.
Ift has a header on the front designed I suspect for synchronisation
(though the whole key of Manchester encoding is it does not need this).
You have to change the state machine used, so that it handles detecting and
stepping through the header clocks, before launching into the standard
decoder for the Manchester data.
All the code sets you have are for standard Manchester encoding without this
header. Hence do not work. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 159
|
|
Posted: Sun Feb 02, 2025 6:45 am |
|
|
Ttelmah wrote: | You are ignoring what I told you.
The data stream here is a _modified_ Manchester encoding system.
Ift has a header on the front designed I suspect for synchronisation
(though the whole key of Manchester encoding is it does not need this).
You have to change the state machine used, so that it handles detecting and
stepping through the header clocks, before launching into the standard
decoder for the Manchester data.
All the code sets you have are for standard Manchester encoding without this
header. Hence do not work. |
Can you give an example of what you said with code? I am not an expert on this subject and this topic has tired me a lot, but I have to do it. |
|
|
|