I´m measuring a voltage on a circuit with a certain voltage reader and I want to give this value to the Arduino Board.
Then the sketch uploaded on the Arduino should be capable to compute a time derivative of this quantity. Is it possible on Arduino? If yes, how can I do that?
previousTime = time; // Save the time of the previous cycle
time = millis();
float interval = time - previousTime; // Calculate the time it takes to run a cycle
voltage_derivative = ( voltage - previous_voltage ) / interval;
I thought there was a command but this seems the only way to do a derivative on Arduino
f.schiano:
I don´t know it yet. I know that I will have a number that is proportional to the voltage on my load of interest.
Measuring such a high voltage is going to be very difficult on an arduino, you can not use the normal potential divider method. Also the 10 bit resoloution means that the resoloution at this voltage will be very poor. What sort of resoloution do you need?
I don´t want to measure the voltage through the Arduino.
On the Arduino I just want to implement a simple controller that has to switch on and off 2 switches that are on the circuit. So the Arduino will be aware only of a number that is computed by some kind of measurement instrument that will give to Arduino just a number , The VOLTAGE.
I don´t want to measure the voltage through the Arduino.
Sorry but that is what your initial question implied. So how is this voltage reading getting into the arduino and what is it switching?
It sound like it is simple again.
I´m working on a High Voltage circuit, at the end of this circuit there is a load resistance and the voltage on this resistance will be measured in some way (I don´t know how it will be measured because it´s not my job, but I know that I will have available a signal proportional to the voltage applied to the LOAD resistance).
I want to take this voltage into an Arduino Analog Pin and do a derivative of it.
A little clearer, but just saying "a signal" isn't much help.
It could be a pulse width proportional to voltage, it could be a frequency proportional to voltage, it could be another analogue voltage, an ASCII stream specifying the voltage to 'n' decimal places...
Aside from the high voltages and signal processing to interface with the uC what you are proposing is just sooo easy!
Its basic math operations, derivative in its most simple form is
distance up/distance along which is great for straight lines but you most likely have a sinusoid so the time interval needs to be as small as possible so the sinusoid approximates a straight line in order to maintain accuracy
If you know enough about the sampled waveform then there is
Sin'(wt)=w*Cos(wt);
Use power series maybe but I would go for the straight line approximation
(Volts new-volts old)/(time new - time old)
Use an interrupt to sample and then you know the time difference everytime so its down to three steps
Samplenew
Samplenew-Sample old
Divide by interrupt time
The derivative is for "continuous signals" but the Arduuino uses "discrete signals". An approximation of a derivative can be calculated using discrete values by calculating the slope of the signal. If the signal is slow the approximation will be accurate, within a tolerance level that you will define. A slow signal with 1000 hz frequency components can be sampled by the ADC analog to digital converter. Then the slope for each pair of values (y1 y2) can be used as a first order approximation.
slope dy/dt
dy = y2-y1
dt = t2-t1
the slope is an approximation for the derivative.
Ref. : Issac Newton. The derivative is made accurate by reducing the sizes of dt and dy until they are vanishingly small.
f.schiano:
No the voltage is a High Voltage (order of 4KV).
I was thinking to something like that:
previousTime = time; // Save the time of the previous cycle
time = millis();
float interval = time - previousTime; // Calculate the time it takes to run a cycle
voltage_derivative = ( voltage - previous_voltage ) / interval;
I thought there was a command but this seems the only way to do a derivative on Arduino :)
Yes, you can calculate the average derivative during the interval between the two readings like that. However, it's better to use micros instead of millis for the timing, it has much greater resolution and it increments uniformly (unlike millis, which increments by 2 sometimes).
Grumpy_Mike:
Measuring such a high voltage is going to be very difficult on an arduino, you can not use the normal potential divider method.
Whyever not? There are additional considerations, like using a high voltage resistor for the upper resistor, or a string of normal resistors in series (because of the inadequate voltage rating of standard resistors); and the power dissipation in the voltage divider may be substantial unless you design it for very low current; and the high voltage source must be capable of delivering that current/power. But the basic principle is still valid.
[I've been there before - many years ago, I used to work with 0-20kV laser power supplies.]
What is the source of the 4kV voltage you are measuring? How fast will it be changing?
Mike mentioned that the 10-bit resolution of the ADC may be insufficient. To expand on this, suppose the voltage changes by 1% of the ADC range during the interval. Then the actual change in reading is only about 10, and the resolution (and hence limiting accuracy) of your computed derivative is only 1 part in 10.
The simplest filter is probably a 1st-order low pass filter made by connecting a capacitor in parallel with the lower resistor of the potential divider (there are other reasons why a capacitor here is a good idea anyway). If that isn't sufficient, then I suggest you implement an additional filter in software.
Well, the source of the Voltage is a Dielectric Elastomer, and in practice it acts like a variable capacitor and I want to decide when discharge it on the LOAD through the controller (that I´m designing) of some switches.
I don´t know yet how the voltage will change in the real world, but I can ask, have some data and then I will be here again.
Thanks a lot.
If you have more advices I will listen at everything.
f.schiano:
Well, the source of the Voltage is a Dielectric Elastomer, and in practice it acts like a variable capacitor and I want to decide when discharge it on the LOAD through the controller (that I´m designing) of some switches.
Then the connection of a potential divider across the device to allow the voltage to be measured will discharge it, at a rate inversely proportional to the resistance of the potential divider. Mike was right, you have a potential problem measuring the voltage.