How to get Analog Comparator to ignore a short initial spike

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a signal that is going to the analog comparator. The CPU (M328p) is running on the internal 8MHz clock at 8MHz. The signal has a brief spike of 0.2 to 0.4uS followed by a 7-8uS plateau. I need to measure the plateau, but ignore the initial spike. The uC creates the pulse, and there is a little propagation delay after that. So, I know when the pulse is coming. Is there some way to turn on the AC 1-4uS after the spike is generated, so it will sample only the plateau? Adding low pass filtering to the external hardware may be hard to do with excessive impact on the measured signal.

-Tony

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, for instance, keep AC interrupt disabled, send pulse, delay enough, clear any pending AC interrupt flags, enable AC interrupt?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jepael wrote:
Well, for instance, keep AC interrupt disabled, send pulse, delay enough, clear any pending AC interrupt flags, enable AC interrupt?

That may work. I flip a pin, delay 8uS, then unflip a pin to create the pulse.

I probably could flip the pin, delay 2uS, clear the int flag, enable AC interrupt, delay 6uS, unflip the pin, then disable the AC interrupt

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I need to measure the plateau,

The width?

Remember that the analog comparator can be routed to the ICP. Even at a sedate 8MHz a skinny ISR should be able to grab the "rising" edge counts, and then the next trip for the "falling" edge can be more leisurely.

But tell more about this measurement: If the spike is 7-8us then what are you trying to measure? 1) At 8MHz one clock cycle is 125ns so at best you have only 8 or 10 possible outcomes. 2) The internal oscillator is not going to be very accurate. So if I wanted to measure this pulse width I'd use a faster crystal. At 20MHz you get 50 possible outcomes per microsecond. If an "important" app I'd perhaps look to see if e.g. an Xmega had better facilities.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, not the pulse width, I want to compare the plateau voltage to a reference voltage but not get confused by the initial spike. The problem is that I enabled the AC interrupt flag on the rising edge. I think that to do the delay I need to just check the AC output, not the flag then set my own flag instead. This also allows measurement at any arbitrary point in the plateau which may be useful!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm still confused about what you are "measuring". Are you doing repeated cycles varying the reference voltage?

Lessee--if there is enough drive in the signal, can you use the ADC? At 200kHz ADC clock one ADC clock is 5us. The sample-and-hold is the second clock IIRC. Pretty close to your needs, but perhaps a 400-500kHz ADC clock might be better. Now, what trigger sources do we have for the ADC on that little beastie? Yep, a conversion can be started based on an Analog Comparator trip.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Spamiam wrote:
No, not the pulse width, I want to compare the plateau voltage to a reference voltage but not get confused by the initial spike. The problem is that I enabled the AC interrupt flag on the rising edge. I think that to do the delay I need to just check the AC output, not the flag then set my own flag instead. This also allows measurement at any arbitrary point in the plateau which may be useful!

Hmm, then trigger an AC interupt on the spike rising edge. In the interrupt, start a timer to trigger after the time you want (or use input capture feature) and disable further AC interrupts. In the timer interrupt, read plateau voltage, stop timer and enable AC interrupts.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
I'm still confused about what you are "measuring". Are you doing repeated cycles varying the reference voltage?

Yes, that is correct, I am trying to measure the voltage of the plateau of the pulse by varying the reference voltage.

The reference increases at 20mV/mS. pulses are at 2KHz, I count the number of pulses detected. Comparator transitions start when the reference voltage reaches the lower voltage range of the pulses, and stop when the ref exceeds the peak of the pulses. The number of high transistions counted multiplied by 10mV = the low-to-high voltage of the pulse.

I think I do not need to add complexity of using the ADC at this point since I have the reference voltage ready to go. In the design phase, I guess I could have put the pulse on an ADC channel and directly measured the voltage, but I was worried about settling time, and propagation delays interfering with accurate measurement.