Author Topic: MSP430 Crystal Timer Problems  (Read 2572 times)

0 Members and 1 Guest are viewing this topic.

Offline Jon86Topic starter

  • Frequent Contributor
  • **
  • Posts: 526
  • Country: gb
MSP430 Crystal Timer Problems
« on: June 21, 2014, 02:17:22 pm »
I'm trying to use an MSP430 timer with a 32.768Khz crystal to generate an interrupt every second increments the number on a 7-segment display.
And I'm using the following code to set up the clocks etc.

Code: [Select]
WDTCTL = WDTPW | WDTHOLD;
    BCSCTL1 = CALBC1_1MHZ ;
    DCOCTL = CALDCO_1MHZ;

P1DIR = 0xFF;
P2DIR = 0xFF;
P1OUT = 0x00;

CCTL0 = CCIE;
CCR0 = 32768;
TACTL = TASSEL_1 + MC_2;
__bis_SR_register(GIE);

When the interrupt is run, I execute

Code: [Select]
CCR0 += 32768;
But instead of a 1s interval, I'm getting somewhere around 5-6s. I'm pretty sure it's running from the crystal as when I remove it the timer stops counting.
Does anyone know what might be wrong? And also could someone explain to me the process of setting up and resetting the timer? I'm not sure I understand the code properly.
Death, taxes and diode losses.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: MSP430 Crystal Timer Problems
« Reply #1 on: June 21, 2014, 03:54:24 pm »
My suspicion would be this line here:

Code: [Select]
BCSCTL1 = CALBC1_1MHZ ;
I'm guessing that the value of CALBC1_1MHZ has been lost and now holds a value of 0xff.  This will cause the auxiliary clock (the 32.768kHz xtal) to be divided by 8--which would account for what you're seeing.

See this Stack Overflow post.
 

Offline Jon86Topic starter

  • Frequent Contributor
  • **
  • Posts: 526
  • Country: gb
Re: MSP430 Crystal Timer Problems
« Reply #2 on: June 21, 2014, 03:59:50 pm »
Looking at the BCSCTL1 Register, the value at runtime is 0x86 so apparently it's not being divided.
Death, taxes and diode losses.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: MSP430 Crystal Timer Problems
« Reply #3 on: June 21, 2014, 04:18:07 pm »
That was my best guess.  From what I can tell it should work as you are expecting it to based on the code that you show.
 

Offline Jon86Topic starter

  • Frequent Contributor
  • **
  • Posts: 526
  • Country: gb
Re: MSP430 Crystal Timer Problems
« Reply #4 on: June 21, 2014, 04:20:55 pm »
Damn, It's going to be a real pain in the ass to put an RTC in, ah well thanks anyway.
Death, taxes and diode losses.
 

Offline Jon86Topic starter

  • Frequent Contributor
  • **
  • Posts: 526
  • Country: gb
Re: MSP430 Crystal Timer Problems
« Reply #5 on: June 22, 2014, 04:01:05 pm »
I think it's a hardware problem, if I unplug the board and plug it back in again after I've reprogrammed it, then it works fine.
Also if I touch a scope probe on XOut then it works fine too, I'm guessing it's a capacitance problem, but I can't work out why it starts working if I plug it in again?
Death, taxes and diode losses.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf