Teensy LC FrequencyMeasure

Status
Not open for further replies.

ol boy

Member
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

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(" ");
  
}
 
Hi Ryan,
Reading the Github start page of the FreqMeasureMulti library, it states a capture mode called "FREQMEASUREMULTI_INTERLEAVE".
If I read that correctly, it measures time between edges [rising or falling].
Perhaps that is usable for you?

Regards,
Paul
 
So.. I re-did my project with a T3.2 and I had the same issue. I ended up uninstalling Arduino IDE and reinstalled with the latest 1.8.13 and Teensystudio. Recompiled the project with T3.2 hardware and now it works as it should. I might revisit the LC later and see if it now works as it should.

Thanks Ryan
 
Status
Not open for further replies.
Back
Top