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.

cc2530 vdd check

Other Parts Discussed in Thread: CC2530

Hello everybody,

I am using the GenericApp with the chip cc2530 and the smartrf board. My goal is to write on the lcd something to highlight that the battery voltage is insufficient. In this current implementation theere is the method zmain_vdd_check() in the Zmain.c file:

/*********************************************************************
 * @fn      zmain_vdd_check
 * @brief   Check if the Vdd is OK to run the processor.
 * @return  Return if Vdd is ok; otherwise, flash LED, then reset
 *********************************************************************/
static void zmain_vdd_check( void )
{
  uint8 cnt = 16;
  
  do {
    while (!HalAdcCheckVdd(VDD_MIN_RUN));
       
  } while (--cnt);
  
}

This method calls the method  HalAdcCheckVdd() in the h_adc.c file:

/*********************************************************************
 * @fn      HalAdcCheckVdd
 *
 * @brief   Check for minimum Vdd specified.
 *
 * @param   vdd - The board-specific Vdd reading to check for.
 *
 * @return  TRUE if the Vdd measured is greater than the 'vdd' minimum parameter;
 *          FALSE if not.
 *
 *********************************************************************/
bool HalAdcCheckVdd(uint8 vdd)
{
  ADCCON3 = 0x0F;
  while (!(ADCCON1 & 0x80));
  return (ADCH > vdd);
}

Basically, if the voltage is lower than a threshold, then 3 leds start flashing. This is the point that I do not understand:  what is the part of the code these leds start flashing? Even though debugging I cannot get it. I think it is important in order to achieve my goal and change this kind of alert (write "VDD insufficient" on the LCD).

Maybe it is a trivial question, but I am a beginner.

Thank you. 

  • You can create a periodical event and use HalAdcCheckVdd to check VDD. If the voltage is less than threshold, you display it on LCD.

  • A periodical event is a good idea and I will surely do that, but the point is that I want to do it at the startup too and I want to stop the program if the voltage is non suffiecient. So, I tried this:

    /*********************************************************************
     * @fn      zmain_vdd_check
     * @brief   Check if the Vdd is OK to run the processor.
     * @return  Return if Vdd is ok; otherwise, flash LED, then reset
     *********************************************************************/
    static void zmain_vdd_check( void )
    {
    //  uint8 cnt = 16;
    //  
    //  do {
    //    while (!HalAdcCheckVdd(VDD_MIN_RUN));
    //       
    //  } while (--cnt);
      
      if(!HalAdcCheckVdd(174)){
         HalLcdWriteString( "VDD not sufficient ", HAL_LCD_LINE_1 );
      }
      
      
    }

    and I put value 174  in order to force the alarm status. What I expect from this code is that the LCD displays the string and that the code will go ahead. What I obtained, instead, is that the three led keeps flashing (as in the previous case), and the program stops. I do not understand why.

    Thank you.

  • I don't think you can call HalLcdWriteString in zmain_vdd_check because zmain_lcd_init is called after zmain_vdd_check.