9S08qg4 STOP mode 3 question

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

9S08qg4 STOP mode 3 question

2,652 Views
rick_l
Contributor I

I'm new to this and stymied.    I am using a USBSPYDER08 to develop code. 

I set the STOPE bit and when I execute a STOP instruction it just seems to ignore it (if I set a breakpoint for the instruction after STOP it encounters it).  If I just run the program (green arrow no breakpoints) it just goes merrily on its way.

This thread says when in background debug mode the stop instruction is ignored.  Is that true?  I havent tried the progam in its non-debug environment.

 
On the off chance I figure this out, the manual says asynchronous interrupt (I want to use KBI) will result in the MCU taking the appropriate interrupt vector.   What does it do on the RTI?   The instruction after STOP perhaps?
Labels (1)
0 Kudos
6 Replies

633 Views
RickN
Contributor I
Hi Rickl,
 
    Debugging your Stop mode code can be tricky, as you have found out because the BDM is not too useful.   An ammeter connected to VDD is often the best way to work with Stop modes.  You basically figure out the expected current draw (Idd) for your setup, write & run your code, and measure Idd to make sure they match up.   I suggest starting off with static tests that initialize the MCU and just put it directly into the desired Stop mode.  Make sure you disconnect the BDM when you are taking current measurements.  I haven't worked with the Spyder08, so this may not be easy.  Maybe bend the VDD pin up on the MCU to make the ammeter connection, if possible.
 
   I haven't tried going into Stop mode from an ISR, but it sounds like it should be possible.   I have seen that you usually do some work then hit the Stop instruction.  You then wait for an event to wake you up from Stop mode, and do some more work.  An ISR is sometimes used to wake you up from certain Stop modes on a periodic basis. 
 
   Getting into the Stop mode is the first problem you face, then getting out of Stop mode is the next step.  The 9S08QG Data Sheet is the best source of information for you with respect to understanding Stop modes.  I suggest you spend some time looking through the information in the Data Sheet, because it will actually save you some time when working with the Stop modes.  
 
   Lastly watch out for the write once bits in the system configuration registers.  This can be tricky, as you really end up with a write once byte.   If you post the appropriate sections of your code, I can look for the typical problems.  Start off with simple tests that use an blinking LED or GPIO when working with Stop modes.
 
   Thanks,
 
      Rick
0 Kudos

633 Views
bigmac
Specialist III
Hello Rick and Rick,
 
A good reason not to put a STOP instruction within an ISR is because this instruction will automatically clear the I-bit within CCR, so as to enable interrupts.  Within an ISR, this may prove problematic upon exit from STOP mode, because it would allow nested interrupts in an uncontrolled manner.
 
In fact, if the interrupt in question was also the source of the wake-up, it would seem the ISR would continue to nest with each wake-up, and never exit.  With each execution of the ISR, a new STOP instruction would be encountered prior to continuing beyond the previous STOP.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-02-24 02:26 AM
0 Kudos

633 Views
JimDon
Senior Contributor III
Just to reinforce the points made - you do NOT what to do a STOP in an ISR handler. What mac said is correct, you will end up nesting and crashing the stack. This could be hard to debug as it will work x number of times then die or just reset. If it resets, you may not even notice it, until you add application code.

What Rick was saying about measuring the current is that you want to measure ONLY the current flowing into the MCU, not the current draw of the board. This could be tricky, as there might be multiple power pins on the mcu, so just lifting a pin may not prove to be effective. Some demo boards have a jumper just for this purpose. Also, if you are sourcing current to loads, this will be coming from the MCU.



0 Kudos

633 Views
rick_l
Contributor I
I think think I got it to work but I don't know why. 
 
If I have the STOP inside the MTIM interrupt routine it doesn't seem to work.  If I put it in main it does.  Does this make sense?
0 Kudos

633 Views
RickN
Contributor I
Hi,
 
   Can you post your code please?  There are a couple of tricky spots for putting the QG8 into sleep mode.  Posting the code will help narrow the field.
 
   Thanks,
 
    Rick
0 Kudos

633 Views
JimDon
Senior Contributor III
As for the comment concerning STOP and the BDM these are observations, and they make sense as the BDM does not fully function in STOP mode.


AN2493:
Exit from stop3 can be less intrusive than the exits of stop1 and stop2. If an interrupt source such as IRQ, KBI, or RTI is used to exit stop3, the MCU services the interrupt and then continues operation at the instruction that follows the stop instruction. It is not necessary to initialize peripherals after exiting stop3. Stop3 can also be exited by asserting the RESET pin. In this case the MCU will fetch the reset vector and registers and peripherals will be placed in their reset state.


Message Edited by JimDon on 2008-02-22 01:19 PM
0 Kudos