I'm trying to measure the mark or space of an incoming pulse. No mater what I do I'm only seeing the period. I can not see the high or low width. I poked around in the library and it looks like LC can do mark and space calculation.
Thanks Ryan
Thanks Ryan
Code:
// PWM to anaolg out Use DAC output.
// expect 78 hz input, zero to 100% duy. 0.012820 ms.
#include <FreqMeasureMulti.h>
FreqMeasureMulti pwm_in; // pin 6
IntervalTimer myTimer;
unsigned long mark;
unsigned int val;
void setup() {
//pinMode(6, INPUT_PULLUP);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
pwm_in.begin(6, FREQMEASUREMULTI_MARK_ONLY);// Grab mark time. Sort duty.
myTimer.begin(serout, 250000); //do serial out every 0.25 sec (4 hz).
analogWriteResolution(12);
}
void loop() {
if (pwm_in.available()){
unsigned long a = pwm_in.read();
mark = pwm_in.countToNanoseconds(a);// micro sec res.
val = mark / 3130;
//DAC 0 to 4095 range.
analogWrite(A12, val);
}
}
void serout(void){
Serial.println(mark);
Serial.println(val);
Serial.println(" ");
}