Kirk Humphries


Discussion created by Kirk Humphries Employee on Jan 26, 2006

This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.


Posted: Mon Dec 19, 2005  3:55 pm


Hello all,

I have some problems with the ATD.


I'm programming on the Metrowerks IDE, and I'm trying to input an ATD input but something goes wrong...


If someone can give me the typical configuration for the registers it would be great. Secondly, I would like to put the controller in a wait mode in order to consume less power, when it does nothing. How do I do so, and how do I return from the wait mode to the normal mode.


Thanks a bunch,



Date: Tue Jan 3, 2006  11:05 am


Entering low power mode can be tricky. What you need to look out for is the scenario where an interrupt happens right before the wait instruction. In that scenario, the system handles the interrupt and then goes into wait. This can be a serious problem if that interrupt was meant to wake the system. Follow these steps to prevent that scenario:


Firstly disable all interrupts:


asm SEI;


Then setup whatever it is you want to have wake you up (such as key wakeup, SCI, RTI interrupts etc). If you are getting woken by the timer or the RTI make sure the timer/RTI is setup to keep ticking in wait mode.


Then execute these two commands in this order (without any commands in between):


asm CLI; // enable interrupts

asm WAI; // enter wait mode


HC(S)12 will guarantee that the command after the CLI gets executed before any interrupts happen, preventing the system from going into wait if an interrupt comes right as you execte the CLI.


Entering stop mode is done in a near identical fashion. Instead of asm WAI, use asm STOP. Just remember that all the conditions that wake the CPU from wait will not wake it from stop (such as SCI).


Hope this helps,