SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
#65901
Hello my name is Jose Miguel, I write from spain and I'm having some problems to set the frequency of my msp430. (f2013, the one with de detachable board). I want the signal to change every 10ms and this is what I think:
timer interrupts: Ti = CCR0 / f
The thing is that actually period is: (T) 7 interrupciones del timer,
And: T = Ti * 7; luego, I know T=10 ms and I think f=16MHz (?) so CCR0 = 22857

Well, it seems that CCR0 doesn't work, because it doesn't matter the value it's ascribed and it's in the for loop when I have to ascribe one or another value to i, but I don't know exactly how long does it take for the loop to increase the i.

This is the code and I hope someone help me.

Thanks all.




#include <msp430x20x3.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= 0xFF;
CCTL0 = CCIE;
CCR0 = 22857;
TACTL = TASSEL_2 + MC_1;
BCSCTL2 |= SELM_3 + DIVM_3;
_BIS_SR(LPM0_bits + GIE);
}
unsigned int n=7;
char s[ ] = {0x01, 0x42, 0x81, 0x48, 0x81, 0x42, 0x01};

#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A (void)
{

volatile unsigned int i;
volatile unsigned int j;
volatile unsigned int k;


for (i=0; i<n; i++)
{
P1OUT = s;
for (k=0; j<100; j++) //100 times 10ms (should be 1s)
{
for (j=0; j<22857; j++); //software delay (should be 10ms)
}
}
By gm
#65924
Jose,

There are numerous problems with your code. Here is what I think you wanted to achieve. Take it, study it and modify it until you understand it. The MSP430's are quite versatile, especially the timers so it pays to study the User Guides.
Code: Select all
#include <msp430x20x3.h>

char s[] = {0x01, 0x42, 0x81, 0x48, 0x81, 0x42, 0x01};

void main(void)
{
	unsigned int i;
	
	WDTCTL = WDTPW + WDTHOLD;
	
	// Configure DCO for 1 MHz
	BCSCTL1 = CALBC1_1MHZ;
	DCOCTL  = CALDCO_1MHZ;
	
	// Source MCLK and SMCLK from DCO, dividers set to 1
	BCSCTL2 = 0;

	// Configure P1 as outputs, initially low
	P1OUT = 0x00;
	P1DIR |= 0xFF;
	
	// Configure TimerA0 to be sourced by SMCLK, divided by 2
	// interrupt every 70 ms
	TACTL		= TASSEL_2 | ID_1 | MC_1;
	TACCR0	= 35000;	// 1 MHz / 2 * .07 seconds
	TACCTL0 = CCIE;
	
	i = 0;
	
	for (;;)
	{
		// Go to sleep until TimerA0 fires
		_BIS_SR(LPM0_bits + GIE);
		
		P1OUT = s[i++];
		
		if ( i >= sizeof(s) )
			i = 0;
	}
}

 #pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
	// Timer fired, wake up processor
	LPM0_EXIT;
}
Good Luck!

gm
By Jose Chico
#65930
Thanks a lot, gm. I'll do so, and by the time it'll work I'll tell you.
Thanks. =)
By gm
#65933
Your welcome! Glad to help and welcome to the club!

gm