Hi
I would avoid the GPT for generating periodic interrupts. It is more useful for generating waveforms.
The M5223X has 2 PITs, which are designed for this purpose and are very easy to use. Rich's code shows how much simpler it is.
The M5223X also has 4 DMA timers which are very powerful - they can easily be configured to generate periodic interrupts from us region up to many days with very high resolution.
Here are extracts from the user interface for these timer in the uTasker project, which will also simulate these timers to allow easy testing of code:
Eg of configuring a PIT with a single shot interrupt of 3245us - it calls back the user handler test_timer_int() when it fires. It will power itself up and automatically power itself down when finished with its work.
Code:
static void fnConfigurePIT(void){ PIT_SETUP pit_setup; // interrupt configuration parameters pit_setup.int_type = PIT_INTERRUPT; pit_setup.int_handler = test_timer_int; pit_setup.int_priority = PIT1_INTERRUPT_PRIORITY; pit_setup.count_delay = PIT_US_DELAY(3245); // 3245us delay pit_setup.mode = PIT_SINGLE_SHOT; // one-shot interrupt fnConfigureInterrupt((void *)&pit_setup); // enter interrupt for PIT1 test}Here is an example of using a DMA timer (these are interesting because they can also be used to cause DMA transfers to take place) rather than interrupting..
In this case it also performs a single shot interrupt with 6345us timeout
Code:
static void fnConfigure_DMA_Timer(void){ DMA_TIMER_SETUP dma_timer_setup; // interrupt configuration parameters dma_timer_setup.int_type = DMA_TIMER_INTERRUPT; dma_timer_setup.int_handler = DMA_timer_int; dma_timer_setup.channel = 1; // DMA timer channel 1 dma_timer_setup.int_priority = DMA_TIMER1_INTERRUPT_PRIORITY; // define interrupt priority dma_timer_setup.mode = (DMA_TIMER_INTERNAL_CLOCK | DMA_TIMER_SINGLE_SHOT_INTERRUPT); dma_timer_setup.count_delay = DMA_TIMER_US_DELAY(1,1,6345); // 6345us delay using no dividers fnConfigureInterrupt((void *)&dma_timer_setup); // enter interrupt for DMA timer test} To generate periodic interrupts or control output signals the parameters can be simply modified:
eg. periodic interrupt:
dma_timer_setup.mode = (DMA_TIMER_INTERNAL_CLOCK | DMA_TIMER_PERIODIC_INTERRUPT);
or an output on its TOUT pin:
dma_timer_setup.mode = (DMA_TIMER_RESTART_ON_MATCH | DMA_TIMER_TOGGLE_OUTPUT);
dma_timer_setup.count_delay = DMA_TIMER_US_DELAY(1,1,(1000000/2/1500)); // 1500Hz signal
Regards
Mark
www.uTasker.com