# Hall sensor simulation

Hi,

I try to simulate some hall sensors with an arduino. Currently I have a working code for a speed pulse. But running it from an external pwm signal. The interrupt pin is currently controlled by an external pwm frequency from 0hz (off) up to ~12000hz.

``````int dirPin = 0; //A0
boolean dirRev=0;
volatile int outPin = 1; //A1
volatile unsigned int dirDelay = 45;

void setup() {
pinMode(outPin, OUTPUT);
pinMode(dirPin, INPUT);
attachInterrupt(0,speedPulse, RISING);
}

void loop() {

void speedPulse(){
if(dirRev==LOW){
dirDelay=40;
}else{
dirDelay=85;
}
noInterrupts();
digitalWrite(outPin,HIGH);
//  delayMicroseconds(40);
delayMicroseconds(dirDelay);
digitalWrite(outPin, LOW);
interrupts();
}
``````

Now to my question.. I'm trying to make this a bit better. I now need to setup 4 different speed pulses, and would like to control direction and frequency from serial input instead. The serial part is ok but how would i generate the frequency internally to control the different speed pulses..?

On each of 4 pins, you want to generate simultaneously independent, variable frequency (up tp 12kHz) square wave signals of a specific pulse width ( say 40 microseconds ). Is that it ?

6v6gt:
On each of 4 pins, you want to generate simultaneously independent, variable frequency (up tp 12kHz) square wave signals of a specific pulse width ( say 40 microseconds ). Is that it ?

Yes that is correct! And the pulse with of the top could also be 85 usec depending on the direction.

If the pulse width is 85 microseconds, there won’t be much of a gap between them at 12kHz.
If you are using a Uno etc, you are limited to 1 16 bit timer and 2 8 bit timers (really only one of which can easily be used).

What level of granularity do you require ? Would the following example be fine enough :

``````Frequency Steps (KHz)    Period (uS)
---------------------    -----------
12.5                     80
10.0                    100
8.33                    120
7.1                     140
6.25                    160
etc.                    etc.
``````

If so, you could probably get away with one timer. However, if you require a continuously variable frequency, it will clearly not be sufficient.

12kHz might be on the very far side of it, and maybe don't get up there.
The different channels on the other hand need to be quite exact.
simulating the frequency of a wheel with 2 teeth freq = 2 * ( (10*rpm) / (60 * 0.291) )
1 rpm I get ~1,3831 hz => 722999usec
8000 rpm ~11065.007 hz => 90.375usec

OK. You are simulating a wheel revolution.
12kHz would be 720,000 RPM !! (12,000 revolutions in 1 second and 60 seconds per minute)

8,000 RPM is 133.3 Hz (period of 7.5mS or 7500uS)