AnsweredAssumed Answered

Need clarification - HCS12 - analog comparator

Question asked by puppetmaster on Aug 28, 2012
Latest reply on Sep 13, 2012 by kef



I've have a strange "problem", at least I classify it as a problem until someone tells me that is normal. Though I might have set up some registers wrong, but I'm not sure.


We use a S12G64 - MCU. This particular problem only affects the ATD-functionality.


Connected to the ATD are eight analog signals (on AN0-AN7) which need to be measured in a 10ms cycle. Works fine.

We decided to use the ACMPP and ACMPM  which are connected to AN10 and AN11. For debugging purposes we set up ACMPO (AN9) to output the comparison results.


ACMPP and ACMPM are connected to a voltage divider attached to the voltage source and a reference voltage to detect undervoltage. In this set up this event happens if a rising edge is detected.


The particular program flow is as follows:



Setup ATD: eight channels, AN0-AN7 with wrap around, 500 kHz

Setup ACMP: using interrupts, using ACMPO, initial rising edge detection (buffered input or unbuffered input, does NOT affect the described behavior)

ACMP-ISR: manually toggeling from rising to falling and vice versa. setting a "undervoltage detected"-flag, depending on the current setting of the ACMP-edge-detection register directly after entering the ISR.


On normal voltage levels:


Cyclic measurement of internal Vref (ATD special conversion @ 2MHz)

Cyclic measurement of ATD input channel (@500 kHz)


When detecting undervoltage:


STOP measuring the ATD channels


And here comes the problem!


If I stop the operations on the ATD then the analog comparator WON'T detect the edge anymore (or just randomly)! Even though I still continue to measure the internal Vref with special conversion. I can monitor the ACMPO via an oscilloscope and the edges are coming in just fine; even in the debugger I can see the ACMPO-bit toggeling.


However, if I measure anything with the ATD in normal operation mode then the edge detection works like a charm.


So, is this the normal behavior for the ACMP or is there a configuration bit that I'm missing?!


If possible we really would like to stop measuring with the ATD at all (except the internal Vref) during this undervoltage situation... Ah, I don't set up any port directions at all, as I assume the ATD/ACMP does this for me (which it seems to do, as I can measure without problems). Though it's stated in the manual as follows: "If a peripheral module controls the pin the contents of the data direction register is ignored". Therefore this can't be a problem here...