How to multiply frequency signal from motor hall sensor by x1.2 (motor rpm feedback mod because of 50Hz and 60Hz compatibility)?
I expect frequency is something about hundreds of Hz to few kHz.
I need as simple solution as possible (maybe bare attiny chip enough?).
Are you saying that you want to receive a signal at one frequency and output it at a higher frequency ?
Yes, exactly.
What type of signal are you receiving ?
For instance, is it a sine wave or a square wave ?
If it is a square wave then does its mark/space ratio change ?
Signal comes directly from a 3pin (Vcc, GND, Signal) hall sensor. I didn't looked at it with scope, because device switches off after a second (don't like a feedback signal it expects).
If it comes from a Hall sensor it will almost certainly be a square wave
Let's imagine an example to work with
Suppose that the input is a symmetrical 100Hz square wave. Over what period should the input be measured to determine its frequency and what should be output ?
I just looked with a scope. The signal is square wave with 50% duty cycle.
So at the output it must stay like this only a frequency should be multiplied by x1.2
As it shuts down after a 1s with wrong signal, I think it should receive acceptable signal few times quicker to work correctly.
Does the frequency of the input change or is it always either present or not present at a fixed frequency ?
When motor do not rotate it is still LO or HI, depending on rotor position according hall sensor. When rotor rotates a square signal is generated immediately and its frequency changes according RPM.
I think it is just ordinary principle of hall sensor work.
And a device has variable work frequency, user may select either of 10 predefined.
Also device monitors overload (by rpm I suspect) and shuts down once detected.
I don't think that I can offer a solution but other users may have something to add
@finderbinder
Maybe this IC meets your needs.
You will need to study the datasheet and see if it really works for your project.
APPLICATIONS
Multiplication, division, squaring
Modulation/demodulation, phase detection
Voltage-controlled amplifiers/attenuators/filters
One could measure the frequency of the input using some convenient method, e.g. measuring the interval between rising edges and use that frequency to generate a frequency 1.2 times the measured frequency, e.g. using the tone() function.
This would introduce a lag in the frequency reading of at least one interval which may or may not be a problem if this is part of a control loop.
// Pseudo code
float sensor_period = measure_sensor_period() ; // Function to measure the period of sensor pulses
tone(1.2/sensor_period) ; // Generate output to controller at 1.2 * sensor frequency
"measure_sensor_period()" is left as an exercise for the student.
Back in the analog days we would multiply the incoming signal by 6 and then divide the result by 5. The frequency multiplication was typically done with a PLL(phase lock loop) then something like an SN7490 counter to divide by 5.
So far I think the most acceptable solution would be to do it in Arduino code (chips at hand, tune in software). The only restrict is my knowledge in coding
Can't force to work your strings, MrMark (undefined, unknown,...)
I agree that tone() function should make the output easy enough.
For measuring the input, because the input signal frequency can be, let's assume, up to 5KHz (period 200us), I would recommend using an external interrupt pin to count the rising edges of the signal.
volatile int counter;
...
void incrementCounter() {
counter++;
}
...
void setup() {
...
attachInterrupt(digitalPinToInterrupt(inPin), incrementCounter, RISING);
...
}
The main code can then use millis() to use that count, perhaps every 100ms, to calculate the input frequency and set the output frequency.
void loop() {
...
static unsigned long lastMeasurement;
static unsigned int lastCount;
...
if (millis() - lastMeasurement >= 100) {
noInterrupts();
unsigned int newCount = counter;
interrupts();
unsigned int frequency = 10 * (newCount - lastCount);
tone(outPin, 6 * frequency / 5);
lastMeasurement += 100;
lastCount = newCount;
}
...
}
If this isn't fast enough, it might be possible to use a hardware timer to count the input signal edges, instead of using an interrupt. But that would make the code less portable between chips, so the interrupt method is preferred.
I get constant ~4kHz at output by this example. And it has no relation to input frequency.
Do you mean the example from @MrMark on post #13? Or the example I gave in post #16?
Neither was complete code. The forum will need to see your complete code, and a schematic, in order to help you figure out what's causing your problem.
I mean your code PaulRB in post #16.
I experiment with Arduino Uno at the moment.
I need a separate solution (only bare mcu if possible, or simple Arduino board), there are no other code. I receive Freq1 from hall sensor, multiply it by x1.2 and output Freq2 to device board. That's it.
The code I posted in #16 is not complete code. It will not compile or upload, so you cannot have tested that code. You must have used my suggested code as part of your complete code which you uploaded to the Uno. I am asking you to post that complete code.
We can take that code and add some serial output to help us understand/debug why it is not working as desired.
We will also look at your schematic to discover how you have connected the hall sensor, to check if that is correct.