|
|
View previous topic :: View next topic |
Author |
Message |
temtronic
Joined: 01 Jul 2010 Posts: 9370 Location: Greensville,Ontario
|
|
Posted: Sun Feb 02, 2025 6:51 am |
|
|
sigh, I've been so focused on the 'data' aspect, I forgot about the 'sync' requirement.
Of course it'll never,ever work..
It needs a total rewrite, back to the beginning, literally..... |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 156
|
|
Posted: Sun Feb 02, 2025 7:14 am |
|
|
God damn it, I'm running out of hope on this issue. If you could help me, I'd be grateful. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 502 Location: Montenegro
|
|
Posted: Sun Feb 02, 2025 8:17 am |
|
|
I believe that is the reason for that lonely zero at the beginning, which is not part of the actual dala sent out. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9370 Location: Greensville,Ontario
|
|
Posted: Sun Feb 02, 2025 8:31 am |
|
|
OK, start fresh.
Create a program that SEES the 'preamble or sync or whatever you want to call that series of 8 pulses that are 2.5 ms wide.
My idea is to measure a pulse, if 2.5ms wide, increment a counter,loop looking for more.....
When you have 8, delay for say 1ms(?), then flash an LED,
Your logic analyzer should show the 'remote ' data as well as the LED status.
You need to do this before trying to read/decode the buttons.
there are 1,000s of hit for 'measuring pulse width with PIC', check code library here,could be something close to what you need. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 156
|
|
Posted: Sun Feb 02, 2025 9:08 am |
|
|
Thank you masters, I will do what you said and publish it here |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 156
|
|
Posted: Sun Feb 02, 2025 5:24 pm |
|
|
As you said, I did the preamble reading part and tested it. The preamble decode part works. 7 bytes of preamble data are taken, then the header part is taken, then the Manchester decode part is started, but in this way the Manchester decode part does not work.
Code: |
#include <16F1824.h> //RF TEST CODE
#device ADC = 8 //VERSION_2
#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
/////////////////////////////////////////////////////////////////////////////// register set.
#byte PIR3 = 0x013
#bit CCP3IF = PIR3.4
#byte CCP3CON = 0X313
#bit CCP3M3 = CCP3CON.3
///////////////////////////////////////////////////////////////////////////////
#define led pin_c3
/////////////////////////////////////////////////////////////////////////////// global int
int8 ready = 0;
//
unsigned int16 baslangic_time = 0;
unsigned int16 bitis_time = 0;
signed int16 sinyal_time = 0;
//
int8 ilk_yakalama = 0;
int8 puls_count = 0;
int8 works = 0;
int8 sync_flag = 0;
/////////////////////////////////////////////////////////////////////////////// preamble SYNC DECODE (7 byte)
#INT_CCP3
void ccp3_kesmesi(){
if(CCP3IF == 1){
CCP3IF = 0;
puls_count ++;
//
if(ilk_yakalama == 0){
baslangic_time = CCP_3_HIGH;
ilk_yakalama = 1;
}
else if(ilk_yakalama == 1){
bitis_time = CCP_3_LOW;
sinyal_time = (bitis_time - baslangic_time);
//
if(sinyal_time >= 170 && sinyal_time <= 210){} //signal time measure
else{
puls_count = 0;
}
//
if(puls_count >= 7 && sinyal_time >= 170 && sinyal_time <= 210){ // 7 byte preamble sync data (2.5 ms x 7 piece)
sync_flag = 1;
}
//
if(sync_flag == 1 && sinyal_time >= 130 && sinyal_time <= 150){ //headers (4.8 ms)
output_toggle(led);
works = 1; //manchester decode start
sync_flag = 0;
}
//
if(puls_count > 7){ //sync count reset
puls_count = 0;
}
//
ilk_yakalama = 0;
set_timer1(0);
CCP_3_HIGH = 0;
CCP_3_LOW = 0;
}}
////
clear_interrupt(int_ccp3);
}
///////////////////////////////////////////////////////////////////////////////
#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_a2);
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;
output_high(led);
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;
}
works = 0;
//
}
///////////////////////////////////////////////////////////////////////////////
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_timer0);
//
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1); //CCP3 time adj
set_timer1(0);
//
setup_ccp3(CCP_CAPTURE_RE); //RISING EDGE
enable_interrupts(INT_CCP3);
CCP_3_HIGH = 0;
CCP_3_LOW = 0;
clear_interrupt(int_ccp3);
//
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);
//
while(true){
///////////////////////////////////////////////////////////////////////////////
if(XTMR < 512){
XTMR=0;
}
//
if(ready == 1){
ready_();
}
//
if(works == 1){
InitReceiver();
}
//*****************************************************************************
}}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9370 Location: Greensville,Ontario
|
|
Posted: Sun Feb 02, 2025 8:10 pm |
|
|
OK had a quick look...
and I think the program needs to do the following..
main()
loop starts here
enable CCP3 interrupt
now..... CCP3 ISR waits for 7 pulses ,sets flag 'sync found'
disable CCP3 interrupt //could be 2nd last line in CCP3 ISR
might need a delay(1ms) here....//a pause between sync ...and ... data
enable timer0 interrupt// could be last line in CCP3 ISR
now... timer 0 captures ' 7 bytes of data'
disable timer0 interrupt // could be last line in Timer0 ISR
parse buffer B[] to get key pressed
send information to PC terminal program
loop ends here
The data in B[] should look like the actual bytes in the logic analyzer
You have to disable the CCP3 interrupt when 'sync' is found , otherwise real 'data' will cause CCP3 interrupts.Same for the Timer0 ISR. 'clearing' an interrupt only 'resets' the flag that an interrupt occoured. 'disable' prevents all incoming pulses on the input pin from doing 'anything'.
curious why the 1600 baud rate for the RS232 to PC ?
You're making great progress !! It's best to learn by doing, that way you'll understand WHAT is happening better. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 156
|
|
Posted: Mon Feb 03, 2025 5:25 am |
|
|
temtronic wrote: | OK had a quick look...
and I think the program needs to do the following..
main()
loop starts here
enable CCP3 interrupt
now..... CCP3 ISR waits for 7 pulses ,sets flag 'sync found'
disable CCP3 interrupt //could be 2nd last line in CCP3 ISR
might need a delay(1ms) here....//a pause between sync ...and ... data
enable timer0 interrupt// could be last line in CCP3 ISR
now... timer 0 captures ' 7 bytes of data'
disable timer0 interrupt // could be last line in Timer0 ISR
parse buffer B[] to get key pressed
send information to PC terminal program
loop ends here
The data in B[] should look like the actual bytes in the logic analyzer
You have to disable the CCP3 interrupt when 'sync' is found , otherwise real 'data' will cause CCP3 interrupts.Same for the Timer0 ISR. 'clearing' an interrupt only 'resets' the flag that an interrupt occoured. 'disable' prevents all incoming pulses on the input pin from doing 'anything'.
curious why the 1600 baud rate for the RS232 to PC ?
You're making great progress !! It's best to learn by doing, that way you'll understand WHAT is happening better. |
mr.temtronic Thank you for your wishes, I am publishing 3 versions. The Manchester decode section is stubborn and does not work. When I close the ccp3_int cut, I cannot open the ccp3_int in the Manchester decode section because the code does not work in the Manchester decode section. I did what they said but could not get the result.
baund 1600 It doesn't make sense, it's a setting from the past.
Code: | #include <16F1824.h> //RF TEST CODE
#device ADC = 8 //VERSION_3
#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
/////////////////////////////////////////////////////////////////////////////// register set.
#byte PIR3 = 0x013
#bit CCP3IF = PIR3.4
#byte CCP3CON = 0X313
#bit CCP3M3 = CCP3CON.3
///////////////////////////////////////////////////////////////////////////////
#define led pin_c3
/////////////////////////////////////////////////////////////////////////////// global int
int8 ready = 0;
//
unsigned int16 baslangic_time = 0;
unsigned int16 bitis_time = 0;
signed int16 sinyal_time = 0;
//
int8 ilk_yakalama = 0;
int8 puls_count = 0;
int8 works = 0;
int8 sync_flag = 0;
/////////////////////////////////////////////////////////////////////////////// preamble SYNC DECODE (7 byte)
#INT_CCP3
void ccp3_kesmesi(){
if(CCP3IF == 1){
CCP3IF = 0;
puls_count ++;
//
if(ilk_yakalama == 0){
baslangic_time = CCP_3_HIGH;
ilk_yakalama = 1;
}
else if(ilk_yakalama == 1){
bitis_time = CCP_3_LOW;
sinyal_time = (bitis_time - baslangic_time);
//
if(sinyal_time >= 170 && sinyal_time <= 210){} //signal time measure
else{puls_count = 0;}
//
if(puls_count >= 7 && sinyal_time >= 170 && sinyal_time <= 210){ // 7 byte preamble sync data (2.5 ms x 7 piece)
sync_flag = 1;
}
//
if(sync_flag == 1 && sinyal_time >= 130 && sinyal_time <= 150){ //headers (4.8 ms)
output_toggle(led);
works = 1; //manchester decode start
sync_flag = 0;
}
//
if(puls_count > 7){ //sync count reset
puls_count = 0;
}
//
ilk_yakalama = 0;
set_timer1(0);
CCP_3_HIGH = 0;
CCP_3_LOW = 0;
}}
////
clear_interrupt(int_ccp3);
//disable_interrupts(INT_CCP3);
//
}
///////////////////////////////////////////////////////////////////////////////
#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_a2);
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;
output_high(led);
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;
}
//
disable_interrupts(int_timer0); //timer0 disable
//enable_interrupts(INT_CCP3); //ccp3 enable
//
}
///////////////////////////////////////////////////////////////////////////////
void InitReceiver()
{
enable_interrupts(int_timer0);
delay_ms(1);
set_timer0(0);
RFstate = TRFreset;
RFFull = 0;
XTMR = 0;
works = 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_timer0);
//
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1); //CCP3 time adj
set_timer1(0);
//
setup_ccp3(CCP_CAPTURE_RE); //RISING EDGE
enable_interrupts(INT_CCP3);
CCP_3_HIGH = 0;
CCP_3_LOW = 0;
clear_interrupt(int_ccp3);
//
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);
//
while(true){
///////////////////////////////////////////////////////////////////////////////
if(XTMR < 512){
XTMR=0;
}
//
if(ready == 1){
ready_();
}
//
if(works == 1){
InitReceiver();
}
//*****************************************************************************
}}
|
|
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 156
|
|
Posted: Mon Feb 03, 2025 2:28 pm |
|
|
I am sure about the 4 settings here why the code is not working
Code: |
#define HIGH_TO -10
#define LOW_TO 10
#define SHORT_HEAD 20
#define LONG_HEAD 45
|
it is not clear what the values of these should be, what the units are, when I debug it is stuck in the synchronization header and the measurement is reset |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9370 Location: Greensville,Ontario
|
|
Posted: Mon Feb 03, 2025 4:42 pm |
|
|
here's the logic I'm thinking you need..
while(true){
///////////////////////////////////////////////////////////////////////////////
enable_interrupts( INT_CCP3); // this aloows PIC to 'see' the sync'
if(works==1) { //got 'sync' !!
disable_interrupts(INT_CCP3); //stop 'data' from triggering the 'sync' ISR
enable_interrupt( Timer0); // now get 'data' bits
}
if(ready==1) { //got 'data' !!
disable_interrupts(Timer0);
ready_(); //display 'data' buffer B[] contents
}
if(XTMR < 512){
XTMR=0;
}
//
init_receiver();
delay_ms(50); //just a small main loop delay.
}
in main()
1st you setup registers and stuff but do NOT enable the interrupts
in a loop.....
you enable the CCP3 ISR and it gets 'sync'
then disable CCP3 interrupt ,
then enable the timer0 ISR ,and collect the 'data'
then disable Timer0 interrupt.
then send 'data' to PC screen
than small delay
then go back to top of loop
It does compile but I can't test. it was also very hard for me to see the screen, old age,light fonts, sigh.
Think of the program 'flow' like a 'high security' building double door entrance
you unlock the 1st door ( enable the 'sync' interrupt' )
open and enter ( 'sync' bytes found ! )
lock the 1st door (prevent following bytes in )
unlock 2nd door( enable timer0 interrupt
open and enter house ('data' bytes found ! )
lock 2nd door ( disable timer0 )
show data ( send 'data' to PC )
I may not have it exact , hope you can understand the 'flow' of operations...
You're really close though !!! |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 156
|
|
Posted: Tue Feb 04, 2025 6:33 am |
|
|
temtronic wrote: | here's the logic I'm thinking you need..
while(true){
///////////////////////////////////////////////////////////////////////////////
enable_interrupts( INT_CCP3); // this aloows PIC to 'see' the sync'
if(works==1) { //got 'sync' !!
disable_interrupts(INT_CCP3); //stop 'data' from triggering the 'sync' ISR
enable_interrupt( Timer0); // now get 'data' bits
}
if(ready==1) { //got 'data' !!
disable_interrupts(Timer0);
ready_(); //display 'data' buffer B[] contents
}
if(XTMR < 512){
XTMR=0;
}
//
init_receiver();
delay_ms(50); //just a small main loop delay.
}
in main()
1st you setup registers and stuff but do NOT enable the interrupts
in a loop.....
you enable the CCP3 ISR and it gets 'sync'
then disable CCP3 interrupt ,
then enable the timer0 ISR ,and collect the 'data'
then disable Timer0 interrupt.
then send 'data' to PC screen
than small delay
then go back to top of loop
It does compile but I can't test. it was also very hard for me to see the screen, old age,light fonts, sigh.
Think of the program 'flow' like a 'high security' building double door entrance
you unlock the 1st door ( enable the 'sync' interrupt' )
open and enter ( 'sync' bytes found ! )
lock the 1st door (prevent following bytes in )
unlock 2nd door( enable timer0 interrupt
open and enter house ('data' bytes found ! )
lock 2nd door ( disable timer0 )
show data ( send 'data' to PC )
I may not have it exact , hope you can understand the 'flow' of operations...
You're really close though !!! |
mr. temtronic I did exactly what you said, but the Manchester decode part is not working. I added the simulation images. The Manchester decode cannot pass the reset part in the code part. The code does not recognize headers or there is another reason for the problem here.
Check out the pictures below and I hope you understand what I mean.
Code: | #include <16F1824.h> //RF TEST CODE
#device ADC = 8 //VERSION_4
#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
/////////////////////////////////////////////////////////////////////////////// register set.
#byte PIR3 = 0x013
#bit CCP3IF = PIR3.4
#byte CCP3CON = 0X313
#bit CCP3M3 = CCP3CON.3
#byte TMR0 = 0x015
#byte INTCON = 0X00B
#bit T0IF = INTCON.2
#bit T0IE = INTCON.5
///////////////////////////////////////////////////////////////////////////////
#define led pin_c3
/////////////////////////////////////////////////////////////////////////////// global variable
int8 ready = 0;
//
unsigned int16 baslangic_time = 0;
unsigned int16 bitis_time = 0;
signed int16 sinyal_time = 0;
//
int8 ilk_yakalama = 0;
int8 puls_count = 0;
int8 works = 0;
//int8 sync_flag = 0;
/////////////////////////////////////////////////////////////////////////////// preamble SYNC DECODE (7 byte)
#INT_CCP3
void ccp3_kesmesi(){
if(CCP3IF == 1){
CCP3IF = 0;
puls_count ++;
//
if(ilk_yakalama == 0){
baslangic_time = CCP_3_HIGH;
ilk_yakalama = 1;
}
else if(ilk_yakalama == 1){
bitis_time = CCP_3_LOW;
sinyal_time = (bitis_time - baslangic_time);
//
if(sinyal_time >= 165 && sinyal_time <= 210){} //signal time measure
else{puls_count = 0;}
//
if(puls_count >= 7 && sinyal_time >= 165 && sinyal_time <= 210){ // 7 byte preamble sync data (2.5 ms x 7 piece)
//output_toggle(led);
works = 1; //manchester decode start
}
//
if(puls_count > 8){ //sync count reset
puls_count = 0;
}
//
ilk_yakalama = 0;
set_timer1(0);
CCP_3_HIGH = 0;
CCP_3_LOW = 0;
}}
////
clear_interrupt(int_ccp3);
//
}
///////////////////////////////////////////////////////////////////////////////
#define CLOCK 4 //MHz
#define TE 640 //us
#define OVERSAMPLING 3
#define PERIOD TE / OVERSAMPLING * 4 / CLOCK
#define NBIT 56
int8 B[7];
static int8 RFstate;
static signed int8 RFcount;
static int8 Bptr;
static int8 BitCount;
int16 XTMR = 0;
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_a2);
TMR0 -= PERIOD;
T0IF = 0;
OUTPUT_TOGGLE(LED);
//
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;
output_high(led);
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:
default:
//
RFstate = TRFSYNC;
RFcount = 0;
Bptr = 0;
BitCount = 0;
break;
}
//
T0IE = 0; //timer0_int disable
enable_interrupts(INT_CCP3); //ccp3 enable
//
}
///////////////////////////////////////////////////////////////////////////////
void InitReceiver()
{
T0IF = 0;
T0IE = 1; //timer0_int enable
//
RFstate = TRFreset;
RFFull = 0;
XTMR = 0;
works = 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
//
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1); //CCP3 time adj
set_timer1(0);
//
setup_ccp3(CCP_CAPTURE_RE); //RISING EDGE
enable_interrupts(INT_CCP3);
CCP_3_HIGH = 0;
CCP_3_LOW = 0;
clear_interrupt(int_ccp3);
//
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);
//
enable_interrupts(INT_CCP3);
while(true){
///////////////////////////////////////////////////////////////////////////////
if(works == 1){
disable_interrupts(INT_CCP3);
InitReceiver();
delay_ms(50);
}
if(ready == 1){
disable_interrupts(int_Timer0);
ready_();
}
if(XTMR < 512){
XTMR=0;
}
//
//*****************************************************************************
}}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9370 Location: Greensville,Ontario
|
|
Posted: Tue Feb 04, 2025 7:22 am |
|
|
Sorry, I can't help you with any PROTEUS projects, as it's well known that it does not actually work properly. One glaring error in the picture, have a look at D1, the red LED. |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 156
|
|
Posted: Tue Feb 04, 2025 7:56 am |
|
|
temtronic wrote: | Sorry, I can't help you with any PROTEUS projects, as it's well known that it does not actually work properly. One glaring error in the picture, have a look at D1, the red LED. |
The issue is not Proteus, I am trying to show you the truth, I am trying to explain that the Manchester decode code cannot pass the sync section, I think the reason is the header section, maybe it is in the setting. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9370 Location: Greensville,Ontario
|
|
Posted: Tue Feb 04, 2025 8:27 am |
|
|
query.
Are you using real hardware or is this a Proteus Simulation ? |
|
|
bulut_01
Joined: 24 Feb 2024 Posts: 156
|
|
Posted: Tue Feb 04, 2025 9:59 am |
|
|
I am using real hardware. I see real circuit values by putting putc in some places. Whatever I see in Proteus, I see the same value in the real circuit. This timer0 overflow decode needs to have a 72 ms cycle, is that correct? |
|
|
|
|
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
|