This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: MSP432P401R
Hi,
I'm working with a Timer32 to create a simple delay API to use for my future projects.
It seems to work with 1s duration (I don't have an oscilloscope at hand to check for smaller values..).
I would like some advices about the code (Is it enough to work with any ms/µs duration values?), and if a better & easier way to do a delay exists (Maybe with the Timer32 interrupt, or even without a Timer32?).
Remark: the minimum delay duration needed for my future projects is 10µs.
#include "driverlib.h" void delay_init(void) { Timer32_initModule(TIMER32_0_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE); Timer32_disableInterrupt(TIMER32_0_BASE); } void delay(uint32_t duration_us) { Timer32_haltTimer (TIMER32_0_BASE); Timer32_setCount (TIMER32_0_BASE, 24 * duration_us); Timer32_startTimer(TIMER32_0_BASE, true); while (Timer32_getValue(TIMER32_0_BASE) > 0); } int main(void) { WDT_A_holdTimer(); CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_24); // 24000000 Hz CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // 24000000 Hz GPIO_setAsOutputPin (GPIO_PORT_P2, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0); delay_init(); while(1) { delay(1 * 1000 * 1000); // 1s GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN0); } }
Thanks,
Michaël
Hi Jeff,
Thank you for your answer.
I thought '__delay_cycles()' wasn't present for the MSP432, but I was wrong.
It's easy to use, however there're some issues/constraints:
* An IT executed during the delay increases its duration
* The duration must be a compile-time constant
I think I will keep using a Timer32 for the delay() function, the Timer_A are quite enough for my projects.
-------------------------------------------
About the code above, maybe using the LowPowerMode + Timer32 with IT could be the best solution, instead of using a polling on the Timer32 value.
Michaël
**Attention** This is a public forum