I Need the your help, been racking my brains out for a bit, and I need your help.
This is a test program o figure out how to use the timer0 in a one shot mode repeatedly as required. the larger part is I'm using the the Comparator function and interrupt, when the COMP is triggered I need a 200ms-300ms delay to trigger another function.
I just can't get the timer to trigger the interrupt and generate a delay.
Regards
Roman
// ***************************************************************************
// PF1 = RED led
// PF2 = BLUE led
// PF3 = GREEN led
// PF0 = SW2
// PF4 = SW1
// ****************************************************************************
#include <stdint.h>
#include "tm4c123gh6pm.h"
extern void Timer0IntHandler(void);
void delay_sec(uint32_t);
#define SYSDIV 2
#define LSB 0
#define timer_int 0x00080000
#define timer0_cnt_dwn 0x000F000 // TIMER COUNT VALUE <<<<<<<<<<<<<<<<<<<<<<<<<
#define red 0x0002
#define blue 0x0004
#define green 0x0008
#define sw2 0x0001
volatile uint32_t ui32Loop;
volatile uint32_t ui32Loop2;
volatile uint32_t nope;
volatile uint32_t temp = 0;
//*****************************************************************************
//
//*****************************************************************************
int
main(void)
{
SYSCTL_RCC2_R |= SYSCTL_RCC2_USERCC2;
SYSCTL_RCC2_R |= SYSCTL_RCC2_BYPASS2;
SYSCTL_RCC_R &= ~SYSCTL_RCC_XTAL_M; // clear XTAL field
SYSCTL_RCC_R += SYSCTL_RCC_XTAL_16MHZ; // configure for 16 MHz crystal
SYSCTL_RCC2_R &= ~SYSCTL_RCC2_OSCSRC2_M; // clear oscillator source field
SYSCTL_RCC2_R += SYSCTL_RCC2_OSCSRC2_MO; // configure for main oscillator source
SYSCTL_RCC2_R &= ~SYSCTL_RCC2_PWRDN2;
SYSCTL_RCC2_R |= SYSCTL_RCC2_DIV400;
SYSCTL_RCC2_R &= ~SYSCTL_RCC2_SYSDIV2_M; // clear system clock divider field
SYSCTL_RCC2_R &= ~SYSCTL_RCC2_SYSDIV2LSB; // clear bit SYSDIV2LSB
SYSCTL_RCC2_R += (SYSDIV<<23)|(LSB<<22); // divide by (2*SYSDIV+1+LSB)
while((SYSCTL_RIS_R&SYSCTL_RIS_PLLLRIS)==0){};
SYSCTL_RCC2_R &= ~SYSCTL_RCC2_BYPASS2;
SYSCTL_RCGCGPIO_R = SYSCTL_RCGCGPIO_R4 + SYSCTL_RCGCGPIO_R5; // * enable GPIO E & F
SYSCTL_RCGCTIMER_R = SYSCTL_RCGCTIMER_R0 + SYSCTL_RCGCTIMER_R1; //enable clk timer0
// Do a dummy read to insert a few cycles after enabling the peripheral.
ui32Loop = SYSCTL_RCGC2_R;
GPIO_PORTF_LOCK_R = GPIO_LOCK_KEY;
GPIO_PORTF_CR_R = GPIO_LOCK_LOCKED;
GPIO_PORTF_DIR_R = 0x0E;
GPIO_PORTF_DR2R_R &= ~GPIO_0;
GPIO_PORTF_DEN_R = 0x0F;
GPIO_PORTF_PUR_R |= GPIO_0;
GPIO_PORTF_AMSEL_R = 0;
ui32Loop = SYSCTL_RCGC2_R;
GPIO_PORTF_DATA_R &= ~(0x0E);
// *************************************************************************
// timer 698
// *************************************************************************
TIMER0_CTL_R &= ~(TIMER_CTL_TAEN + TIMER_CTL_TBEN); // disable timers
TIMER0_CFG_R = TIMER_CFG_32_BIT_TIMER; // 32-bit timer configuration
TIMER0_TAMR_R |= TIMER_TAMR_TAMR_1_SHOT | TIMER_TAMR_TAMIE + TIMER_TAMR_TAWOT;
TIMER0_TAILR_R = 0xFFFFFFFF; // load timer value 750
TIMER0_IMR_R = 0x1F; //TIMER_IMR_CAMIM; // Capture Mode Match Interrupt Mask
TIMER0_ICR_R = 0x1F; //TIMER_ICR_CAECINT;// clear timer0A capture match flag
// *************************************************************************
// interrupt
// *************************************************************************
NVIC_EN0_R = timer_int;
NVIC_ST_CTRL_R |= NVIC_ST_CTRL_INTEN;
NVIC_UNPEND0_R |= timer_int; // clear interrupt
GPIO_PORTF_DATA_R &= ~(green); // Turn Off LED
while(1) // loop forever
{
if ((GPIO_PORTF_DATA_R & GPIO_0)== 0)
{
TIMER0_CTL_R |= TIMER_CTL_TAEN;
GPIO_PORTF_DATA_R |= green;
}
GPIO_PORTF_DATA_R &= ~(red); // reset off LEDS
GPIO_PORTF_DATA_R &= ~(green);
GPIO_PORTF_DATA_R &= ~(blue);
// delay_sec(1000);
}
}
// *****************************************************************
// end of Main
// *****************************************************************
void delay_sec(uint32_t waste_time) // used to see the LEDs flash for testing
{
for(ui32Loop = 0; ui32Loop < waste_time; ui32Loop++)
{
}
}
void Timer0IntHandler(void)
{
GPIO_PORTF_DATA_R &= ~(green);
// TIMER0_CTL_R &= ~TIMER_CTL_TAEN; // disable timers
TIMER0_ICR_R = 0x1F; //TIMER_ICR_CAMCINT;// GPTM TimerA Capture Mode Match INT Clear
GPIO_PORTF_DATA_R |= red; // never comes on WHY ?????
delay_sec(1000);
}