Hello,
I am using the MSP-EXP432P401R development kit, and have issues trying to set up the Timer32 module.
I would like to have an interrupt generated each 20.8µs (48kHz), so i set up Timer32 in periodic mode with a reload value of 1000.
I am toggling a pin in the interrupt to verify the generated frequency. Surprisingly, my scope shows it as a 2.5kHz square wave whereas it should be a 24kHz square wave !
I also used the CS_getMCLK() function from the DriverLib API, which returns 128kHz in debug mode. I would expect it to return 48MHz ...
Here is my code :
/** SONIC DISASTER ** ** David BLANCHARD ** ** RELEASE NOTES 28/06/2016 : first version **/ /* DriverLib Includes */ #include "driverlib.h" /* Standard Includes */ #include <stdint.h> #include <stdbool.h> /** Interrupt routines declaration **/ void ADC_interrupt(); void TimerA_interrupt(); int main(void) { uint32_t MCLK_freq; /* Stop interrupts for initialisation */ Interrupt_disableMaster(); /* Stop Watchdog */ MAP_WDT_A_holdTimer(); /* Power */ PCM_setPowerState(PCM_AM_LDO_VCORE1); /* Clocking */ //Crystal inputs GPIO_setAsInputPin(GPIO_PORT_PJ, GPIO_PIN2); GPIO_setAsOutputPin(GPIO_PORT_PJ, GPIO_PIN3); CS_setExternalClockSourceFrequency(32000,48000000); CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ); CS_enableClockRequest(CS_ACLK); CS_enableClockRequest(CS_MCLK); CS_enableClockRequest(CS_HSMCLK); CS_enableClockRequest(CS_SMCLK); CS_startHFXT(false); CS_startLFXTWithTimeout(CS_LFXT_DRIVE3, 10); CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_HSMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_BCLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); /* Init Timer 48kHz */ Timer32_initModule(TIMER32_0_BASE, TIMER32_PRESCALER_1, TIMER32_1_MODULE6BIT, TIMER32_PERIODIC_MODE); Timer32_setCount(TIMER32_0_BASE, 1000); Timer32_enableInterrupt(TIMER32_0_BASE); Timer32_registerInterrupt(TIMER32_0_INTERRUPT, ADC_interrupt); Timer32_startTimer(TIMER32_0_BASE, false); /* DEBUG - GPIO setup */ GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN5); GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN6); CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); /* Interrupts activation */ Interrupt_enableMaster(); /* Main program loop */ while(1) { MCLK_freq=CS_getMCLK(); } } /** Interrupt routines */ /* ADC 48kHz interrupt */ void ADC_interrupt() { //DEBUG --> write f/2 square wave to output GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN6); Timer32_clearInterruptFlag(TIMER32_0_BASE); }
I desperately searched for hours, any help would be apreciated !
Thank you in advance,
David