Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong readings from PulseIn Function #23

Closed
ToughAce opened this issue Jan 31, 2021 · 3 comments
Closed

Wrong readings from PulseIn Function #23

ToughAce opened this issue Jan 31, 2021 · 3 comments

Comments

@ToughAce
Copy link

ToughAce commented Jan 31, 2021

Many thanks for providing this Attiny core!
I'm experiencing an issue with this very simple code:

int unsigned long pwm = 0;

void setup() {
  pinMode(3, INPUT);
  pinMode(0, OUTPUT);
}

void loop() {
  pwm = pulseIn(3, HIGH);
  if (pwm > 1800) digitalWrite(0, HIGH);  
    else digitalWrite(0, LOW);
}

It's supposed to be a simple RC switch and reads the PWM input from a RC receiver channel on Pin 3 and sets Pin 0 based on this.

This code works perfectly fine on an Arduino nano and also on an Attiny 45 with the dammelis Attiny core. But I would like to run it on an Attiny 13 using this core and it turns out the PWM reading is by factor 1.5 too high. I have used a servo tester to generate pulses between 800 and 2200us and sent the readings to a serial monitor and they are between 1200 and 3300us. Same issue occurs when I use the the above mentioned Attiny 45 with this core instead of the dammelis core. I have used the defaults and burned the fuses to the chip. I have also tried several other fuse combinations without success.
For now I've adjusted the 'if' statement to use 2700 instead of 1800us and it switches as intended when the input goes over 1800us.
Nevertheless, would be interested to know what I'm doing wrong

Thanks!

@sleemanj
Copy link
Owner

Mmm. Probably not doing anything wrong, could just be a bug in my code :)

You could try changing the "Millis Accuracy" setting (Tools Menu) and see if that makes a difference. You could also try SpenceKonde's original ATTInyCore with a Tiny45 and see if that produces a better result there, Spence's doesn't support Tiny13, but it could narrow it down to something in my changes.

@sleemanj
Copy link
Owner

Actually, now I dig into it, yes, this all came up before :)

SpenceKonde/ATTinyCore#384

SpenceKonde's original ATTinyCore has a fix but I have not rolled it in yet.

@sleemanj
Copy link
Owner

The 2022.3.10 release should incorporate the changes. Hopefully they work for the T13 (not tested)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants