Hi, I want to measure a pulsating DC voltage. The voltage pulsates slowly and constantly varies its level and speed. for calibration I would like to capture the Mninimum tips. Can anyone offer some help? I´d like only detect these minimum peaks constantly.
Note: The voltage is read by A0 (Mega2560)
Thanks in advance....
I´d like only detect these minimum peaks constantly.
That's a little baffling. What information are you expecting to collect? i.e. in your example waveform, what would be the output from the arduino?
Would this work?
UIR = analogRead(A0);
if (UIR < lowestUIR) { lowestUIR = UIR;}
I will have to try. But how do I save my measurements and it detected my minimum voltage and compare it with the lowest UIR?
Thanks for this tip!
here my new code. But it doesnt work. DAC only incements up, when the voltage is to low. But the DAC doesnt decrment , if lowest voltage ist higher my level.
#include <AH_MCP4922.h>
#include <MsTimer2.h>int IR= 0;
int j=0;
int i =10;
int UIR = 0;
int lowest_UIR=11; // min Level UIR
int UR = 0;
int lowest_UR=11; // min Level URAH_MCP4922 AnalogOutput1(51,52,53,LOW,HIGH); //define AnalogOutput1 for MEGA_board, select DAC_A, Gain=1x
AH_MCP4922 AnalogOutput2(51,52,53,HIGH,LOW);
volatile byte counter = 0;void setup()
{
pinMode(A0,INPUT);
pinMode(A1,INPUT);
AnalogOutput1.setValue(i);
AnalogOutput2.setValue(j);
initTimer2();}
void loop()
{
}
ISR(TIMER2_COMPA_vect) { // ISR for read every 10 ms
counter = (counter + 1) % 2;
switch(counter) {case 0:
UR = analogRead(A1); // read A1 make DAC high if UR smaller 11
if( UR <=11){
j++;
}
AnalogOutput2.setValue(j);
UR = analogRead(A1); // read A1 , make DAC loower if UR_lowest voltage ist higher Level 11
if (UR < lowest_UR) {
lowest_UR = UR;
}
if (lowest_UR>11){
j--;
}
AnalogOutput2.setValue(j);break;
case 1:
UIR = analogRead(A0); // read A0 make DAC high if UIR smaller 11
if ( UIR <=10){
i++;
}
AnalogOutput1.setValue(i);UIR = analogRead(A0); // read A0 , make DAC loower if UIR_lowest voltage ist higher Level 11
if (UIR < lowest_UIR) {
lowest_UIR = UIR;
}
if (lowest_UIR>11){
i--;
}
AnalogOutput1.setValue(i);}
}
void initTimer2()
{
// Timer 2 CTC mode, prescaler 1024
TCCR2B = (1<<CS22) | (1<<CS21)| (1<<CS20);
TCCR2A = (1<<WGM21);
OCR2A = 155;
// enable Timer 2 interrupts
TIMSK2 = (1<<OCIE2A);
}