/****************************************************************************** * @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++) ; } }
int main(void) { CHIP_Init(); if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ; BSP_Init(BSP_INIT_DEFAULT); BSP_LedsSet(0); BSP_PeripheralAccess(BSP_AUDIO_IN, true); BSP_PeripheralAccess(BSP_AUDIO_OUT, true); RTCDRV_Trigger(1000, NULL); EMU_EnterEM2(true); initSource(); setupCMU(); setupDMA(); //setupADC(); //setupDAC(); //setupDMAInput(); //setupDMAOutput(); //setupDMASplit(); //setupDMAMerge(); ADCConfig(); DACConfig(); TIMER_Init_TypeDef timerInit = TIMER_INIT_DEFAULT; TIMER_TopSet(TIMER0, CMU_ClockFreqGet(cmuClock_HFPER) / SAMPLE_RATE); TIMER_Init(TIMER0, &timerInit); Delay(100); BSP_LedsSet(3); Delay(500); BSP_LedsSet(0); Delay(100); while(1) { volatile bool result = test(); if (result) { BSP_LedsSet(0x00FF); } else { BSP_LedsSet(0xFF00); } Delay(1000); BSP_LedsSet(0x0); Delay(1000); } }
/**************************************************************************//** * @brief Main function * The DAC produces an output signal which the ADC measures. The measured * result is printed on the LCD screen. * * The code shows two different examples of ADC input: * * One version uses DAC output channel 0 as input. * * The other version uses ADC input channel 3 (PD3 on the STK). This pin must * then be connected with a wire to the DAC output channel 0 (PB11 on the STK). * *****************************************************************************/ int main(void) { /* Variable declarations */ uint32_t DAC_Value; uint32_t sample; double voltage; /* Initialize chip */ CHIP_Init(); /* Initialize LCD */ SegmentLCD_Init(false); /* Enable clocks required */ CMU_ClockEnable(cmuClock_HFPER, true); CMU_ClockEnable(cmuClock_ADC0, true); /* Configure ADC */ ADCConfig(); /* Initialize the DAC */ DAC_setup(); /* Enable DAC channel 0, located on pin PB11 */ DAC_Enable(DAC0, 0, true); /* This code is only necessary when using ADC input channel 3 which * is connected to pin PD3 on the STK. Enable it by uncommenting the * definition of EXTERNAL above */ #ifdef EXTERNAL CMU_ClockEnable(cmuClock_GPIO, true); GPIO_PinModeSet(gpioPortD, 3, gpioModeInputPull, 1); GPIO_PinOutClear(gpioPortD, 3); #endif /* Stay in this loop forever */ while (1) { /* Calculate DAC output to 0.5 V. */ DAC_Value = (uint32_t)((0.5 * 4096) / 1.25); /* Write the new value to DAC register */ DAC_WriteData(DAC0, DAC_Value, 0); /* Start single conversion for ADC */ ADC_Start(ADC0, adcStartSingle); /* Wait while conversion is active */ while (ADC0->STATUS & ADC_STATUS_SINGLEACT) ; /* Get ADC result */ sample = ADC_DataSingleGet(ADC0); /* Calculate output voltage produced by the DAC */ voltage = (sample * 1.25) / 4096; /* Write the result to LCD */ char buffer[10]; snprintf(buffer, 8, "%1.2f", voltage); SegmentLCD_Write(buffer); /* wait 100ms in EM2 before next conversion */ RTCDRV_Trigger(100, NULL); EMU_EnterEM2(true); } }