/* DriverLib Includes */ #include /* Standard Includes */ #include #include #include // Sampling frequency const int fs = 48000; // Timer for calculate sine wave static double Timer = 0; // Coefficients for bandstop filter const double B1[] = {0.7755, -2.5985, 6.3671, -9.6188, 11.5650, -9.6188, 6.3671, -2.5985, 0.7755}; const double A1[] = {1.0000, -3.1835, 7.4065, -10.6464, 12.1861, -9.6677, 6.1083, -2.3849, 0.6809}; // Coefficients for lowpass filter const double B2[] = {0.0000, 0.0001, 0.0005, 0.0025, 0.0093, 0.0260, 0.0564, 0.0967, 0.1330, 0.1477, 0.1330, 0.0967, 0.0564, 0.0260, 0.0093, 0.0025, 0.0005, 0.0001, 0.0000}; const double A2[] = {0.0001, -0.0014, 0.0096, -0.0423, 0.1340, -0.3250, 0.6243, -0.9708, 1.2386, -1.3057, 1.1399, -0.8221, 0.4862, -0.2326, 0.0881, -0.0255, 0.0053, -0.0007, 0.0000}; // Time delays for both filters static double Z1[8]; static double Z2[18]; int main(void){ /* Halting the Watchdog */ MAP_WDT_A_holdTimer(); //![Simple CS Config] /* Configuring pins for peripheral/crystal usage */ MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ, GPIO_PIN3 | GPIO_PIN2, GPIO_PRIMARY_MODULE_FUNCTION); /* Configure P5.6 and P5.7 to their analog functions to output VREF */ P5SEL0 |= BIT6 | BIT7; P5SEL1 |= BIT6 | BIT7; REFCTL0 |= REFON; // Turn on reference module REFCTL0 |= REFOUT; // Output reference voltage to a pin /* Output VREF = 1.2V */ REFCTL0 &= ~(REFVSEL_3); // Clear existing VREF voltage level setting REFCTL0 |= REFVSEL_0; // Set VREF = 1.2V while (REFCTL0 & REFGENBUSY); // Wait until the reference generation is settled /* Configuring pins for HFXT crystal */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_PJ, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /* Set P6.0 as output */ MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); /* Set all 8 pins of P2 as output */ MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7); /* Configuring GPIOs (4.3 MCLK) */ MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P4, GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /* Setting the external clock frequency. This API is optional, but will * come in handy if the user ever wants to use the getMCLK/getACLK/etc * functions */ CS_setExternalClockSourceFrequency(32000,48000000); /* Starting HFXT in non-bypass mode without a timeout. Before we start * we have to change VCORE to 1 to support the 48MHz frequency */ MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); MAP_FlashCtl_setWaitState(FLASH_BANK0, 2); MAP_FlashCtl_setWaitState(FLASH_BANK1, 2); CS_startHFXT(false); /* Initialising MCLK to HFXT (effectively 48MHz) */ MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); /* Set SysTick to 48MHz/1000=48kHz*/ MAP_SysTick_enableModule(); MAP_SysTick_setPeriod(1000); MAP_Interrupt_enableSleepOnIsrExit(); MAP_SysTick_enableInterrupt(); /* Initialising ADC (MCLK/1//1) */ MAP_ADC14_enableModule(); MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1, 0); /* Configuring GPIOs (P5.0 (A5) as the ADC input pin) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN0, GPIO_TERTIARY_MODULE_FUNCTION); /* Configure ADC Resolution */ ADC14_setResolution(ADC_10BIT); /* Configuring ADC Memory */ MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A5, false); /* Configuring Sample Timer */ MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION); /* Enabling MASTER interrupts */ MAP_Interrupt_enableMaster(); while (1){ //MAP_PCM_gotoLPM0(); } } void SysTick_Handler(void) { double buffer = ADC14_getResult(ADC_MEM0); //Get the conversion result. descramble(&buffer, Timer, B1, A1, B2, A2, Z1, Z2); Timer += 1/fs; P2OUT = buffer / 4; //We do this because the ADC is set to use 10 bits but P2OUT is only 8 bits. /* Enabling/Toggling Conversion */ MAP_ADC14_enableConversion(); MAP_ADC14_toggleConversionTrigger(); MAP_ADC14_toggleConversionTrigger(); } void ADC14_IRQHandler(void) { uint64_t status = MAP_ADC14_getEnabledInterruptStatus(); MAP_ADC14_clearInterruptFlag(status); }