EmbeddedRelated.com
Forums

Parralax servo and MSP430G2231

Started by pbbonham October 27, 2010
I have just recently picked up a TI MSP430 Launchpad. I am new to programming microprocessors.

I was wondering if someone can give me a few hints on PWM. I understand some of the basic principles of PWM in general, but I am having a hard time putting them to practice using TI's MSP430 family user's guide.

I am trying to control a continuous rotation servo from parallax.
The servo requires PWM to control it.

Basically I need to send a pulse on the signal pin on the servo.
I need to send it a 1.5 ms pulse every 20 ms to hold the servo in a locked state
I need to send it a 1.7 ms pulse every 20 ms to spin the servo in a CCW direction.
I need to send it a 1.3 ms pulse every 20 ms to spin the servo in a CW direction.

My clock runs at about 1MHz.

My issue is trying to determine the values for CCR0 and CCR1.
I borrowed the code from TI's example file msp430x20x3_ta_17.c and have been playing around with the values by guessing.

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x0C; // P1.2 and P1.3 output
P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
CCR0 = 512-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = 384; // CCR1 PWM duty cycle
TACTL = TASSEL_1 + MC_1; // ACLK, up mode

_BIS_SR(LPM3_bits); // Enter LPM3
}

As you can tell I am a bit lost. can anyone point me in the right direction?

Thank you,
Paul

Beginning Microcontrollers with the MSP430

I suggest you head back to year 3 of primary school. My 8 year old
grandson can manage the maths, and the amount of reading involved is
both trivial and not overly technical.

CCR0 sets the period of the PWm waveform, ie the 20msecs, so at a clock
speed of 1MHz you need to set CCR0 to 19999, simple enough? Now all you
need do for yourself is figure out how to calculate the 3 values needed
to set CCR1, which determines the pulse ON time.

Al

On 28/10/2010 6:06 AM, pbbonham wrote:
> I have just recently picked up a TI MSP430 Launchpad. I am new to programming microprocessors.
>
> I was wondering if someone can give me a few hints on PWM. I understand some of the basic principles of PWM in general, but I am having a hard time putting them to practice using TI's MSP430 family user's guide.
>
> I am trying to control a continuous rotation servo from parallax.
> The servo requires PWM to control it.
>
> Basically I need to send a pulse on the signal pin on the servo.
> I need to send it a 1.5 ms pulse every 20 ms to hold the servo in a locked state
> I need to send it a 1.7 ms pulse every 20 ms to spin the servo in a CCW direction.
> I need to send it a 1.3 ms pulse every 20 ms to spin the servo in a CW direction.
>
> My clock runs at about 1MHz.
>
> My issue is trying to determine the values for CCR0 and CCR1.
> I borrowed the code from TI's example file msp430x20x3_ta_17.c and have been playing around with the values by guessing.
>
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> P1DIR |= 0x0C; // P1.2 and P1.3 output
> P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
> CCR0 = 512-1; // PWM Period
> CCTL1 = OUTMOD_7; // CCR1 reset/set
> CCR1 = 384; // CCR1 PWM duty cycle
> TACTL = TASSEL_1 + MC_1; // ACLK, up mode
>
> _BIS_SR(LPM3_bits); // Enter LPM3
> }
>
> As you can tell I am a bit lost. can anyone point me in the right direction?
>
> Thank you,
> Paul
>
>
Aside from the PWM period and duty cycle, there are a few other mistakes in the code you shown.

There is no TA2 in F20xx nor G2xx1. Your settings for P1.3 are incorrect and useless.

You do not seem to have an ACLK. And even if you do have one, it would not be anywhere close to 1MHz. Yet in the TACTL setup, you selected ACLK to be the clock source for TimerA. This is incorrect.

If you use the SMCLK driven by the DCO to source TimerA, then you better use LPM0 instead of LPM3.

--- In m..., "pbbonham" wrote:
>
> I have just recently picked up a TI MSP430 Launchpad. I am new to programming microprocessors.
>
> I was wondering if someone can give me a few hints on PWM. I understand some of the basic principles of PWM in general, but I am having a hard time putting them to practice using TI's MSP430 family user's guide.
>
> I am trying to control a continuous rotation servo from parallax.
> The servo requires PWM to control it.
>
> Basically I need to send a pulse on the signal pin on the servo.
> I need to send it a 1.5 ms pulse every 20 ms to hold the servo in a locked state
> I need to send it a 1.7 ms pulse every 20 ms to spin the servo in a CCW direction.
> I need to send it a 1.3 ms pulse every 20 ms to spin the servo in a CW direction.
>
> My clock runs at about 1MHz.
>
> My issue is trying to determine the values for CCR0 and CCR1.
> I borrowed the code from TI's example file msp430x20x3_ta_17.c and have been playing around with the values by guessing.
>
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> P1DIR |= 0x0C; // P1.2 and P1.3 output
> P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
> CCR0 = 512-1; // PWM Period
> CCTL1 = OUTMOD_7; // CCR1 reset/set
> CCR1 = 384; // CCR1 PWM duty cycle
> TACTL = TASSEL_1 + MC_1; // ACLK, up mode
>
> _BIS_SR(LPM3_bits); // Enter LPM3
> }
>
> As you can tell I am a bit lost. can anyone point me in the right direction?
>
> Thank you,
> Paul
>

Al,
Thank you, I appreciate the help you have provided. As one who has only built PWM controllers using 555 timers I somehow missed the fact that 19999 will set the clock period to 20ms. hmm I guess I just need to read more of those wonderful datasheets written by TI for primary school children or just give up trying to learn a new way of doing things. Silly me for trying.

--- In m..., OneStone wrote:
>
> I suggest you head back to year 3 of primary school. My 8 year old
> grandson can manage the maths, and the amount of reading involved is
> both trivial and not overly technical.
>
> CCR0 sets the period of the PWm waveform, ie the 20msecs, so at a clock
> speed of 1MHz you need to set CCR0 to 19999, simple enough? Now all you
> need do for yourself is figure out how to calculate the 3 values needed
> to set CCR1, which determines the pulse ON time.
>
> Al
>
> On 28/10/2010 6:06 AM, pbbonham wrote:
> > I have just recently picked up a TI MSP430 Launchpad. I am new to programming microprocessors.
> >
> > I was wondering if someone can give me a few hints on PWM. I understand some of the basic principles of PWM in general, but I am having a hard time putting them to practice using TI's MSP430 family user's guide.
> >
> > I am trying to control a continuous rotation servo from parallax.
> > The servo requires PWM to control it.
> >
> > Basically I need to send a pulse on the signal pin on the servo.
> > I need to send it a 1.5 ms pulse every 20 ms to hold the servo in a locked state
> > I need to send it a 1.7 ms pulse every 20 ms to spin the servo in a CCW direction.
> > I need to send it a 1.3 ms pulse every 20 ms to spin the servo in a CW direction.
> >
> > My clock runs at about 1MHz.
> >
> > My issue is trying to determine the values for CCR0 and CCR1.
> > I borrowed the code from TI's example file msp430x20x3_ta_17.c and have been playing around with the values by guessing.
> >
> > void main(void)
> > {
> > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> > P1DIR |= 0x0C; // P1.2 and P1.3 output
> > P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
> > CCR0 = 512-1; // PWM Period
> > CCTL1 = OUTMOD_7; // CCR1 reset/set
> > CCR1 = 384; // CCR1 PWM duty cycle
> > TACTL = TASSEL_1 + MC_1; // ACLK, up mode
> >
> > _BIS_SR(LPM3_bits); // Enter LPM3
> > }
> >
> > As you can tell I am a bit lost. can anyone point me in the right direction?
> >
> > Thank you,
> > Paul
> >
> >
> >
> >
> >
> >
> >
> >
old_cow_yellow,

Thank you. I must have picked the wrong example from TI to play with.
I will make the changes you have suggested and see if I can get the code to work better on the device I am using.
That code is a direct copy and paste from the examples provided by TI for the MSP430G2x family of processors. I pulled it from http://tech.groups.yahoo.com/group/msp430/post?act=reply&messageNumG065 the link is labeled "MSP430F20xx, MSP430G2xx Code Examples (Rev. H)" So I assumed it was a good starting place.

Paul
--- In m..., "old_cow_yellow" wrote:
>
> Aside from the PWM period and duty cycle, there are a few other mistakes in the code you shown.
>
> There is no TA2 in F20xx nor G2xx1. Your settings for P1.3 are incorrect and useless.
>
> You do not seem to have an ACLK. And even if you do have one, it would not be anywhere close to 1MHz. Yet in the TACTL setup, you selected ACLK to be the clock source for TimerA. This is incorrect.
>
> If you use the SMCLK driven by the DCO to source TimerA, then you better use LPM0 instead of LPM3.
>
> --- In m..., "pbbonham" wrote:
> >
> > I have just recently picked up a TI MSP430 Launchpad. I am new to programming microprocessors.
> >
> > I was wondering if someone can give me a few hints on PWM. I understand some of the basic principles of PWM in general, but I am having a hard time putting them to practice using TI's MSP430 family user's guide.
> >
> > I am trying to control a continuous rotation servo from parallax.
> > The servo requires PWM to control it.
> >
> > Basically I need to send a pulse on the signal pin on the servo.
> > I need to send it a 1.5 ms pulse every 20 ms to hold the servo in a locked state
> > I need to send it a 1.7 ms pulse every 20 ms to spin the servo in a CCW direction.
> > I need to send it a 1.3 ms pulse every 20 ms to spin the servo in a CW direction.
> >
> > My clock runs at about 1MHz.
> >
> > My issue is trying to determine the values for CCR0 and CCR1.
> > I borrowed the code from TI's example file msp430x20x3_ta_17.c and have been playing around with the values by guessing.
> >
> > void main(void)
> > {
> > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> > P1DIR |= 0x0C; // P1.2 and P1.3 output
> > P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
> > CCR0 = 512-1; // PWM Period
> > CCTL1 = OUTMOD_7; // CCR1 reset/set
> > CCR1 = 384; // CCR1 PWM duty cycle
> > TACTL = TASSEL_1 + MC_1; // ACLK, up mode
> >
> > _BIS_SR(LPM3_bits); // Enter LPM3
> > }
> >
> > As you can tell I am a bit lost. can anyone point me in the right direction?
> >
> > Thank you,
> > Paul
>

Paul,

The fact that you didn't recognize ACLK suggests that you haven't read the family guide nor have you read all the examples.

Read the section on Timer A carefully and you should have a very good idea on what to do. Simply copying a piece of example code from TI will not get you much support from here until you at least show that you've tried to adapt it to your chip.

-Steve
-----Original Message-----
From: m... [mailto:m...] On Behalf Of pbbonham
Sent: Thursday, October 28, 2010 10:44 AM
To: m...
Subject: [msp430] Re: Parralax servo and MSP430G2231
old_cow_yellow,

Thank you. I must have picked the wrong example from TI to play with.
I will make the changes you have suggested and see if I can get the code to work better on the device I am using.
That code is a direct copy and paste from the examples provided by TI for the MSP430G2x family of processors. I pulled it from http://tech.groups.yahoo.com/group/msp430/post?act=reply&messageNumG065 the link is labeled "MSP430F20xx, MSP430G2xx Code Examples (Rev. H)" So I assumed it was a good starting place.

Paul
--- In m..., "old_cow_yellow" wrote:
>
> Aside from the PWM period and duty cycle, there are a few other mistakes in the code you shown.
>
> There is no TA2 in F20xx nor G2xx1. Your settings for P1.3 are incorrect and useless.
>
> You do not seem to have an ACLK. And even if you do have one, it would not be anywhere close to 1MHz. Yet in the TACTL setup, you selected ACLK to be the clock source for TimerA. This is incorrect.
>
> If you use the SMCLK driven by the DCO to source TimerA, then you better use LPM0 instead of LPM3.
>
> --- In m..., "pbbonham" wrote:
> >
> > I have just recently picked up a TI MSP430 Launchpad. I am new to programming microprocessors.
> >
> > I was wondering if someone can give me a few hints on PWM. I understand some of the basic principles of PWM in general, but I am having a hard time putting them to practice using TI's MSP430 family user's guide.
> >
> > I am trying to control a continuous rotation servo from parallax.
> > The servo requires PWM to control it.
> >
> > Basically I need to send a pulse on the signal pin on the servo.
> > I need to send it a 1.5 ms pulse every 20 ms to hold the servo in a locked state
> > I need to send it a 1.7 ms pulse every 20 ms to spin the servo in a CCW direction.
> > I need to send it a 1.3 ms pulse every 20 ms to spin the servo in a CW direction.
> >
> > My clock runs at about 1MHz.
> >
> > My issue is trying to determine the values for CCR0 and CCR1.
> > I borrowed the code from TI's example file msp430x20x3_ta_17.c and have been playing around with the values by guessing.
> >
> > void main(void)
> > {
> > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> > P1DIR |= 0x0C; // P1.2 and P1.3 output
> > P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
> > CCR0 = 512-1; // PWM Period
> > CCTL1 = OUTMOD_7; // CCR1 reset/set
> > CCR1 = 384; // CCR1 PWM duty cycle
> > TACTL = TASSEL_1 + MC_1; // ACLK, up mode
> >
> > _BIS_SR(LPM3_bits); // Enter LPM3
> > }
> >
> > As you can tell I am a bit lost. can anyone point me in the right direction?
> >
> > Thank you,
> > Paul
>

Steve,
I understand.

The fact that I am new to all embedded programming and the section on Timer A in the family guide is written so well that I had no clue on what I was reading is what prompted my request for pointers.

In no way was I looking for someone to do the work for me. I was looking for pointers on trying to understand and learn this for myself. I can not pick up the family guide and start programming an embedded system without a little direction from others. The guide expects a certain level on knowledge to start with and I do not have that.

I guess I need to move forward by finding another resource to help me learn enough to ask more informed questions.

Thank you everyone for such a great welcome and the help given to me.

Paul

--- In m..., "Hayashi, Steve" wrote:
>
> Paul,
>
> The fact that you didn't recognize ACLK suggests that you haven't read the family guide nor have you read all the examples.
>
> Read the section on Timer A carefully and you should have a very good idea on what to do. Simply copying a piece of example code from TI will not get you much support from here until you at least show that you've tried to adapt it to your chip.
>
> -Steve
> -----Original Message-----
> From: m... [mailto:m...] On Behalf Of pbbonham
> Sent: Thursday, October 28, 2010 10:44 AM
> To: m...
> Subject: [msp430] Re: Parralax servo and MSP430G2231
> old_cow_yellow,
>
> Thank you. I must have picked the wrong example from TI to play with.
> I will make the changes you have suggested and see if I can get the code to work better on the device I am using.
> That code is a direct copy and paste from the examples provided by TI for the MSP430G2x family of processors. I pulled it from http://tech.groups.yahoo.com/group/msp430/post?act=reply&messageNumG065 the link is labeled "MSP430F20xx, MSP430G2xx Code Examples (Rev. H)" So I assumed it was a good starting place.
>
> Paul
> --- In m..., "old_cow_yellow" wrote:
> >
> > Aside from the PWM period and duty cycle, there are a few other mistakes in the code you shown.
> >
> > There is no TA2 in F20xx nor G2xx1. Your settings for P1.3 are incorrect and useless.
> >
> > You do not seem to have an ACLK. And even if you do have one, it would not be anywhere close to 1MHz. Yet in the TACTL setup, you selected ACLK to be the clock source for TimerA. This is incorrect.
> >
> > If you use the SMCLK driven by the DCO to source TimerA, then you better use LPM0 instead of LPM3.
> >
> > --- In m..., "pbbonham" wrote:
> > >
> > > I have just recently picked up a TI MSP430 Launchpad. I am new to programming microprocessors.
> > >
> > > I was wondering if someone can give me a few hints on PWM. I understand some of the basic principles of PWM in general, but I am having a hard time putting them to practice using TI's MSP430 family user's guide.
> > >
> > > I am trying to control a continuous rotation servo from parallax.
> > > The servo requires PWM to control it.
> > >
> > > Basically I need to send a pulse on the signal pin on the servo.
> > > I need to send it a 1.5 ms pulse every 20 ms to hold the servo in a locked state
> > > I need to send it a 1.7 ms pulse every 20 ms to spin the servo in a CCW direction.
> > > I need to send it a 1.3 ms pulse every 20 ms to spin the servo in a CW direction.
> > >
> > > My clock runs at about 1MHz.
> > >
> > > My issue is trying to determine the values for CCR0 and CCR1.
> > > I borrowed the code from TI's example file msp430x20x3_ta_17.c and have been playing around with the values by guessing.
> > >
> > > void main(void)
> > > {
> > > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> > > P1DIR |= 0x0C; // P1.2 and P1.3 output
> > > P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
> > > CCR0 = 512-1; // PWM Period
> > > CCTL1 = OUTMOD_7; // CCR1 reset/set
> > > CCR1 = 384; // CCR1 PWM duty cycle
> > > TACTL = TASSEL_1 + MC_1; // ACLK, up mode
> > >
> > > _BIS_SR(LPM3_bits); // Enter LPM3
> > > }
> > >
> > > As you can tell I am a bit lost. can anyone point me in the right direction?
> > >
> > > Thank you,
> > > Paul
> > >
> >
>
Never silly for trying, just for missing the obvious. The Family user
Guide does a great job in my opinion of describing the timer functions,
and is possibly a better source than example code sometimes. ;@} best of
Luck

Al

On 29/10/2010 1:07 AM, pbbonham wrote:
> Al,
> Thank you, I appreciate the help you have provided. As one who has only built PWM controllers using 555 timers I somehow missed the fact that 19999 will set the clock period to 20ms. hmm I guess I just need to read more of those wonderful datasheets written by TI for primary school children or just give up trying to learn a new way of doing things. Silly me for trying.
>
> --- In m..., OneStone wrote:
>> I suggest you head back to year 3 of primary school. My 8 year old
>> grandson can manage the maths, and the amount of reading involved is
>> both trivial and not overly technical.
>>
>> CCR0 sets the period of the PWm waveform, ie the 20msecs, so at a clock
>> speed of 1MHz you need to set CCR0 to 19999, simple enough? Now all you
>> need do for yourself is figure out how to calculate the 3 values needed
>> to set CCR1, which determines the pulse ON time.
>>
>> Al
>>
>> On 28/10/2010 6:06 AM, pbbonham wrote:
>>> I have just recently picked up a TI MSP430 Launchpad. I am new to programming microprocessors.
>>>
>>> I was wondering if someone can give me a few hints on PWM. I understand some of the basic principles of PWM in general, but I am having a hard time putting them to practice using TI's MSP430 family user's guide.
>>>
>>> I am trying to control a continuous rotation servo from parallax.
>>> The servo requires PWM to control it.
>>>
>>> Basically I need to send a pulse on the signal pin on the servo.
>>> I need to send it a 1.5 ms pulse every 20 ms to hold the servo in a locked state
>>> I need to send it a 1.7 ms pulse every 20 ms to spin the servo in a CCW direction.
>>> I need to send it a 1.3 ms pulse every 20 ms to spin the servo in a CW direction.
>>>
>>> My clock runs at about 1MHz.
>>>
>>> My issue is trying to determine the values for CCR0 and CCR1.
>>> I borrowed the code from TI's example file msp430x20x3_ta_17.c and have been playing around with the values by guessing.
>>>
>>> void main(void)
>>> {
>>> WDTCTL = WDTPW + WDTHOLD; // Stop WDT
>>> P1DIR |= 0x0C; // P1.2 and P1.3 output
>>> P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
>>> CCR0 = 512-1; // PWM Period
>>> CCTL1 = OUTMOD_7; // CCR1 reset/set
>>> CCR1 = 384; // CCR1 PWM duty cycle
>>> TACTL = TASSEL_1 + MC_1; // ACLK, up mode
>>>
>>> _BIS_SR(LPM3_bits); // Enter LPM3
>>> }
>>>
>>> As you can tell I am a bit lost. can anyone point me in the right direction?
>>>
>>> Thank you,
>>> Paul
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
Given what you've just said, I would recommend looking for tutorials for the MSP430. A quick google search returns quite a lot and it will give you the fundamentals you'll need to proceed further.

Most people here are willing to answer more specific questions that you have. Like for example: In OUTMOD_7, the output will be 0 once the timer reaches the value in CCR1 and will be 1 when the timer reaches CCR0. Up mode will increment the timer until it reaches the value in CCR0, and then it will start back from 0. And the Timer will increment at whatever clock you set it to, divided by whatever divider you set it to.

-Steve

-----Original Message-----
From: m... [mailto:m...] On Behalf Of pbbonham
Sent: Thursday, October 28, 2010 1:05 PM
To: m...
Subject: [msp430] Re: Parralax servo and MSP430G2231

Steve,
I understand.

The fact that I am new to all embedded programming and the section on Timer A in the family guide is written so well that I had no clue on what I was reading is what prompted my request for pointers.

In no way was I looking for someone to do the work for me. I was looking for pointers on trying to understand and learn this for myself. I can not pick up the family guide and start programming an embedded system without a little direction from others. The guide expects a certain level on knowledge to start with and I do not have that.

I guess I need to move forward by finding another resource to help me learn enough to ask more informed questions.

Thank you everyone for such a great welcome and the help given to me.

Paul

--- In m..., "Hayashi, Steve" wrote:
>
> Paul,
>
> The fact that you didn't recognize ACLK suggests that you haven't read the family guide nor have you read all the examples.
>
> Read the section on Timer A carefully and you should have a very good idea on what to do. Simply copying a piece of example code from TI will not get you much support from here until you at least show that you've tried to adapt it to your chip.
>
> -Steve
> -----Original Message-----
> From: m... [mailto:m...] On Behalf Of pbbonham
> Sent: Thursday, October 28, 2010 10:44 AM
> To: m...
> Subject: [msp430] Re: Parralax servo and MSP430G2231
> old_cow_yellow,
>
> Thank you. I must have picked the wrong example from TI to play with.
> I will make the changes you have suggested and see if I can get the code to work better on the device I am using.
> That code is a direct copy and paste from the examples provided by TI for the MSP430G2x family of processors. I pulled it from http://tech.groups.yahoo.com/group/msp430/post?act=reply&messageNumG065 the link is labeled "MSP430F20xx, MSP430G2xx Code Examples (Rev. H)" So I assumed it was a good starting place.
>
> Paul
> --- In m..., "old_cow_yellow" wrote:
> >
> > Aside from the PWM period and duty cycle, there are a few other mistakes in the code you shown.
> >
> > There is no TA2 in F20xx nor G2xx1. Your settings for P1.3 are incorrect and useless.
> >
> > You do not seem to have an ACLK. And even if you do have one, it would not be anywhere close to 1MHz. Yet in the TACTL setup, you selected ACLK to be the clock source for TimerA. This is incorrect.
> >
> > If you use the SMCLK driven by the DCO to source TimerA, then you better use LPM0 instead of LPM3.
> >
> > --- In m..., "pbbonham" wrote:
> > >
> > > I have just recently picked up a TI MSP430 Launchpad. I am new to programming microprocessors.
> > >
> > > I was wondering if someone can give me a few hints on PWM. I understand some of the basic principles of PWM in general, but I am having a hard time putting them to practice using TI's MSP430 family user's guide.
> > >
> > > I am trying to control a continuous rotation servo from parallax.
> > > The servo requires PWM to control it.
> > >
> > > Basically I need to send a pulse on the signal pin on the servo.
> > > I need to send it a 1.5 ms pulse every 20 ms to hold the servo in a locked state
> > > I need to send it a 1.7 ms pulse every 20 ms to spin the servo in a CCW direction.
> > > I need to send it a 1.3 ms pulse every 20 ms to spin the servo in a CW direction.
> > >
> > > My clock runs at about 1MHz.
> > >
> > > My issue is trying to determine the values for CCR0 and CCR1.
> > > I borrowed the code from TI's example file msp430x20x3_ta_17.c and have been playing around with the values by guessing.
> > >
> > > void main(void)
> > > {
> > > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> > > P1DIR |= 0x0C; // P1.2 and P1.3 output
> > > P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
> > > CCR0 = 512-1; // PWM Period
> > > CCTL1 = OUTMOD_7; // CCR1 reset/set
> > > CCR1 = 384; // CCR1 PWM duty cycle
> > > TACTL = TASSEL_1 + MC_1; // ACLK, up mode
> > >
> > > _BIS_SR(LPM3_bits); // Enter LPM3
> > > }
> > >
> > > As you can tell I am a bit lost. can anyone point me in the right direction?
> > >
> > > Thank you,
> > > Paul
> > >
> >
>
pbbonham wrote:
> Steve,
> I understand.
>
> The fact that I am new to all embedded programming and the section on Timer A in the family guide is written so well that I had no clue on what I was reading is what prompted my request for pointers.
>

Hi Paul,
But that is the way it works, if 'you' want to program the timer, you
will have to look at that section until it starts to make sense. Right
at the top is the block diagram. How is your comfort level looking at
it? Right at the top left you can see you need to select a clock. This
is where you program starts, you look over the timer and come up with a
plan to use it before writing one line of code.

Look further down at figure 12-9. This looks like just what you want to
end up doing. You want an adjustable pulse width of about 1.5ms every
10-20ms. So you need just one compare with TCCR1, the second with TCCR2
is not part of your plan. So now you can start by selecting a
clock/divisor and TCCR0 for the timer to have it up/down at some 15ms. A
little more math and you have TCCR1 that gets a value range for your
pulse width range. And when you think you have that plan together, you
will have the result on the 'OUT' pin of the comparator.

And this is just one possible plan, there are other ways to do it.

From there you look at the device datasheet, find a pin that you can
tie to that output. Look at the block diagram for that pin and find out
what you need to set to get the timer output to the pin.

> In no way was I looking for someone to do the work for me. I was looking for pointers on trying to understand and learn this for myself. I can not pick up the family guide and start programming an embedded system without a little direction from others. The guide expects a certain level on knowledge to start with and I do not have that.
>

And if your objective is to understand it, you must 'program' this
without writing any code 'first'. Understand how/why all the registers
are set first. The code controls the timer and pin, without knowing what
you want to do with the timer and pin, you can't write the code. When I
work with a peripheral, I have a hard copy, usually two sided print,
stapled together, of that periphrial in my hand. Print the Timer_A
section and curl up with it for a while...

Best, Dan.