Pages: 1 [2] 3   Go Down
Author Topic: Analog Comparator falling edge setup  (Read 3238 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The comparator(and C10) is essentially there

No.

Quote
Where should the µC know C from?

The meter you are trying to build does not measure ESR: it provides an indication of ESR, in conjunction with a known C.

Quote
Anyhow, can I improve my software solution or do I require two interrupts, without changes to the way the measurement is done?

Yes. This would be what I would do:

1) measure the voltage on the capacitor, V0;
2) charge up the capacitor for a known period of time, Tc;
3) measure the voltage on the capacitor, V1; C = (V1-V0) / (I * Tc);
4) discharge the capacitor for a known period of time, Td;
5) measure the voltage, V2: V2 = V1 * exp (-Td / (ESR * C)), solve for ESR.

Done.

It uses the same hardware.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Somehow I knew that I shouldn't have said what I'm building because there is always someone who just wants to argue instead of helping someone.
Btw, the Meter has been sold tens on thousands of times (as a kit and prebuild) and is still being sold, so the method of "indication" can't be too wrong.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Somewhere I heard, that interrupts aren't allowed within interrupts. Is that true? If the Arduino "remembers" that there was another(different) interrupt during the timer interrupt and executes it afterwards, that would be fine ...

It wouldn't work very well if it could only handle one interrupt source at a time. Yes it will remember interrupt events. The ISR will not be entered until the current one completes, and one more instruction is executed. Then the highest priority outstanding interrupt (if any) will be serviced.

http://www.gammon.com.au/interrupts
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Somewhere I heard, that interrupts aren't allowed within interrupts. Is that true? If the Arduino "remembers" that there was another(different) interrupt during the timer interrupt and executes it afterwards, that would be fine ...

It wouldn't work very well if it could only handle one interrupt source at a time. Yes it will remember interrupt events. The ISR will not be entered until the current one completes, and one more instruction is executed. Then the highest priority outstanding interrupt (if any) will be serviced.

http://www.gammon.com.au/interrupts
Thanks!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have another question on timing inside an interrupt. Currently a
Code:
bitWrite(PORTD, measurementRange, 0);
is just called multiple times inside a timer interrupt to make a pulse with a width of somewhere between 4µs and 15µs(adjustable) because i read here http://jeelabs.org/2010/01/06/pin-io-performance/ that it takes about 1µs to execute a bitWrite(). Is there a better way for such short timings? It doesn't have to be that precise, just the same amount of delay every time once it's set.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could call delayMicroseconds instead, but I'm not sure what the minimum delay you can get with it is.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could call delayMicroseconds instead, but I'm not sure what the minimum delay you can get with it is.
On the Arduino website, it says around 3µs. But can I call it inside a timer interrupt?

Quote
This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times.
« Last Edit: December 11, 2012, 06:13:14 am by daywalkerdha » Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you can call it inside an ISR. However, inside an ISR you should use it only for short delays, because you are lengthening the time it takes to complete the ISR and hence the time before other interrupts can be serviced.
« Last Edit: December 11, 2012, 07:11:30 am by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you can call it inside an ISR. However, inside an ISR you should use it only for short delays, because you are lengthening the tie it takes to complete the ISR and hence the time before other interrupts can be serviced.
Ok, thanks! The interrupt will be executed every 500µs and inside it will only be one delayMicroseconds() of around 10µs and the whole routine should take no longer than 15µs, including the delay.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can do the whole thing with PWM. In my project of making VGA output I needed both vertical and horizontal sync pulses. It sounds similar to what you are doing. You need the pulses a certain width apart, and with a short pulse time. Project page:

http://www.gammon.com.au/forum/?id=11608

Example screenshot:



In that case I had a 4 uS pulse with a 32 uS period. Those figures can be changed by the timer configuration values. This doesn't rely on ISRs at all (for the pulses) since the timer does that.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can do the whole thing with PWM.

Yes, but I need to switch the pulse between three pins to change the range for my measurement. That would only be possible with software PWM, right?
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can do the whole thing with PWM.

Yes, but I need to switch the pulse between three pins to change the range for my measurement. That would only be possible with software PWM, right?

You have 3 timers on an Arduino Uno, one 16-bit and two 8-bit. So if 8-bit timers are adequate to get the frequency and pulse width resolution your require, you can use timers to generate pulses on 3 pins. However, timer 0 is normally used to count microseconds. So, when you are using timer 0 to generate pulses, you will need to switch the timekeeping function to timer 2. Alternatively, use a Mega, which has more timers.

Alternatively, use a single timer with external gating.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've now looked at the ESR meter article. The circuit does look rather complicated. It was designed in the late 1990s and is suited to the technology of the time. Essentially, it feeds pulses of a known current to the capacitor under test, discharging the capacitor more or less fully between pulses. It is assumed that the capacitor does not charge significantly, because the pulse is short and the capacitor under test is assumed to have high capacitance. It measures the pulse amplitude by amplifying it and comparing it with a ramping voltage.

I am concerned that the atmega328p datasheet provides (as far as I can tell) no data on the speed of the analog comparator, so there is no telling whether it is fast enough for this application.

An alternative would be to use the ADC to read the pulse amplitude directly. The ADC sample and hold takes nominally 1.5 ADC clock cycles. The default Arduino ADC clock is 125kHz, so this is 12us, plus an 8us uncertainty about when the sample is taken. If you increase the ADC clock frequency to 250KHz, you halve this time to 10uS total at the expense of slightly reduced accuracy. So if you write the start conversion command to the ADC and then immediately start the pulse, then if the pulse is at least 10us long you should be able to read its amplitude through the ADC.

Another option is to use a faster external A to D converter, or an external sample and hold circuit. Either way, you don't need the ramp[ generator circuit.

If you do decide to use the comparator (or an external comparator), then consider using a DtoA converter to generate the ramp instead of several transistors and resistors and a capacitor.

Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the output from less than 10 lines of code, measuring a 100uf capacitor with a 10ohm ESR.

Code:
esr = 9969mOhm
esr = 10000mOhm
esr = 10030mOhm
esr = 10060mOhm
esr = 9755mOhm
esr = 9785mOhm
esr = 9815mOhm
esr = 9845mOhm
esr = 9876mOhm
esr = 9906mOhm
esr = 9937mOhm
esr = 10312mOhm
esr = 10344mOhm
esr = 10020mOhm
esr = 10052mOhm
esr = 10084mOhm
esr = 10116mOhm
esr = 10137mOhm
esr = 10170mOhm
esr = 10202mOhm
esr = 10588mOhm
esr = 10257mOhm
esr = 10290mOhm
esr = 10679mOhm
esr = 10345mOhm
esr = 10379mOhm
esr = 10402mOhm
esr = 10436mOhm
esr = 10470mOhm
esr = 10493mOhm
esr = 10528mOhm
esr = 10551mOhm
esr = 10586mOhm
esr = 10609mOhm
esr = 10645mOhm
esr = 10668mOhm
esr = 10324mOhm
esr = 10728mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10728mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm
esr = 10347mOhm

Display in mOhm.

All it takes is a digital pin, an analog pin, and a 330ohm resistor (user defined in the code).

Plus a few lines of code on an arduino.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you going to reveal what those < 10 lines of code are?
Logged

Pages: 1 [2] 3   Go Up
Jump to: