EmbeddedRelated.com
Forums

bug on code ?!?!

Started by edson burgo August 4, 2008
I'm working with msp430F2013 making a code, i'm using IAR Workbench to make
and debug the code.

Part of this code consist in a delayer implement, and i used watchdog to
make this
Basically i used the RTI to increment a variable and test this variable in
main code, when the test is true things would be done.

The problem:
I monitored the debug step by step and monitored the value of the variable
incremented in RTI, even the variable being the same in condition of the
test the code don't enter in wich condition. (the test should be true, but
the program don't consider that).
The program never enter in condition of the *if*, even when is true. And i
can't make the "things" in RTI, i need make out of RTI.

Thanks for all help.

Edson Burgo

here is the code:

> *// testando temporizador
>
> #include
> #include
> #include
> int cont_8_seg=0;
> void config_portas (void);
> void config_wdt (void);
>
> #pragma vector=WDT_VECTOR
> __interrupt void watchdog_timer (void)
> {
> cont_8_seg ++;
> }
>
> void config_portas (void)
> {
> P1DIR |= 0xFF; // P1 inteira como saa ---->
> MUDAR__TESTANDO <--
> }
>
> void config_wdt (void)
> {
> BCSCTL1 |= DIVA_3;
> WDTCTL = WDTPW + WDTTMSEL + WDTSSEL;
> IE1 = WDTIE;
> }
> void main (void)
> {
> config_portas ();
> config_wdt ();
> __low_power_mode_3();
> while(1)
> {
> if(cont_8_seg == 1)
> {
> P1OUT ^= 1;
> cont_8_seg = 0;
> }
> } *

*}*
>

Beginning Microcontrollers with the MSP430

Hi Edson, you need to wake up from lpm3 on exit of the interrupt. Your
code now simply increments the variable, but doesn't wake up to test it.

in this case I would place the test inside the interrupt routine, and
only wake up when the value matches.

The exit LPM3 instruction will vary with your compiler.

If this is not a simple test code, and the tst value 1 is not just for
est purposes there are better ways to do this of course. The count of 1
is superfluous, you could simply exit sleep mode on occurence of the WDT
interrupt.

Al

#pragma vector=WDT_VECTOR
> __interrupt void watchdog_timer (void)
> {
> cont_8_seg ++;

if(cont_8_seg == 1)
> {
> _exit_low_power mode_3();
> > }
}
>
void main (void)
> {
> while(1)
> {
> config_portas ();
> config_wdt ();
> __low_power_mode_3();
P1OUT ^= 1;
> cont_8_seg = 0;
}
}
>
>

edson burgo wrote:

>I'm working with msp430F2013 making a code, i'm using IAR Workbench to make
>and debug the code.
>
>Part of this code consist in a delayer implement, and i used watchdog to
>make this
>Basically i used the RTI to increment a variable and test this variable in
>main code, when the test is true things would be done.
>
>The problem:
>I monitored the debug step by step and monitored the value of the variable
>incremented in RTI, even the variable being the same in condition of the
>test the code don't enter in wich condition. (the test should be true, but
>the program don't consider that).
>The program never enter in condition of the *if*, even when is true. And i
>can't make the "things" in RTI, i need make out of RTI.
>
>Thanks for all help.
>
>Edson Burgo
>
>here is the code:
>
>
>
>>*// testando temporizador
>>
>>#include
>>#include
>>#include
>>int cont_8_seg=0;
>>void config_portas (void);
>>void config_wdt (void);
>>
>>#pragma vector=WDT_VECTOR
>>__interrupt void watchdog_timer (void)
>>{
>> cont_8_seg ++;
>>}
>>
>>void config_portas (void)
>>{
>> P1DIR |= 0xFF; // P1 inteira como saa ---->
>>MUDAR__TESTANDO <--
>>}
>>
>>void config_wdt (void)
>>{
>> BCSCTL1 |= DIVA_3;
>> WDTCTL = WDTPW + WDTTMSEL + WDTSSEL;
>> IE1 = WDTIE;
>>}
>>void main (void)
>>{
>> config_portas ();
>> config_wdt ();
>> __low_power_mode_3();
>> while(1)
>> {
>> if(cont_8_seg == 1)
>> {
>> P1OUT ^= 1;
>> cont_8_seg = 0;
>> }
>> } *
>>
>>*}*
>
>
>
>
The major problem is, once the main() enters LPM3, it cannot get out.
It will wake up to handle the interrupt routine, but when the
interrupt routine is finished, the CPU will go back to LPM3. The
entire while() loop (including the if statement) is never executed.

Delete the line: "__low_power_mode_3();"
And the code will run correctly.

But do you have an ACLK? If not, WDT will take a very very very long
time to generate an interrupt.

--- In m..., "edson burgo" wrote:
>
> I'm working with msp430F2013 making a code, i'm using IAR Workbench
to make
> and debug the code.
>
> Part of this code consist in a delayer implement, and i used watchdog to
> make this
> Basically i used the RTI to increment a variable and test this
variable in
> main code, when the test is true things would be done.
>
> The problem:
> I monitored the debug step by step and monitored the value of the
variable
> incremented in RTI, even the variable being the same in condition of the
> test the code don't enter in wich condition. (the test should be
true, but
> the program don't consider that).
> The program never enter in condition of the *if*, even when is true.
And i
> can't make the "things" in RTI, i need make out of RTI.
>
> Thanks for all help.
>
> Edson Burgo
>
>
>
> here is the code:
>
> > *// testando temporizador
> >
> > #include
> > #include
> > #include
> > int cont_8_seg=0;
> > void config_portas (void);
> > void config_wdt (void);
> >
> >
> >
> > #pragma vector=WDT_VECTOR
> > __interrupt void watchdog_timer (void)
> > {
> > cont_8_seg ++;
> > }
> >
> >
> >
> > void config_portas (void)
> > {
> > P1DIR |= 0xFF; // P1 inteira como saa ---->
> > MUDAR__TESTANDO <--
> > }
> >
> >
> >
> > void config_wdt (void)
> > {
> > BCSCTL1 |= DIVA_3;
> > WDTCTL = WDTPW + WDTTMSEL + WDTSSEL;
> > IE1 = WDTIE;
> > }
> >
> >
> >
> >
> > void main (void)
> > {
> > config_portas ();
> > config_wdt ();
> > __low_power_mode_3();
> >
> >
> > while(1)
> > {
> > if(cont_8_seg == 1)
> > {
> > P1OUT ^= 1;
> > cont_8_seg = 0;
> > }
> > } *
>
> *}*
> >
>
>
>
>

Thanks for spend your time to help me
This is an example and the test to code. The code that i'm making need
increment that variable 8 times to after call a routine.
I realy need use lpm3 and i can't delete that line, i have an ACLK.

Tahnk you so much for all help.

Edson.

Your lpm3 is totally in the wrong place, as I pointed out in my reply.
It doesn't matter how many times you need to count the variable. There
still has to be a low power exit instruction in the interrupt handler.
You need to read the manual on exit from low power modes, as well as
read old posts here.

Al

edson burgo wrote:

>Thanks for spend your time to help me
>This is an example and the test to code. The code that i'm making need
>increment that variable 8 times to after call a routine.
>I realy need use lpm3 and i can't delete that line, i have an ACLK.
>
>Tahnk you so much for all help.
>
>Edson.
>
>
Sorry.
I didn't say that i changed my code that you said. You help with that you
said and i'm thank very much.
I said something about the number of increments of the variable because you
said that was superfluos, but i need it.

Thank you very much and sorry.

Edson

In the code snippet you posted to the group the variable was
superfluous. I posed the question that if it were only needed to count
to one then it could be discarded. If you seek answers to problems you
should perhaps define them better, or post more representative code. The
simple point of this is thyat your while loo[p structure is wrong, the
interrupt handler never exits sleep mode, and your whole program as
presented could exist within the intyerrupt handler without in fact
needing to wake up, irrespective of the number of counts needed for the
variable.

Al

edson burgo wrote:

>Sorry.
>I didn't say that i changed my code that you said. You help with that you
>said and i'm thank very much.
>I said something about the number of increments of the variable because you
>said that was superfluos, but i need it.
>
>Thank you very much and sorry.
>
>Edson
>
>
I'm thanking for you. You HELPED ME.
I think that i define good enough because you solve the problem.
The problem was in sleep mode and this is solved. (and now i understand of
sleep mode)
I didn't exposed my complete code because i thought that isn't necessary.

Thank you for help, my code is right now.

Edson

Hi Edson. The simple fact is that when you ask for help it is much
easier for us to help you, if you explain more and give as much
information as possible. The fact that you have a problme should tell
you that you don't know enough to realise what information can be left out.

Anyway I'm glad I was able to help, this too is intended to help in the
future.

Al

edson burgo wrote:

>I'm thanking for you. You HELPED ME.
>I think that i define good enough because you solve the problem.
>The problem was in sleep mode and this is solved. (and now i understand of
>sleep mode)
>I didn't exposed my complete code because i thought that isn't necessary.
>
>Thank you for help, my code is right now.
>
>Edson
>
>