Reply by shskurkra June 27, 20102010-06-27
Hi Group,

LED is program to stay high and low for interrupt; from switch and timer. Looked at PWM application program from TI.

Interested to make LED act as PWM kind of; starting at slowly increases its brightness and slowly decreasing its brightness for the interrupts.

I tried to use Timer B to do the PWM. Inserted the for loop inside ISR of port interrupt and timer interrupt routine. Here is the initializations of timer B. Help me out with this code. Thank you.

Beginning Microcontrollers with the MSP430

Reply by old_cow_yellow June 7, 20102010-06-07
I give up. --- OCY

--- In m..., "shskurkra" wrote:
>
> The code does not work for desired output. Instead the LED stays high always. I was expected to have LED ON and OFF for 30 seconds and OFF for input provided from switch with-in 30 seconds. THe code is posted below. Please help to debug. Thank you.
> ========
> program
> ========
> #include
> #define PERIOD (50)
> #define DUTY (25)
> static volatile unsigned int timer_event;
> int true;
>
> int main( ) {
> int false;
>
> WDTCTL= WDTPW + WDTHOLD; // turn off the watchdog timer.
> P1IN = 0x06;
> P1DIR |= 0x00; // Set all P1.x to input direction, that is bit 0 is
> //turned to input
> P1DIR |= 0x05; // Set P1.8 to output direction, that is bit 0 is
> //turned to output
>
>
> BCSCTL1= CALBC1_16MHZ;
> DCOCTL= CALDCO_16MHZ;
>
> while (1==1) {
> if ((P1IN & 0x06) !=0){
> P1OUT = P1OUT ^ 0x05; // LED ON.
> }
>
> TACTL= MC_0 | TASSEL_2 | ID_3 | TACLR; // reset it, first.
> TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE; // set the mode.
> TACCR0= 19999; // 10ms
> //intervals.[change here for 15 seconds or 30 seconds delay]
> TACCR0= 5999; // For 15 seconds
> //299999999 or 30 seconds 59999999 delay]
> TACTL= MC_1 | TASSEL_2 | ID_3; // turn it off.
>
> __enable_interrupt( );
> __low_power_mode_0( );
>
> for ( ; ; ){
> static int counter= DUTY - 1;
> static enum { up, down } count_direction= up;
> timer_event= true;
> switch ( count_direction ) {
> case up:
> if ( ++counter >= PERIOD )
> count_direction= down;
> break;
> case down:
> if ( --counter <= 0 )
> count_direction= up;
> break;
> }
> if ( counter == DUTY )
> switch ( count_direction ) {
> case up:
> P1OUT |= 0x05; // LED on
> break;
> case down:
> P1OUT &= ~0x05; // LED off
> break;
> }
> for ( timer_event= false; !timer_event; )
> P1OUT = P1OUT ^0x05; // LED OFF;
> while (P1IN & 0x06 != 0) {
> P1OUT = P1OUT ^0x05; // LED OFF.
> }
> }
> }
> }
>
Reply by shskurkra June 6, 20102010-06-06
The code does not work for desired output. Instead the LED stays high always. I was expected to have LED ON and OFF for 30 seconds and OFF for input provided from switch with-in 30 seconds. THe code is posted below. Please help to debug. Thank you.
========
program
========
#include
#define PERIOD (50)
#define DUTY (25)
static volatile unsigned int timer_event;
int true;

int main( ) {
int false;

WDTCTL= WDTPW + WDTHOLD; // turn off the watchdog timer.
P1IN = 0x06;
P1DIR |= 0x00; // Set all P1.x to input direction, that is bit 0 is
//turned to input
P1DIR |= 0x05; // Set P1.8 to output direction, that is bit 0 is
//turned to output
BCSCTL1= CALBC1_16MHZ;
DCOCTL= CALDCO_16MHZ;

while (1==1) {
if ((P1IN & 0x06) !=0){
P1OUT = P1OUT ^ 0x05; // LED ON.
}

TACTL= MC_0 | TASSEL_2 | ID_3 | TACLR; // reset it, first.
TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE; // set the mode.
TACCR0= 19999; // 10ms
//intervals.[change here for 15 seconds or 30 seconds delay]
TACCR0= 5999; // For 15 seconds
//299999999 or 30 seconds 59999999 delay]
TACTL= MC_1 | TASSEL_2 | ID_3; // turn it off.

__enable_interrupt( );
__low_power_mode_0( );

for ( ; ; ){
static int counter= DUTY - 1;
static enum { up, down } count_direction= up;
timer_event= true;
switch ( count_direction ) {
case up:
if ( ++counter >= PERIOD )
count_direction= down;
break;
case down:
if ( --counter <= 0 )
count_direction= up;
break;
}
if ( counter == DUTY )
switch ( count_direction ) {
case up:
P1OUT |= 0x05; // LED on
break;
case down:
P1OUT &= ~0x05; // LED off
break;
}
for ( timer_event= false; !timer_event; )
P1OUT = P1OUT ^0x05; // LED OFF;
while (P1IN & 0x06 != 0) {
P1OUT = P1OUT ^0x05; // LED OFF.
}
}
}
}
Reply by Joe Radomski May 3, 20102010-05-03
change the clocking of timer if you need an interval longer than what its currently configured for.. timer a can be sourced by several clocks, and these clocks can have divisors..
 
--- On Mon, 5/3/10, shskurkra wrote:
From: shskurkra
Subject: [msp430] Re: Soft-Start to "ON" and Soft-Start to "OFF" - LED
To: m...
Date: Monday, May 3, 2010, 1:02 AM
 

Thank you, Joe R, OCY and others. Finally, managed to execute code without errors, but still i'm in puzzle with delay for 1minutes, 2 minutes, and so on....I have't figured out how to solve the delay problem. MSP430 has 16-bit registers... .Anyways, once I implement with the kit, I will contact this group.
See you all soon.

--- In msp430@yahoogroups. com, "old_cow_yellow" wrote:
>
> The word "Homomorphism" exists, but it is probably not in your vocabulary. Thus you do not get it.
>
> Type "bool" exists, but it is not in the vocabulary of the c-compiler you are using. Thus the compiler does not get it.
>
> Homomorphism is not in my vocabulary either. But I think the set non-zero and zero is a homomorphism of the set True and False.
>
> --- In msp430@yahoogroups. com, "shskurkra" wrote:
> >
> >
> >
> > Thank you OCY.
> >
> > 240 hours per day, I got the point; that leads to --> Timer A can have maximum of 65535. So, I should use delay loop for particular delay. For example, 1 minute, 30 seconds ,....
> > Homomorphism --> I did not figure it out.
> >
> > One more thing, is my logic correct.
> > To:-
> > (1) ON LED at interrupt;
> > (2) OFF LED at particular time and with interrupt too;
> >
> > --- In msp430@yahoogroups. com, "shskurkra" wrote:
> > >
> > > Read datasheet, user guide. Manged to give correct syntax for pin input and output. But, the 16th bit register, and "bool" error still exists. Can anyone give an hint to solve the errors.
> > >
> > > The program is:
> > >
Reply by shskurkra May 3, 20102010-05-03
Thank you, Joe R, OCY and others. Finally, managed to execute code without errors, but still i'm in puzzle with delay for 1minutes, 2 minutes, and so on....I have't figured out how to solve the delay problem. MSP430 has 16-bit registers....Anyways, once I implement with the kit, I will contact this group.
See you all soon.
--- In m..., "old_cow_yellow" wrote:
>
> The word "Homomorphism" exists, but it is probably not in your vocabulary. Thus you do not get it.
>
> Type "bool" exists, but it is not in the vocabulary of the c-compiler you are using. Thus the compiler does not get it.
>
> Homomorphism is not in my vocabulary either. But I think the set non-zero and zero is a homomorphism of the set True and False.
>
> --- In m..., "shskurkra" wrote:
> >
> >
> >
> > Thank you OCY.
> >
> > 240 hours per day, I got the point; that leads to --> Timer A can have maximum of 65535. So, I should use delay loop for particular delay. For example, 1 minute, 30 seconds ,....
> > Homomorphism --> I did not figure it out.
> >
> > One more thing, is my logic correct.
> > To:-
> > (1) ON LED at interrupt;
> > (2) OFF LED at particular time and with interrupt too;
> >
> > --- In m..., "shskurkra" wrote:
> > >
> > > Read datasheet, user guide. Manged to give correct syntax for pin input and output. But, the 16th bit register, and "bool" error still exists. Can anyone give an hint to solve the errors.
> > >
> > > The program is:
> > >
Reply by old_cow_yellow May 2, 20102010-05-02
The word "Homomorphism" exists, but it is probably not in your vocabulary. Thus you do not get it.

Type "bool" exists, but it is not in the vocabulary of the c-compiler you are using. Thus the compiler does not get it.

Homomorphism is not in my vocabulary either. But I think the set non-zero and zero is a homomorphism of the set True and False.

--- In m..., "shskurkra" wrote:
>
>
>
> Thank you OCY.
>
> 240 hours per day, I got the point; that leads to --> Timer A can have maximum of 65535. So, I should use delay loop for particular delay. For example, 1 minute, 30 seconds ,....
> Homomorphism --> I did not figure it out.
>
> One more thing, is my logic correct.
> To:-
> (1) ON LED at interrupt;
> (2) OFF LED at particular time and with interrupt too;
>
> --- In m..., "shskurkra" wrote:
> >
> > Read datasheet, user guide. Manged to give correct syntax for pin input and output. But, the 16th bit register, and "bool" error still exists. Can anyone give an hint to solve the errors.
> >
> > The program is:
> >
Reply by OneStone May 2, 20102010-05-02
Hi OCY

1) Sorry I'm happily married, and aspirin cures my headaches
2) Slacker, why not work full time.

Al

old_cow_yellow wrote:
> Correct syntax is necessary but not sufficient. For examples:
>
> (1) Use homomorphism.
> (2) Work 240 hours per day.
>
> -- OCY
>
> --- In m..., "shskurkra" wrote:
>> Read datasheet, user guide. Manged to give correct syntax for pin input and output. But, the 16th bit register, and "bool" error still exists. Can anyone give an hint to solve the errors.
>>
>> The program is:
>> ===============>> #include
>> static volatile bool timer_event;
>> int true;
>>
>> int main( ) {
>> int false;
>>
>> WDTCTL= WDTPW + WDTHOLD; // turn off the watchdog timer.
>>
>> P1DIR |= 0x00; // Set all P1.x to input direction, that is bit 0 is turned to input
>> P1DIR |= 0111; // Set P1.8 to output direction, that is bit 0 is turned to output
>> BCSCTL1= CALBC1_16MHZ;
>> DCOCTL= CALDCO_16MHZ;
>>
>> while (1) {
>> P1OUT = 0111; // LED ON.
>> }
>>
>> TACTL= MC_0 | TASSEL_2 | ID_3 | TACLR; // reset it, first.
>> TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE; // set the mode.
>> //TACCR0= 19999; // 10ms intervals.[change here for 15 seconds or 30 seconds delay]
>> TACCR0= 59999999; // For 15 seconds 29999999 or 30 seconds 59999999 delay]
>> TACTL= MC_1 | TASSEL_2 | ID_3; // turn it off.
>>
>> __enable_interrupt( );
>>
>> for ( ; ; ){
>> for ( timer_event= false; !timer_event; )
>> P1OUT = 0x00; // LED OFF;
>> while (1) {
>> P1OUT = 0x00; // LED OFF.
>> }
>> }
>> }
>>
>> #define PERIOD (50)
>> #define DUTY (25)
>>
>> #pragma vector= TIMERA0_VECTOR
>> __interrupt void timer_A2( void ) {
>> static int counter= DUTY - 1;
>> static enum { up, down } count_direction= up;
>> timer_event= true;
>> switch ( count_direction ) {
>> case up:
>> if ( ++counter >= PERIOD )
>> count_direction= down;
>> break;
>> case down:
>> if ( --counter <= 0 )
>> count_direction= up;
>> break;
>> }
>> if ( counter == DUTY )
>> switch ( count_direction ) {
>> case up:
>> P1OUT |= 0111; // LED on
>> break;
>> case down:
>> P1OUT &= ~0111; // LED off
>> break;
>> }
>> return;
>> }
>> ====================>>
>> --- In m..., Joe Radomski wrote:
>>> first of all the timers are only 16bit registers!
>>> You REALLY need to read the family user guide for the intended device AND the data sheets..
>>>
>>>
>>>
>>> --- On Thu, 4/29/10, shskurkra wrote:
>>>
>>>
>>> From: shskurkra
>>> Subject: [msp430] Re: Soft-Start to "ON" and Soft-Start to "OFF" - LED
>>> To: m...
>>> Date: Thursday, April 29, 2010, 11:38 PM
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Hi Bob, I tried to execute the code, but I have errors. Regarding "bool", the number "59999999" . Does anybody can give me ideas to debug this program.
>>> Thank you.
>>>
>>> ===========>>> #include
>>> static volatile bool timer_event;
>>>
>>> int main( ) {
>>>
>>> WDTCTL= WDTPW + WDTHOLD; // turn off the watchdog timer.
>>>
>>> P2DIR |= 0x00; // Set P2.0 to input direction, that is bit 0 is turned to input
>>>
>>> P7DIR |= 0x01; // Set P7.0 to output direction, that is bit 0 is turned to output
>>>
>>> //BCSCTL1= CALBC1_16MHZ;
>>> //DCOCTL= CALDCO_16MHZ;
>>>
>>> BCSCTL1= CALBC1_16MHZ;
>>> DCOCTL= CALDCO_16MHZ;
>>>
>>> // BCSCTL1= XT2OFF | RSEL3 | RSEL2 | RSEL1 | RSEL0; // Microcontroller runs at faster rate at 16MHz range
>>> // DCOCTL= DCO2 | DCO1 | DCO0; // Microcontroller runs at faster rate 16MHz range
>>>
>>> __enable_interrupt( );
>>>
>>> for ( ; ; ) {
>>> //P7OUT ^= 0x01; // using XOR toggles the pin value.
>>> P7OUT = 0x01; // LED ON.
>>> for ( timer_event= false; !timer_event; )
>>> P7OUT = 0x00; // LED OFF;
>>> else
>>> for ( ; ; ) {
>>> P7OUT = 0x00; // LED OFF.
>>> }
>>>
>>> return 0;
>>> }
>>> }
>>>
>>> TACTL= MC_0 | TASSEL_2 | ID_3 | TACLR; // reset it, first.
>>> TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE; // set the mode.
>>> //TACCR0= 19999; // 10ms intervals.[change here for 15 seconds or 30 seconds delay]
>>> TACCR0= 59999999; // For 15 seconds 29999999 or 30 seconds 59999999 delay]
>>> TACTL= MC_1 | TASSEL_2 | ID_3; // turn it off.
>>>
>>> #pragma vector= TIMERA0_VECTOR
>>> __interrupt void timer_A2( void ) {
>>> timer_event= true;
>>> return 0;
>>> }
>>> }
>>> =======>>>
>>> --- In msp430@yahoogroups. com, "shskurkra" wrote:
>>>> The code for LED ON and OFF. Managed to write, but not sure about the for loop part errors. Please let me know. Thank you.
>>>> ========>>>> PROGRAM
>>>> ========>>>> #include
>>>> static volatile bool timer_event;
>>>>
>>>> int main( ) {
>>>>
>>>> WDTCTL= WDTPW + WDTHOLD; // turn off the watchdog timer.
>>>>
>>>> P2DIR |= 0x00; // Set P2.0 to input direction, that is bit 0 is turned to input
>>>>
>>>> P7DIR |= 0x01; // Set P7.0 to output direction, that is bit 0 is turned to output
>>>>
>>>> BCSCTL1= CALBC1_8MHZ;
>>>> DCOCTL= CALDCO_8MHZ;
>>>>
>>>> __enable_interrupt( );
>>>>
>>>> for ( ; ; ) {
>>>> //P7OUT ^= 0x01; // using XOR toggles the pin value.
>>>> P7OUT = 0x01; // LED ON.
>>>> for ( timer_event= false; !timer_event; )
>>>> P7OUT = 0x00; // LED OFF;
>>>> else
>>>> for ( ; ; ) {
>>>> P7OUT = 0x00; // LED OFF.
>>>> }
>>>>
>>>> return 0;
>>>> }
>>>>
>>>>
>>>> TACTL= MC_0 | TASSEL_2 | ID_3 | TACLR; // reset it, first.
>>>> TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE; // set the mode.
>>>> TACCR0= 59999999; // For 15 seconds 29999999 or 30 seconds 59999999 delay]
>>>> TACTL= MC_1 | TASSEL_2 | ID_3; // turn it off.
>>>>
>>>>
>>>> #pragma vector= TIMERA0_VECTOR
>>>> __interrupt void timer_A2( void ) {
>>>> timer_event= true;
>>>> return;
>>>> }
>>>> ============ ====>>>> --- In msp430@yahoogroups. com, "Bob" wrote:
>>>>>> can I simulate Assembly code and C
>>>>>> written code together in code composer studio v4.
>>>>> Sorry, I don't know the answer to that...
>>>>>
>>>>> --- In msp430@yahoogroups. com, Shreyas Kumar Krishnappa wrote:
>>>>>> The example is 8.18. One question, can I simulate Assembly code and C
>>>>>> written code together in code composer studio v4.
>>>>>>
>>>>>>
>>>>>> On Thu, Apr 15, 2010 at 11:13 PM, Bob wrote:
>>>>>>
>>>>>>>
>>>>>>> I've not had need to write such routines, but I believe I've seen them in
>>>>>>> John Davies' text on the MSP430 (
>>>>>>> http://www.amazon. com/MSP430- Microcontroller- Basics-John- Davies/dp/ 0750682760),
>>>>>>> and if I remember correctly, the code examples can be downloaded.
>>>>>>>
>>>>>>>
>>>>>>> --- In msp430@yahoogroups. com , "shskurkra"
>>>>>>> wrote:
>>>>>>>> Thanks Bob, for your potential feedback. How about turning LED ON from
>>>>>>> dim to bright and vice versa.
>>>>>>>> I looked through PWM continuous signal.
>>>>>>>> Do you have an alternative method like altering duty cycle for certain
>>>>>>> seconds to start LED from dim to certain brightness.
>>>>>>>>
>>>>>>>> --- In msp430@yahoogroups. com , "Bob"
>>>>>>> wrote:
>>>>>>>>> shskurkra,
>>>>>>>>>
>>>>>>>>> You might simply use two interrupt routines. One for your button, a
>>>>>>> second one tied to a timer of your choice. On a button press, if the LED is
>>>>>>> off, turn it on and start a timer running that will trigger a second
>>>>>>> interrupt at 60 seconds to turn the LED off and stop the timer. If the LED
>>>>>>> is on when the button's pressed, turn it and the timer off.
>>>>>>>>> So, if the user presses the button only once, LED stays on for one
>>>>>>> minute and then turns off. If the user presses the button a second time in
>>>>>>> less than a minute, LED turns off. No loops, and you can run in a pretty low
>>>>>>> power mode waiting for the initial button press. HTH
>>>>>>>>>
>>>>>>>>> --- In msp430@yahoogroups. com , "shskurkra"
>>>>>>> wrote:
>>>>>>>>>> Designing a project based on LED to ON and OFF based on interrupt
>>>>>>> from momentary switch. Using F2013 kit. I have stuck with soft-start LED ON
>>>>>>> and soft-start LED OFF. Can anyone give some ideas.
>>>>>>>>>> LED switches ON - for interrupt
>>>>>>>>>> LED is in ON state for 1 min and automatically switches OFF. During 1
>>>>>>> minute wait, momentary switch is pressed LED should switch OFF.
>>>>>>>>>> I have gone through sampleEZ codes posted in "Files" section.
>>>>>>>>>> From those I came up with some sort of coding technique.
>>>>>>>>>>
>>>>>>>>>> The best I can think is:-
>>>>>>>>>> 1. Define P1.DIR as output pin.
>>>>>>>>>> 2. connect momentary switch to pin 7.
>>>>>>>>>> 3. write an "if" loop to accept interrupt from pin7 and LED starts to
>>>>>>> switch ON.
>>>>>>>>>> 4. Once LED is switched ON, insert another if loop to receive
>>>>>>> interrupt from momentary switch to turn LED OFF in that 1 minute duration or
>>>>>>> wait for 1 minute to switch LED OFF automatically.
>>>>>>>>>> 5. I have connected N-channel MOSFET to receive output from MSP430 in
>>>>>>> parallel with 10K resistor.
>>>>>>>>>> 6. Supply voltage is connected directly to MSP430.
>>>>>>>>>> 7. LED is connected directly to supply voltage with 100 ohm resistor
>>>>>>> and drain of MOSFET.
>>>>>>>>>> I'm new to MSP430. Using Code composer studio for simulation and
>>>>>>> debug.
>>>>>>>>>> Waiting for your replies.
>>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
Reply by shskurkra May 2, 20102010-05-02
Thank you OCY.

240 hours per day, I got the point; that leads to --> Timer A can have maximum of 65535. So, I should use delay loop for particular delay. For example, 1 minute, 30 seconds ,....
Homomorphism --> I did not figure it out.

One more thing, is my logic correct.
To:-
(1) ON LED at interrupt;
(2) OFF LED at particular time and with interrupt too;

--- In m..., "shskurkra" wrote:
>
> Read datasheet, user guide. Manged to give correct syntax for pin input and output. But, the 16th bit register, and "bool" error still exists. Can anyone give an hint to solve the errors.
>
> The program is:
>
Reply by old_cow_yellow May 2, 20102010-05-02
Correct syntax is necessary but not sufficient. For examples:

(1) Use homomorphism.
(2) Work 240 hours per day.

-- OCY

--- In m..., "shskurkra" wrote:
>
> Read datasheet, user guide. Manged to give correct syntax for pin input and output. But, the 16th bit register, and "bool" error still exists. Can anyone give an hint to solve the errors.
>
> The program is:
>
Reply by shskurkra May 2, 20102010-05-02
Read datasheet, user guide. Manged to give correct syntax for pin input and output. But, the 16th bit register, and "bool" error still exists. Can anyone give an hint to solve the errors.

The program is: