Need clarification - HCS12 - analog comparator

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

Need clarification - HCS12 - analog comparator

961 Views
puppetmaster
Contributor II

Hi,

 

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...

 

Thanks!

Labels (1)
0 Kudos
8 Replies

641 Views
kef
Specialist I

A lot of words, but still not clear what's the problem. Do you mean comparator is working fine until you disable ATD? If so, then you should make service request for this. See support->etc..

0 Kudos

641 Views
puppetmaster
Contributor II

Hi!

 

Ok?! I thought I made everything clear... :smileyfrustrated:

 

I don't disable the ATD at all... I just don't measure anything once the comparator gives me an interrupt for "low voltage detected" (which is "rising edge" due to our circuit)... then I wait patiently for the next interrupt to come (which is "falling edge" in this case)...

 

1. When an ACMP interrupt occurs I switch the detection: falling to rising / rising to falling

2. I can see the register toggeling via debugger and memory map observation; so this works

3. I see the edges coming with the oscilloscope, so the comparator is working too

 

BUT the MCU does not detect the edges as long as I don't use the regular ATD functions in the meantime... and this is what I don't get at all.

 

I highlighted "regular ATD functions" as I do ONE special conversion (measure Vref) each cycle during that low voltage time, but that does not affect this strange behaviour at all.

 

To make long things short:

 

IF I continue (and this is not what we want) to trigger the ATD each cycle during low voltage then the ACMP IRQ-requests come in

IF I don't do this then the ACMP IRQ-requests are not detected or come in randomly

 

 

0 Kudos

641 Views
kef
Specialist I

It's interesting, but unfortunately I don't have S12G at hand to try it. Hope you made service request already.

0 Kudos

641 Views
kef
Specialist I

BTW, isn't it that comparator pulses are too narrow for your interrupt latency, so that you are late clearing comparator interrupt flag?

0 Kudos

641 Views
puppetmaster
Contributor II

Hi,

sorry for the late reply. Due to the board change, my subscriptions seem to have been deleted. :smileyconfused:

As for the comparator pulses; for the tests I trigger them "manually". The voltage source for the whole circuit can be regulated. So I lower the voltage towards to the trigger level... wait for the comparator to trigger... wait a bit and raise the voltage level and see it trigger again...  (as said its purpose is an undervoltage detection of the input voltage)

My code isn't that big either:

__interrupt void  Isr_VACompIrqHandler( void ) {
    const DeviceComparatorEdgeDetectionEnum currentEdgeMode = DeviceComparator_CurrentEdgeMode();

    /* set flag */
    DeviceComparator_SetUndervoltageFlag( (DEV_COMPARATOR_EDGE_MODE_RISING == currentEdgeMode) );   
    /* toggle mode */
    if ( DEV_COMPARATOR_EDGE_MODE_RISING == currentEdgeMode ) {
        DeviceComparator_SetEdgeMode( DEV_COMPARATOR_EDGE_MODE_FALLING );
    } else {
        DeviceComparator_SetEdgeMode( DEV_COMPARATOR_EDGE_MODE_RISING );
    }

    ACMPS |= ACMPS_ACIF_MASK; 
}

As for being "too narrow", with the hand method I should have left enough of room (aka time) IMHO. The flags set will be evaluated in later parts of the software, so the interrupt latency should be pretty short. All functions used here are located in the near segment.

I haven't filed a suppport request yet as I want to be more or less sure that I didn't do anything particular wrong here.

0 Kudos

641 Views
kef
Specialist I

Are you sure comparator interrupt isn't called any more? Did you set breakpoint at interrupt routine ant it is not triggered?

If you don't modify any ATD/ACMP registers when you "stop ATD operations", then comparator and its interrupt should keep working.

0 Kudos

641 Views
puppetmaster
Contributor II

Yes, I set a breakpoint and at the same time I was observing the COMP-Out via the oscilloscope. The COMP-Out toggled, but the interrupt was not called.

As stated: the only thing I'm doing is switching the ATD to special mode and measure the internal Vref during that time which does not prevent the ACMP from working correctly (except of the missing interrupt).

Currently I'm in the process of re-ordering the execution order in the software, I hope that helps otherwise I'm really out of clues...

0 Kudos

641 Views
kef
Specialist I

I still think you should make service request for this.  New Service Request .

If no regs are modified and no interrupts are triggered, then it must be some odd hardware problem.

Did you stop MCU once before or after you set breakpoint at ACMP ISR? It should be done just to make sure that debugger set up breakpoint registers properly. Sometimes with some MCUs I see breakpoints not enabled until I stop and make MCU running again. If this is checked, then you could also verify that ACMP registers still are set up properly and ACMP interrupt is enabled. If this is also OK, then most liketly it's HW.

0 Kudos