Want to modify incoming frequency and resend it (tachometer and speedometer)

could be "runt pulses" explain my problem from above, that the send frequency does not match the real incoming (from the tachometer received) frequency?

i have now some time to go for a new try. i will then post complete with photos of tachometer, frequenz generator and so on, to better explain the problem.

its such worse...

i think my arduino is now broken. its acting really strange. i can´t even send a frequency via tone (which 100% worked before). also the freasured frequency is wrong on some functions.

with the version (first code shown in first thread), the frequency show me around 320hz when i send 293hz with my frequency generator. in another function (2nd code in first post) the frequency is shown correctly). using frequencemeasure-library the frequency is also shown correctly.

will order another one first.

if i change the boud rate in code and in serial monitor the incomming frequency changing and is now only 1% off.

is that normal, that send or received frequency have anything to do with the boud rate of the serial monitor function?

It depends on your code. Serial has an internal Tx buffer which, when full, will cause calls like println() to block until there is room in the buffer to stuff in more chars. How long it has to wait depends on how fast the buffer is emptied which is a function of the baud rate. The higher the rate, the faster the data leaves...

If you post your code, it would help

so... its a really strange thing. After alot of testing i got it ALMOST working.

Here is the code:
#include "TimerOne.h"
int pinIN = 8;
int pinOUT = 10;
unsigned long duration;
unsigned long durationCorrected;
unsigned long durationNEWscale;

void setup() {
pinMode(pinIN, INPUT);
pinMode(pinOUT, OUTPUT);
Timer1.attachInterrupt(callback);
}

void callback() {
digitalWrite(10, digitalRead(10) ^ 1);
}

void loop() {
duration = pulseIn(pinIN, HIGH);
durationCorrected = duration +20;
durationNEWscale = durationCorrected *10/9;
if (durationCorrected < 250000){Timer1.initialize(durationNEWscale);}

so... why "almost working"? when i´m testing just the code for pulsepin (or another reading function like ISR), its 100% working. if i test the code for TimerOne (or another sending function), its 100% working.
BUT... if i put both codes together, i get a difference between the code i send with my frequency generator (which have been readed 100% when using the reading function alone) differs from the received frequency displayed in serial monitor.
the biggest gap was around 30hz.

with the combination of timerOne and PulsePin i have a difference between sended frequency (with my frequency generator) and in serial monitor at around 3hz).

maybe someone did know this problem and could let me know the reason for it.

in the code above i fixed this by using durationCorrected = duration +20;

the difference also depends on, if i have the serial monitor function include or not... if its included the received frequency (or better say duration) gets higher.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.