Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

CC2531: Setting up timer 1

$
0
0

Part Number:CC2531

Hello,

I am very new to the cc2531 and I was looking for some help setting up the timer. I am setting it up in IAR using the CC Debugger. Below is the code that I am using to set the timer up in free-running mode.

// input frequency is per default internal 32 MHz XOSC
#define INPUT_CLK_FREQ (32000000UL/32UL)
#define TIMER_TICK_FREQ_MS (1)
#define TIMER_16BIT_VAL ((INPUT_CLK_FREQ/1000)/TIMER_TICK_FREQ_MS)

// sanity check
#if (TIMER_16BIT_VAL > 65535)
#error Timer value can't fit to 16 bit timer
#endif

void setup(){//set registers, does not effect timer
}

void time_setup(){
// setup Timer_1
// the following two commands set the upper and lower limits of the timer
T1CC0L = (unsigned char) (TIMER_16BIT_VAL & 0xFF);
T1CC0H = (unsigned char) ((TIMER_16BIT_VAL >> 8) & 0xFF);
T1CCTL0 = 0x44; // interrupt enabled, compared mode
T1CTL = 0x01; // tick frequency/32, free-running mode
}
void main(void){

setup();
time_setup();
// Set P1.0 of CC2531 as output
P0DIR = 0x01;
P1DIR = 0x01;

while(1){
if(//condition){

//do this

}
else{
//reset

};
};
T1IE = 1;
//printf( "Hello World!\n");
FREQCTRL += 5;

}
#pragma vector=T1_VECTOR
__interrupt static void T1_Isr(void)
{
// clear interrupt flag
T1STAT &= ~ 0x01;

// toggle pin
P0 ^= 0x01; // should see 500 Hz at P1.0
}

From the documentation, I feel like this is right but when I start my program, the register values do not change in the 'Watch' window. Once again, I am very new to this and any help, tips, and tricks would be greatly appreciated. Thanks for your help!

Brandon


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>