/******************************************************************************
 * @brief  Main function
 * The main file starts a timer and uses PRS to trigger an ADC conversion.
 * It waits in EM1 until the ADC conversion is complete, then prints the
 * result on the lcd.
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();
  
  SegmentLCD_Init(false);

  /* Enable clocks required */
  CMU_ClockEnable(cmuClock_ADC0, true);
  CMU_ClockEnable(cmuClock_PRS, true);
  CMU_ClockEnable(cmuClock_TIMER0, true);

  /* Select TIMER0 as source and TIMER0OF (Timer0 overflow) as signal (rising edge) */
  PRS_SourceSignalSet(0, PRS_CH_CTRL_SOURCESEL_TIMER0, PRS_CH_CTRL_SIGSEL_TIMER0OF, prsEdgePos);

  ADCConfig();
  TimerConfig();

  /* Stay in this loop forever */
  while (1)
  {
    /* Enter EM1 and wait for timer triggered adc conversion */
    EMU_EnterEM1();

    /* Write result to LCD */
    SegmentLCD_Number(adcResult);

    /* Do other stuff */
    int i;
    for (i = 0; i < 10000; i++) ;
  }
}
示例#2
0
/*
*********************************************************************************************************
* Input PWM
*********************************************************************************************************
*
*********************************************************************************************************
*/
void InputTask(void *p_arg)
{
  CPU_TS ts;
  OS_ERR  err;
  TimerConfig();
  SetUpTimer1();
  SetUpTimer3();
  
  
  while (1)
  {
    OSTimeDly(15,OS_OPT_TIME_DLY,&err);         //Read every 150ms
    
    if(TIM3->SR & (1 << 1))               //if status register is true go fetch the Period
    {
      Period = TIM3->CCR1;
    }
    if(TIM3->SR & (1 << 2))              //if status register is true go fetch the Duty Cycle
    {
      DutyCycle = TIM3->CCR2;
    }
    
    //Save la valeur de Commande dans la variable golbale
    OSMutexPend(&mutTMR3,0,OS_OPT_PEND_BLOCKING,&ts,&err);
    Command = DutyCycle;
    OSMutexPost(&mutTMR3,OS_OPT_POST_NONE,&err);
  }
  
}