Exemple #1
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  bool vboost = false;

  /* Chip revision alignment and errata fixes */
  CHIP_Init();

  /* Initialize DVK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize board specific registers */
  VDDCHECK_Init();

  /* Check if voltage is below 3V, if so use voltage boost */
  if (VDDCHECK_LowVoltage(2.9))
    vboost = true;

  /* Disable Voltage Comparator */
  VDDCHECK_Disable();

  /* Run Energy Mode with LCD demo, see lcdtest.c */
  SegmentLCD_Init(vboost);
  /* Display a message if vboost is enabled */
  if ( vboost )
  {
    SegmentLCD_Write("vboost");
    RTCDRV_Delay(5000, false);
  }
  Test();

  return 0;
}
void checkVoltage(void)
{
  bool vboost;

  /* Initialize voltage comparator, to check supply voltage */
  VDDCHECK_Init();

  /* Check if voltage is below 3V, if so use voltage boost */
  if (VDDCHECK_LowVoltage(2.9))
  {
    vboost = true;
  }
  else
  {
    vboost = false;
  }

  /* Disable Voltage Comparator */
  VDDCHECK_Disable();

  if (vboost != oldBoost)
  {
    SegmentLCD_Init(vboost);

    /* Use Antenna symbol to signify enabling of vboost */
    SegmentLCD_Symbol(LCD_SYMBOL_ANT, vboost);
    oldBoost = vboost;
  }
}
Exemple #3
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  int   value, delayCount = 0, hfrcoband = 0;
  float current, voltage;
  bool  vboost;
  char  buffer[8];

  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize board support package */
  BSP_Init(BSP_INIT_BCC);

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(SystemCoreClockGet() / 1000)) while (1) ;

  /* Initialize voltage comparator, to check supply voltage */
  VDDCHECK_Init();

  /* Check if voltage is below 3V, if so use voltage boost */
  if (VDDCHECK_LowVoltage(2.9))
  {
    vboost = true;
  }
  else
  {
    vboost = false;
  }

  /* Disable Voltage Comparator */
  VDDCHECK_Disable();

  /* Initialize segment LCD */
  SegmentLCD_Init(vboost);

  /* Infinite loop */
  while (1)
  {
    /* Read and display current */
    current = BSP_CurrentGet();
    value   = (int)(1000 * current);

    /* Check that we fall within displayable value */
    if ((value > 0) && (value < 10000))
    {
      SegmentLCD_Number(value);
    }
    else
    {
      SegmentLCD_Number(-1);
    }

    /* Alternate between voltage and clock frequency */
    if (((delayCount / 10) & 1) == 0)
    {
      voltage = BSP_VoltageGet();
      value   = (int)(voltage * 100);
      SegmentLCD_Symbol(LCD_SYMBOL_DP6, 1);
      sprintf(buffer, "Volt%3d", value);
      SegmentLCD_Write(buffer);
    }
    else
    {
      SegmentLCD_Symbol(LCD_SYMBOL_DP6, 0);
      sprintf(buffer, "%3u MHz", (int)(SystemCoreClockGet() / 1000000));
      SegmentLCD_Write(buffer);
    }
    /* After 5 seconds, use another HFRCO band */
    if (delayCount % 50 == 0)
    {
      switch (hfrcoband)
      {
      case 0:
        CMU_HFRCOBandSet(cmuHFRCOBand_11MHz);
        break;
      case 1:
        CMU_HFRCOBandSet(cmuHFRCOBand_14MHz);
        break;
      case 2:
        CMU_HFRCOBandSet(cmuHFRCOBand_21MHz);
        break;
      default:
        CMU_HFRCOBandSet(cmuHFRCOBand_28MHz);
        /* Restart iteartion */
        hfrcoband = -1;
        break;
      }
      hfrcoband++;
      /* Recalculate delay tick count and baudrate generation */
      if (SysTick_Config(SystemCoreClockGet() / 1000)) while (1) ;
      BSP_Init(BSP_INIT_BCC);
    }

    Delay(100);
    delayCount++;
  }
}
/**************************************************************************//**
 * @brief  Capsense demo loop
 *****************************************************************************/
void capSenseDemo(void)
{
  int32_t slider;
  bool oldBoost = vboost;

  /* Setup RTC. */
  RTCDRV_Setup(cmuSelect_LFRCO, cmuClkDiv_32);

  /* Setup capSense callbacks. */
  CAPLESENSE_setupCallbacks(&capSenseScanComplete, &capSenseChTrigger);

  /* Main loop */
  while (1)
  {
    switch(demoState)
    {
      case DEMO_SLEEP_PREPARE:
      {
        /* Setup LESENSE in sleep mode. */
        CAPLESENSE_setupLESENSE(true);
        /* Disable LCD to avoid excessive current consumption */
        SegmentLCD_Disable();
        /* Disable Vdd check. */
        VDDCHECK_Disable();
        /* Go to sleep state. */
        demoState = DEMO_SLEEP;
      }
      break;

      case DEMO_SLEEP:
      {
        /* Go to sleep and wait until the measurement completes. */
        CAPLESENSE_Sleep();
      }
      break;

      case DEMO_SENSE_PREPARE:
      {
        /* Setup LESENSE in high-accuracy sense mode. */
        CAPLESENSE_setupLESENSE(false);
        /* Start timeout counter. */
        RTCDRV_Trigger(1000U, &capSenseTimerFired);
        /* Enable vboost */
        SegmentLCD_Init(vboost);
        /* Go to sense state. */
        demoState = DEMO_SENSE;
      }
      break;

      case DEMO_SENSE:
      {
        /* Go to sleep and wait until the measurement completes. */
        CAPLESENSE_Sleep();

        /* Get slider position. */
        slider = CAPLESENSE_getSliderPosition();
        if (-1 != slider)
        {
          /* Reset RTC */
          RTC_Enable(false);
          RTC_Enable(true);
        }
        capSenseAringUpdate(slider);

        /* Check for change in input voltage. Enable vboost if necessary */
        /* Initialize voltage comparator */
        VDDCHECK_Init();

        /* Check if voltage is below 3V, if so use voltage boost */
        if (VDDCHECK_LowVoltage(2.9))
        {
          vboost = true;
          if (oldBoost != vboost)
          {
            /* Enable vboost */
            SegmentLCD_Init(vboost);
            /* Use antenna symbol to signify enabling of vboost */
            SegmentLCD_Symbol(LCD_SYMBOL_ANT, vboost);
          }
          oldBoost = vboost;
        }
        else
        {
          vboost = false;
        }

        switch (demoMode)
        {
        case (DEMOMODE_SCROLLTEXT):
          capSenseScrollText();
          break;
        case (DEMOMODE_BARS):
          capSenseBars();
          break;
        case (DEMOMODE_VALUES):
          capSenseValues();
          break;
        default:
          break;
        }
      }
      break;

      default:
      {
        ;
      }
      break;
    }
  }
}