For test purposes I am using an external 10MHz crystal to generate the High Frequency clock input (HFIN) which is selected as the SMCLK that I am using to increment timerB.
Timer B is setup in the UP mode with a count of 9999 which should drop to zero every millisecond.
This in turn is setup to generate an interrupt that my software is using as it's time base for time keeping purposes.
The interrupt does occur but it is running at half the expected rate. This would be expected if the crystal was a 5MHz instead of 10.
I have checked and the crystal is oscillating at 10MHz. I suspect that the timer is actually using the MODCLK frequency (fail-safe clock).
As I mentioned I am using the TI development board but I have also created a board with essentially the same configuration except that that I am providing the 10KHz clock with an external high stability oscillator.
The oscillator generates a TTL logic level square wave. That board also has the same problem and runs at half speed.
I have been working on this for weeks now and am not able to drive the timer with the external frequency reference.
Please see my initialization code below:
// GPIO setup of the HFIN crystal pins
PJSEL0 |= BIT6; // P.6 = (01) Set PJ.6 in the High Freq Crystal mode
PJSEL1 &= ~BIT6;
PJSEL0 |= BIT7; // P.7 = (01) Crystal mode
PJSEL1 &= ~BIT7;
// Here is the CS init code....
void init_System_Clock(void)
{
// Before the clock system is set to run the microcontroller at 10 MHz, the
// clock source for the FRAM memory needs to be prescaled using a wait state
// for its operation with MCLK beyond 8 MHz.
FRCTL0 = FRCTLPW | NWAITS_1; // Unlock FRAM and Increase FRAM Wait state number
//SET CLOCK SoURCE
CSCTL0 = 0xA500;
CSCTL1 = 00000000; //DCO 1Mhz (not used)
CSCTL2 = SELS__HFXTCLK + SELM__HFXTCLK; //SMCLK and MCLK source = HFXT
CSCTL3 = DIVS__1 + DIVM__1; //SMCLK/1 and MCLK/1
CSCTL4 = HFXTDRIVE0 + HFFREQ_2; //SeT frequence = 10Mhz
CSCTL6 = SMCLKREQEN + MCLKREQEN;
// Check for fault flags
do
{
CSCTL5 &= ~(HFXTOFFG + LFXTOFFG);
} while (CSCTL5 & HFXTOFFG);
}
// Here is the timer init code....
void init_Timer_Capture(void)
{
// Setup TimerB0 (1K Period)
TB0CCTL0 = CCIE; // TBCCR0 reset/set
TB0CCR0 = 9999; // Clock period of TBCCR0
// Start Timer B
TB0CTL = TBSSEL__SMCLK | MC__UP; // SMCLK Up to CCR0
// TB0CTL |= TBIE; // ENABLE INTERRUPT
TB0CTL &= ~TBIFG; // Clear the interrupt flag
__enable_interrupt(); // enable global
}
Pete England