AnsweredAssumed Answered

BF538F EZ KIT Timers

Question asked by theaman24 on Aug 3, 2011
Latest reply on Aug 4, 2011 by theaman24

Hi,

 

I'm using the BF538F EZKIT and am trying to sample from an external device every 960Hz.  I'm trying to set up the core timer to toggle an LED on the EZKIT board to see if it's working.  Using the core timer registers in the HRM:

 

TCNTL = 0x0007; // enables the timer and sets it to auto reload

TCOUNT = 5000;

TPERIOD = 5000;

TSCALE = 100;

 

If my CCLK is running at 400MHz, the LED should toggle at 800 Hz with these settings.

 

When i run the code below no LEDs turn on (i know the LED code works from toggling a different LED inside the while loop earlier).  Do i have to enable interrupts somehow, or am i missing some time initialization?

 

Also is using the core timer a good/simple way to get me the continual 960Hz I need (i only need about +/- 3 Hz accuracy)?  But regardless I'd like to figure out what I'm doing wrong here. 

 

Thanks!

 

Code:

 

#include <stdlib.h>
#include <math.h>
#include <services/services.h>
#include <cdefBF538.h>
#include <ccblkfn.h>
#include <sys\exception.h>
#include <stdio.h>
int main()
{
*pPLL_CTL = 0x0001; // set VCO = 32x CLKIN = 800MHz (CLKIN = 25MHz from EZKIT)
*pPLL_DIV = 0x0014;     // set SCLK = VCO/4 = 200MHz, CCLK = VCO/2 = 400MHz
*pPORTCIO_FER = 0x03F3; // PORTC GPIO inits
*pPORTCIO_DIR = 0x03E1;
*pPORTCIO_INEN = 0x0012;
*pTSCALE = 100;
*pTPERIOD = 5000;
*pTCOUNT = 5000;
*pTCNTL = 0x0007;
   while(1)
   {
      if( (*pTCNTL & 0x0008) == 1) // if TINT bit in TCNTL register is set (ie the timer has generated an interrupt)
      {
         *pTCNTL = *pTCNTL & 0xFFF7; // reset TINT (interrupt bit)
         *pPORTCIO_TOGGLE = 0x0020; // used to blink LED
         *pPORTCIO_SET = 0x0200;     // used to see TINT is triggered only once, not continuously (if this LED is on and the other is not toggling)
      }
   }
}

Outcomes