CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

HS1527 decode problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
AnthonyRFC



Joined: 21 Jun 2015
Posts: 16
Location: Venezuela

View user's profile Send private message

HS1527 decode problem
PostPosted: Fri Aug 31, 2018 4:28 pm     Reply with quote

Hi, I'm trying to control a system using a commercial 4-buttons RF control that uses the HS1527 chip.

Like all 8-pin RF chip, it sends the data using a preamble, later a 20 bit unique number and, finally, 4 bits for user needs. Preamble is 400uS HIGH and 10,2mS LOW pulse, the 24bit rest is modulated changing the high pulse time and keeping the ON + OFF time the same (approx 1,3mS). "1" bit is 1mS HIGH - 300uS LOW and "0" bit is 400uS HIGH-1mS LOW.

I wrote a code to receive and decode the data coming from the control, I'm using one led per button. First, I made a test using a wire and it worked perfect: pressed A button and turned on A led, so on so for.

BUT when I installed the 433MHz ASK receiver, I only can walk like 50 cm and the microcontroller stops turning on the leds, I tried different "methods" like using a wide range of limits for pulse ON/OFF time but it only cause me worse result.

I'm using RB0 ext interrupt and timer 1 to catch the data and a char array ("sbits[24]") to store and later group individual bits to form 3 bytes.

In the main section, the pic only compares the 3 bytes and decides which LED to turn ON.

This is my code:
Code:

#include <16F877A.h>
#fuses XT,NOWDT,PROTECT
#use delay(clock=4000000)

#define A pin_b5  //Test LED
#define B pin_b4
#define C pin_b3
#define D pin_b2
#define E pin_b1
#define OFF output_low
#define ON  output_high

/////////////////////// LIBRERIAS //////////////////////
//#include "flex_lcd_ccs.c"

/////////////////////// VARIABLES //////////////////////
int16 th=0x00, tl=0x00, t1=0x00,t2=0x00;
int1  bandera_flanco=0, resta=0,arma_bit=0, preamble=0, data_work=0,candadol=0, candadoh=0,first_isr=0;
int8  isr_number=0, nbits=0;
int8  counter1=0, counter0=0, copia1=0,copia0=0;
char sbits[24];
int bits[8]= {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int bytes[3]={0x00,0x00,0x00};
int i,j;
////////////////////// INTERRUPCION EXTERNA ///////////
#int_ext
void ext_isr() {
  if(!first_isr){ //is the first ext interrup?
  set_timer1(0);//Reset the timer1 counter
  first_isr=1;  //Flag to 1
  }
  if(!bandera_flanco){         // LOW TO HIGH edge??
    t1=get_timer1();           // Yes, I catch timer 1 counter value (1tick is 8uS)
    set_timer1(0);             // Re-start timer 1
    ext_int_edge(0,H_TO_L);    // Change edge setting to H-to-L
    bandera_flanco=1;          // Change edge flag.
      if(resta){
      tl=t1;
      resta=0;
      }//Fin del proceso de calculo del tiempo en bajo
   if ((tl>25)&&(tl<1380)){  // HERE I check if the incoming pulse is within specifications
      isr_number++;          // If so, I run a counter to decide when start to evaluate if is a "1" bit or "0" bit
   }
   else{
   isr_number=1;
   arma_bit=0;
   nbits=0;
   preamble=0;
   }
   if(isr_number==3){  //Is 3 interrup?
     isr_number=1;     //Restart interrup counter.
     arma_bit=1;       //This flag is to init the bit evaluation.
 
   }
}//Fin manejo del flanco ascendente
else{                          // HIGH-to-LOW edge?
    t2=get_timer1();           // Catch the timer1 counter value
    ext_int_edge(0,L_TO_H);    // Change edge setting to L-to-H
    bandera_flanco=0;          // Change edge flag.
    set_timer1(0);             // Re-start timer 1
    if (!resta){
    th=t2;
    resta=1;
    }

  if ((th>25)&&(th<148)){ //HERE I check if the incoming pulse is within specifications
    isr_number++; }
  else{
   isr_number=1;
   arma_bit=0;
   nbits=0;
   preamble=0;
  }
}//Fin del manejo del flanco descendente

if((arma_bit)&&(preamble)){             //Here the pic evaluate the different pulses combinations.
  if(((th>108)&&(th<148))&&((tl>25)&&(tl<53))){   //Is "1" bit???
  sbits[nbits]='1';   //Yes, add '1' to the char array
  counter1++;
    if(++nbits==24){
     data_work=1;
     preamble=0;
     nbits=0;
     arma_bit=0;
   
    }
  }
  if(((th>25)&&(th<53))&&((tl>108)&&(tl<148))){ //Is "0" bit???
    sbits[nbits]='0';  //Yes, add '0' to the char array
    counter0++;
      if(++nbits==24){
        data_work=1;
        preamble=0;
        nbits=0;
        arma_bit=0;
  /*
    if(!candadol){
    copia0=counter0;
    candadol=1;
    }
    if(!candadoh){
    copia1=counter1;
    candadoh=1;
        }
    */
         }
  }
  arma_bit=0;
}//Fin de bits de datos
if((arma_bit)&&(!preamble)){
  if(((th>30)&&(th<53))&&((tl>1200)&&(tl<1370))){//Is the preamble???
  preamble=1;  //Yes, preamble flag to 1.
  arma_bit=0;
  }
}
}//Fin del manejo de la interrupción externa




void convierte_bits_a_bytes(void){   //This subfuction translate the char array to 3 bytes (24bits).

  for(i=0;i<3;++i){
    Bytes[i]=0x00;
    for(j=0;j<8;++j){
      if(sbits[(i*8)+j]=='1'){
        bytes[i]=bytes[i]|Bits[j];
      }
    }
  }
}

void main() {

  disable_interrupts(global);
  setup_adc_ports(NO_ANALOGS);
  setup_adc(ADC_OFF);
  setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
  setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); //1 tick is 8uS
  setup_timer_2(T2_DISABLED,0,1);
  setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64);
  setup_adc(ADC_CLOCK_INTERNAL);
  OFF(A);
  OFF(B);
  OFF(C);
  OFF(D);
  OFF(E);
  delay_ms(200);
  ext_int_edge(L_TO_H);


 enable_interrupts(int_ext);
 enable_interrupts(global);

  while(1){
   if(data_work){   //Is valid data present?
   convierte_bits_a_bytes(); //char array to bytes.
   data_work=0;
   if (( bytes[0]==35)&&( bytes[1]==173)&&( bytes[2]==129)){
   ON(A);
   }
   if (( bytes[0]==35)&&( bytes[1]==173)&&( bytes[2]==130)){
   ON(B);
   }
   if (( bytes[0]==35)&&( bytes[1]==173)&&( bytes[2]==132)){
   ON(C);
   }
   if (( bytes[0]==35)&&( bytes[1]==173)&&( bytes[2]==131)){
   ON(E);
   }
   delay_ms(40);
   }
  OFF(A);
  OFF(B);
  OFF(C);
  OFF(D);
  OFF(E);

  }//Fin del while
} //Fin del main


Any help will be appreciated,

Regards,

Anthony
_________________
From Cumaná, Venezuela.
temtronic



Joined: 01 Jul 2010
Posts: 8280
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Aug 31, 2018 5:27 pm     Reply with quote

I was curious, so I downloaded the datasheet for the HS1527. One big issue is that the actual dutycycle spec for the device varies widely depending on the VCC it's running at. With an Rosc of 300K, DC can be 1.32 to 1.99ms !
It could be that your code is designed to run fine at 1.32ms BUT when the voltage drops, the transmitter is now 'out of spec', running at 1.99 ms.
I'd use an oscilloscope to actually see the transmitter data and confirm the duty cycle THEN adjust your program to 'sync' to that speed.
Another possible problem will be the antenna used. Be sure it is tuned to 433MHz. I don't know what the range is supposed to be, no mention of that int he 3 pages of datasheet, though the schematic does show a variable cap for tuning the transmitter.
Since it works at very short range, I suspect either a timing or tuning adjustment is needed.
I do not have those devices here, so I can't compile your code or test.

Jay
AnthonyRFC



Joined: 21 Jun 2015
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Fri Aug 31, 2018 5:38 pm     Reply with quote

temtronic wrote:
I was curious, so I downloaded the datasheet for the HS1527. One big issue is that the actual dutycycle spec for the device varies widely depending on the VCC it's running at. With an Rosc of 300K, DC can be 1.32 to 1.99ms !
It could be that your code is designed to run fine at 1.32ms BUT when the voltage drops, the transmitter is now 'out of spec', running at 1.99 ms.
I'd use an oscilloscope to actually see the transmitter data and confirm the duty cycle THEN adjust your program to 'sync' to that speed.


I used the Pickit's logic analyzer and the timing remain equals.

I think that I might having problem with noise treament, what do you think? I have never work with RF data decoding.

Anthony
_________________
From Cumaná, Venezuela.
Ttelmah



Joined: 11 Mar 2010
Posts: 17595

View user's profile Send private message

PostPosted: Sat Sep 01, 2018 12:58 am     Reply with quote

I'd be saying interference.....

I think you are thinking the same 'noise treatment'?.

Big questions are antenna design for the receiver?. How the tracking here is laid out?. Power. How is this smoothed, and filtered from the processor supply?.
Seriously, poor antenna design will kill receiver sensitivity.
If the Micro-controller is itself radiating RF at a different frequency that is still inside the band accepted by the aerial, this can cause the AGC in the receiver to turn right down. Again killing sensitivity.
If there is some RF on the power rail to the receiver, this can have a similar effect.
AnthonyRFC



Joined: 21 Jun 2015
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Sat Sep 01, 2018 9:38 am     Reply with quote

Antenna: 17cm long wire

Power: I'm using a simple decoupling (10uF+100nF) but I can try using a more elaborate decoupling method like a pi filter.

PCB: The board only contains the ask receiver, the pic and leds, no power control lines or noisy part close to the receiver.

PD: using the char array is a good method to catch the individual bits? Because the dirty job is done inside the interrupt.

Thanks a lot!
_________________
From Cumaná, Venezuela.
Ttelmah



Joined: 11 Mar 2010
Posts: 17595

View user's profile Send private message

PostPosted: Sun Sep 02, 2018 12:20 am     Reply with quote

Ideally your antenna wants to be straight. Is it?. Should be 17.31cm long. Is it?.
Check the receiver board. Does it have a coil by the antenna connection pin?. If so the antenna may need to be shorter. Work out the length of the coil, and subtract this from the 17.31 length.
What is your ground?. The 1/4 wave antenna, is dependant on it's ground. It needs a 1/4 wave or larger area of ground at the receiver. If you don't have this, you may get better results switching to a 1/2 wave antenna.

That your code works at short range, suggests it is OK. However it looks as if it'd actually be easier to use INT_RB and just check which way the signal has gone in the interrupt.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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