I'm determined not to use the provided stellarisware functions, and am trying to figure out how to get my Timer to work. At this moment, all I'm attempting to do is have Timer0 A count to a specified value (That stored in TIMER0_TAILR_R) and blink the on board LED.
The program as it is now will count down from the specified value (by having TIMER0_TAMR_R |= 0x1), yet when in count up mode, the LED specified blinks at a constant rate (slowly) regardless of the value stored in TIMER0_TAILR_R.
#include "lm4f120h5qr.h"
int main(void){
SYSCTL_RCGCGPIO_R |= 0x20; // clock gate to port F
GPIO_PORTF_DIR_R |= 0x7 << 1; // Set Led's as outputs
GPIO_PORTF_DEN_R |= 0x7 << 1;// for LED's
GPIO_PORTF_DEN_R |= 0x1; // For timer
GPIO_PORTF_PCTL_R |= 0x7; //select T0CCP0
SYSCTL_RCGC1_R |= 0x1 << 16;
SYSCTL_RCGCTIMER_R |= 0x1;
TIMER0_CTL_R = 0;
TIMER0_CFG_R = 0;
TIMER0_CFG_R |= 0x4;
TIMER0_TAMR_R |= 0x11; // set mode
TIMER0_TAPR_R |= 0xF; // prescale
TIMER0_TAILR_R = 0x1F1; // load value
while(1){
GPIO_PORTF_DATA_R |= 0x1 << 2;
TIMER0_CTL_R |= 0x1;
while(TIMER0_CTL_R & 0x1);
GPIO_PORTF_DATA_R &= ~(0x1 << 2);
TIMER0_CTL_R |= 0x1;
while(TIMER0_CTL_R & 0x1);
}
}
As far as I know I've initialised the Timer correctly and am doing everything correctly (obviously this is incorrect). Any help as to where I'm going wrong is greatly appreciated as I've been racking my brains over this for quite some time and cannot find a solution.
cheers,
Luke.