Jump to content
Sign in to follow this  
bluehash

1us tick on the Launchpad using the DCO

Recommended Posts

Quick question for you guys:

I am in need of a 1us tick time for a small application on the Launchpad. The basic examples come with the DCO set at 1Mhz. If I set Timer1A to interrupt every 1us, I get something close to 1us, - around 1.2us off. All I'm doing in the ISR is toggling an LED. I know keeping a 1us interrupt in unreasonable, but I just needed to clarify.

 

I also raised the DCO clock to 20Mhz. The same thing happens. I get 1.3us instead of 1us.

//***************************************************************************************
// MSP430 Timer Blink LED Demo - Timer A Software Toggle P1.0 & P1.6
//
// Description; Toggle P1.0 and P1.6 by xor'ing them inside of a software loop. 
// Since the clock is running at 1Mhz, an overflow counter will count to 8 and then toggle
// the LED. This way the LED toggles every 0.5s. 
// ACLK = n/a, MCLK = SMCLK = default DCO 
//
// MSP430G2xx
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | P1.6|-->LED
// | P1.0|-->LED
//
// Aldo Briano
// Texas Instruments, Inc
// June 2010
// Built with Code Composer Studio v4
//***************************************************************************************
#include 


#define LED_0 BIT0 
#define LED_1 BIT6
#define LED_OUT P1OUT
#define LED_DIR P1DIR



unsigned long timerCount = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;	// Stop watchdog timer

BCSCTL1 |= 0xF;             // 20Mhz 
DCOCTL |= 0x70;             // Range 7
LED_DIR |=  ( LED_0 ); 		// Set P1.0 to output direction
LED_OUT &= ~( LED_0 );		// Set the LEDs off

CCTL0 = CCIE;
TACTL = TASSEL_2 + MC_1;	// Set the timer A to SMCLCK, Up mode
TACCR0 = 20;                // Timer load value for 1us tick. 
                            // 20 counts for 1us.

// Clear the timer and enable timer interrupt
__enable_interrupt();

__bis_SR_register(GIE); // interrupts enabled
} 


// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{

		P1OUT ^= ( LED_0 );
}

 

Am I being unreasonable?

Share this post


Link to post
Share on other sites

The problem with interrupts is that there are additional cycles that are occupied in the interrupt scheme. These additional cycles (which are for the most part, required to use interrupt service routines) will add additional time to your ticks. So, as far as my (extremely limited) knowledge goes, I'm going to say that either 1us ticks are either impossible, or you should try for something around a ~.7-.8us tick with the timerA, if your code allows (I didn't take a look at it, my mind is too fried to look at code at the moment). But yeah, always factor in the additional 6-12 cycles to enter the interrupt and the additional 4-10 cycles on the way out of it.

 

Hope this helps, and feel free to correct me if I'm wrong :P

Share this post


Link to post
Share on other sites

Gatesphere's right. I've been experimenting with software PWM on the Launchpad and am finding that if I set a timer to upcount and trigger at a very short period then the processor never executes any non-interrupt code. I assume this is caused by the same issue.

 

I searched for a value for TACCR0 and found that 80 was the minimum which would work with my interrupt handler. At 1MHz that implies a tick of 12.5uS. Even with the ISR just incrementing a variable and then returning, it wasn't a lot shorter.

 

Code's at http://blog.hodgepig.org/articles/00004 ... index.html

Share this post


Link to post
Share on other sites

gatesphere is right. Things start to break down over 16MHz, there are stability problems over 16MHz. It is theoretically possible to clock the chip faster than the max if the right kind of cooling is used and you are very careful with the power supply. I do not recommend overclocking the MSP430 in any important application, do it at your own risk. It is even possible that you permanently damaged your chip by putting it at 20MHz, but maybe not; I actually do not know how to test this cause it could be only one small part of your chip that doesn't work anymore.

 

One thing to try, is to set the clock to 16MHz, you should be able to get close to the 1us interrupt. A few things to keep in mind, first the MSP430 can only run at higher frequencies when higher voltages are used (ex. you can not run at 16MHz when using a 2.2V power supply), see the data-sheet for more info on the voltage/frequency curve. Second, the DCO is not perfectly accurate, there is a percentage of error in each chip. It could be just that your individual chip is not spot on and thus your interrupt timing is slightly off. Try checking your clock speed on an oscilloscope if you have one.

 

Out of curiosity, what do you need the 1us interrupt for?

 

NJC

_________________________

http://msp430launchpad.com

Share this post


Link to post
Share on other sites

Thanks NJC!

I'll try what you said. The highest the MSP430G2231 DCO can go is 21Mhz, according to it's datasheet. I'll have to check the power supply though.

 

Out of curiosity, what do you need the 1us interrupt for?

I was trying to make an IR encoder to send signals to my camera. I need a minimum of 10us tick for it. I was experimenting at how low I could go.

Share this post


Link to post
Share on other sites

The max the DCO can go is 21 MHz, but that max the chip can handle is 16MHz. I know it says "Recommended Operating Conditions", but it's a bit more of than a simple recommendation, lol, at least according to TI. I do think its a bit odd that they put a DCO that can go faster than the chip it is inside. /shrug

 

Cool project idea. Look into the post on my blog were I used to the SPI data pin as a semi-hardware UART. You can modify that to output all the data you want in basically any format that's less than 16 bits per transmitted value. The bit-time is whatever clock you source the USI with. That is really the only way to get very fast data transmissions using these chips (without external chips). Even if you could get your interrupt to happen at exactly 1us, any processing you would need to do to make a "software IR encoder" would make the chip miss interrupts. It's possible to do this with external logic too, but a bit more difficult. Another option is to use the 55xx devices which are clocked at 25MHz (I think it can even go higher).

 

http://www.msp430launchpad.com/2010/08/using-usi-as-uart.html

 

If you have any questions about how to modify the code, ask away.

 

NJC

_________________________

http://msp430launchpad.com

Share this post


Link to post
Share on other sites

Modulation does get messy. I've only played with analog modulation so sorry I can't be of help. Hope you can get everything working though. :-)

 

I actually don't own a scope. I either use the scope I have at my work desk if I am co-op'ing (which I am now), or the scope in the labs when I am in classes. If I need something at home and do not feel like going anywhere I have a basic scope I made with the F5528 a few weeks ago when I got my F5528 board from TI. I only have managed to get about 500kbps from it, which would be the limiting factor on sample rate. I have it sampling at 4kHz though since I am working with lower frequencies on my project. I also have an FPGA board that can sample 16 bits at 1MHz, but I don't have the time to fix it since it broke a year ago or so (Advice: Always put cool projects into a box or case, cause it WILL break if you don't :-P).

 

I usually don't recommend a USB scope to people. They are not worth the money imo. If you want a USB scope, build one. It won't be as good as what you can buy, but you will spend less and have fun making it.

 

NJC

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×