Jump to content
43oh

2 Questions on how to use the MSP430g2252 the best way


Recommended Posts

Hiya, as i am still very new to this stuff, 2 quick questions about the use of the MSP430g2252 for my car drive project:

 

1:The g2252 that has 18 I/O pins, using 2 ports. Looking at the pinouts i am thinking i'd best use the second port for basic things like buttons and leds, and reserve the multi purpose pins (with ADC for instance) on the first for adding sensors and stuff. Is that correct?

 

2: The 2252 only has one timer, but i want to use interrupts for the serial communication as well as possibly PWM motor drive. Is that still possible using one of the clocks or am i better off using an msp with more timers?

 

I will find out eventually, but a quick heads up before i do too much planning would be nice :)

 

Thanks!

MarkoeZ

Link to post
Share on other sites
1:The g2252 that has 18 I/O pins, using 2 ports. Looking at the pinouts i am thinking i'd best use the second port for basic things like buttons and leds, and reserve the multi purpose pins (with ADC for instance) on the first for adding sensors and stuff. Is that correct?

This theory should be ok.

 

2: The 2252 only has one timer, but i want to use interrupts for the serial communication as well as possibly PWM motor drive. Is that still possible using one of the clocks or am i better off using an msp with more timers?

It helps if you use a chip with a hardware uart if you have alot going on. Anything that could be pushed to hardware is good.

Link to post
Share on other sites

Thanks for the tips!

About my second question, i have an MSP430G2553 with hardware uart i could use, but i was planning to save that one for the next project (with servo, rangefinder, and more goodies)

 

Now some googling reminded me that i have the Watchdog Timer as well. Would that also work for motor drive pwm?

Edit: Posted on phone originally, this is the site i found: http://justinstech.org/2010/10/msp430-interrupt-driven-pwm/

 

Greetings,

MarkoeZ

Link to post
Share on other sites
To get by with what you have, do what I do. Use the one timer to create a master clock, then I just use variables that get their timing from that clock.

 

So you can have a software PWM on any pin.

 

hmm, you mean i could use a main interrupt powered by the single timer, and just check,add to and reset individual integers for motor drive pwm, and toggle pins there?

 

sounds interesting

 

Edit: not sure how to time the serial then though... :?

 

Edit2: ooooh wait, i have 3 ccr's on the timer, i could use one for the serial, and 2 for the motor drive pwm? since this first project will only use pwm on the forward/backward drive, that might be enough, right?

 

Another edit: example 3 in this pdf looks very useful for that: http://www.ccs.neu.edu/home/noubir/Courses/CSU610/S07/MSP430-Clock-Timers.pdf

Link to post
Share on other sites

lol its always funny that my site comes up here and there :)

 

Another edit: example 3 in this pdf looks very useful for that: http://www.ccs.neu.edu/home/noubir/Courses/CSU610/S07/MSP430-Clock-Timers.pdf

I like that last example, Thanks.

 

But yes you could use the WDT for PWM, its not the most efficient but it gets the job done..... On a side note, you can use almost the same code for any other interval interrupts -- (timer_A)

Link to post
Share on other sites
lol its always funny that my site comes up here and there :)

 

But yes you could use the WDT for PWM, its not the most efficeint but it gets the job done

 

ok, in that case, could i not better use the WDT for the serial timer, and timerA for the pwm? the motor drive can handle a small bump i guess, the serial would get corrupted probably. But again: new to this stuff so no clue really.

Just using the 3 ccr's like mentioned above might work as well though?

Link to post
Share on other sites

using the WDT for serial timing would not be very good, WDT has very limited options, I would suggest use one of the C/C registers for your serial timing and use the other 2 for PWM, and if you need more use the WDT interval timer

 

 

 

so let me exapnd a little -- WDT CLK can only be sourced from 2 places SMCLK and ACLK --

and the divider options, CLK/ 32768, CLK/ 8192, CLK/512 CLK/ 64

 

other then these settings you really cant set the speed

Link to post
Share on other sites

Thanks, using the CCR registers seems the way to go for this project then.

The main drive motor pwm and serial really are the only time critical components in this setup, i can handle the rest in the main loop probably. And otherwise there are some other interrupts (that are lower in priority, right?) that i can use.

Link to post
Share on other sites

Yes there are other interrupts that have different priorities, even better is if you use maskable interrupts you can set your own priorities for different interrupts.

 

Interrupt, Flag, Priority

Power-up, external

reset, watchdog, PORIFG

flash password, RSTIFG

illegal instruction WDTIFG Reset 0FFFEh 31, highest

fetch KEYV

 

 

 

 

 

 

NMI, oscillator fault, NMIIFG (non)-maskable 0FFFCh 30

flash memory access OFIFG

violation ACCVIFG

 

0FFFCh 30

 

device-specific 0FFFAh 29

device-specific 0FFF8h 28

device-specific 0FFF6h 27

Watchdog timer WDTIFG maskable 0FFF4h 26

device-specific 0FFF2h 25

device-specific 0FFF0h 24

device-specific 0FFEEh 23

device-specific 0FFECh 22

device-specific 0FFEAh 21

device-specific 0FFE8h 20

device-specific 0FFE6h 19

device-specific 0FFE4h 18

device-specific 0FFE2h 17

device-specific 0FFE0h 16

device-specific 0FFDEh 15

device-specific 0FFDCh 14

device-specific 0FFDAh 13

device-specific 0FFD8h 12

device-specific 0FFD6h 11

device-specific 0FFD4h 10

device-specific 0FFD2h 9

device-specific 0FFD0h 8

device-specific 0FFCEh 7

device-specific 0FFCCh 6

device-specific 0FFCAh 5

device-specific 0FFC8h 4

device-specific 0FFC6h 3

device-specific 0FFC4h 2

device-specific 0FFC2h 1

device-specific 0FFC0h 0, lowest

Link to post
Share on other sites

Hmm, i've been experimenting with the CCR's, with mixed results.

 

I could use software serial using CCR0 and simultaniously get a led blinking using CCR1 and CCR2.

Problem is that the led is not blinking in a PWM kind of way, but kind of randomly. Edit: Well it seems to do the pwm, but something is interfering and making it blink bright randomly while it should be dimmed...

 

I removed all code that was not relevant to the PWM, and still the same result.

 

I suspect things go wrong when the timer overflows, but not really sure.

 

Now it's probably something silly/stupid, but maybe one of you has an idea:

 

#include 

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;

if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
	while(1); // If cal constants erased, trap CPU!!
}
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation

CCTL1 = CCIE;
CCTL2 = CCIE;
CCR1 = 800;
CCR2 = 1000;
TACTL = TASSEL_1 + MC_2+ TAIE;

P2DIR = 0X0A;               // set both leds to output
P2OUT = 0;                  // and set them off initially
__bis_SR_register(GIE);			// interrupts enabled\

while(1)
{


}
}

#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer(void)
{
switch( TAIV )
{
  case  2: P2OUT |= 0x08;		//Turn led on on CCR1
 			break;                          
  case  4: P2OUT &= ~0x08;		//And off again on CCR2
  			CCR1 += 1000;		//and set the ccr's for next pulse width
  			CCR2 += 1000;
  			break;

  case 10:                   // overflow
           break;
}

}

Link to post
Share on other sites
  • 3 weeks later...

Ok, just in case someone ends up here in a search:

I solved this by using the Watchdog Timer for the PWM using jsolarski's code, from this page: http://justinstech.org/2010/10/msp430-interrupt-driven-pwm/

 

Full description here: http://markoez.pirategames.co.uk/index.php/blog/msp430-serial-pwm-using-one-timer-and-wdt/

 

Cheers!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...