PaulStoffregen / FreqMeasure

Measures the elapsed time during each cycle of an input frequency.
http://www.pjrc.com/teensy/td_libs_FreqMeasure.html
69 stars 31 forks source link

Freqmeasure causes hardware reset on ATTINYx4 #23

Open cmdrscotty opened 1 year ago

cmdrscotty commented 1 year ago

Description

Attempting to add ATTiny 84/44/24 to the capture definition will allow it to compile, but the ATtiny will end up in a perpetual hardware loop

In the hardware spec sheet for the ATTINYx4 it lists on page 61 that ICP1 is attached to Timer/Counter1 on pin PA7 (arduino pin 6)

At this point, i'm unsure if this is a fault of how i'm defining the ATtiny definition in FreqMeasureCapture.h, a draw back of the ATtiny core, or the ATtiny itself just can't handle the FreqMeasure library.

Steps To Reproduce Problem

update FreqMeasureCapture.h with the following definition update:

#elif defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny24__)
   #define CAPTURE_USE_TIMER1

Hardware & Software

ATtiny84 None Arduino IDE version: 1.8.16 and 2.0.3 Version info & package name (from Tools > Boards > Board Manager): ATtiny core 1.5.2 Windows 10 Pro 21H2 Any other software or hardware?

Arduino Sketch

#include <FreqMeasure.h>
#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

SoftwareSerial mySerial(rxPin, txPin);

void setup() {
  mySerial.begin(9600);
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // print this every time it boots, if this message is spammed, then we are having hardware resets
  mySerial.println("RESET!");
  FreqMeasure.begin();
}

double sum=0;
int count=0;

void loop() {
  if (FreqMeasure.available()) {
  mySerial.println("measured!");
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      float frequency = FreqMeasure.countToFrequency(sum / count);
      mySerial.println(frequency);
      sum = 0;
      count = 0;
    }
  }
}

Errors or Incorrect Output

image

cmdrscotty commented 1 year ago

This can be closed. apparently there was an issue with the ATTiny Core that I was using, reinstalling it fixed the hardware looping i was getting.

But will keep this as it has the values that need to be added to FreqMeasureCapture.h to allow ATtinyx4 to use the library