This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Zero Cross detection on CC2530

Other Parts Discussed in Thread: CC2530, CC2543

Hi,

I am trying to develop something which needs zero cross detection - I have a H11AA1 producing a pulse which is connected to P1_2 of the CC2530.  When running the following code, I am getting inaccurate frequency reporting - it seems to only be picking up approx ~75 pulses / second (and this can fluctuate significantly), whereas it should be exactly 100 (50Hz).

Any suggestions would be very welcome.

Regards,

Ryan

 

 P1DIR &= ~0x04;

 P1SEL &= ~0x04;

 PICTL &= ~0x02;



 P1IFG &= ~0x04;

 P1IF = 0;

 P1IEN |= 0x04;

 IEN2 |= 0x10; // P1IE = 1

 EA = 1;





HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR ) {

unsigned char p1ifg;

 p1ifg = P1IFG;

 P1IFG = ~p1ifg;

     if (p1ifg & 0x04) {

         freq_count = freq_count + 1;

         PICTL &= ~0x02;

         P1IFG = ~0x04;

     }

 P1IF = 0;

}

  • Perhaps you can try to test your code on a simple switch connected to the CC2530 first.  That way you can determine exactly where the problem is.  In your code count the number of times the switch is pressed.  Once that is confirmed then test the part of the code that calculates then number of presses in 5 seconds.

    If you have a scope or DMM, you can verify the frequency output of the H11AA1.

  • Hi Greenja,

    Thanks for your fast reply.  I tried measuring the output from the H11AA1 on a DMM and the result was 99.98Hz, and on the oscilloscope, everything looks clean.

    I tried measuring with a switch (wire on ground / 3.3v), set a 3 second timer, and printf'd the result.  I was getting counts in the tens to hundreds (!).  When the pin is pulled high and left there, the count stays at 0.  When the pin is pulled low and left there, the count stays at zero.  Perhaps this is a result of the pin not being in a positive state for a brief moment on time while switching (at this level, digital signals is a bit of an art to me).

  • There should be an example of setting up the I/O in the CC2530 folder for Zigbee.

    If not, download this file which is for the CC2543/4/5.   The chips are very similar to the CC2530.  Inside the file there is the I/O folder that shows how to setup the Pin for an interrupt.  Try and follow their configuration.

    http://www.ti.com/lit/sw/swrc257/swrc257.zip.

    For your code it would appear that you are counting the frequency somewhere else in the main loop to get counts that high.

  • Hi Ryan,

    If using a switch, make sure to have a resistor there as well to avoid resetting the device.

    Are you running the Zigbee stack on the device? If so, interrupts might be disabled during critical sections of the stack.

    It is probably best to use a timer with capture mode to measure the frequency and allow for the ISR to be serviced at a variying point in time.

    Another thing that might help in debugging would be to toggle a pin yourself during the ISR and look at the oscilloscope what frequency is coming back out of the device.

    The internal oscillator, at least when running the stack, will switch forth and back between the crystal oscillator @ 32Mhz and the internal RC oscillator @ ~16MHz (when going to sleep).

    Regards,
    Svend