Pages: 1 [2] 3   Go Down
Author Topic: Hall effect sensors  (Read 4261 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
will be much more accurate because the period will be measured to an accuracy of 62.5 nS.
62.5 ns is true if you use HW timers, if you use micros() the accuracy goes in steps of 4 micros().

Putting all the timing math in the IRQ gives something like this. Note I removed the counter in the IRQ routine to get max update frequency.
Drawback of this method seems to be that you cannot measure an RPM of zero. => additional code needed to check this.
In general low (<60) RPM's will result in a low (> 1s) update frequency ==> more pulses per rotation needed [for every measure method]
Code:
//
//    FILE: rpm4.pde
//  AUTHOR:
//    DATE: 21-oct-2012
//
// PUPROSE: updates rpm after every pulse
//
volatile boolean newRpm = false;
volatile unsigned int rpm = 0;         // assuming not above 65535
volatile unsigned long time = 0;
volatile unsigned long timeold = 0;

void setup()
{
  Serial.begin(115200);
  attachInterrupt(0, rpm_fun, FALLING);
}

void loop()
{
  if (newRpm)
  {
    newRpm = false;
    Serial.print(millis());
    Serial.print(", ");
    Serial.println(rpm);
  }
}

// every pulse a new rpm value,
void rpm_fun() 
{
  time = micros();
  unsigned long duration = time - timeold;
  rpm = 60000000UL/duration;
  timeold = time;
  newRpm = true;
}

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HW sounds OK.

If the baudrate influences the RPM it might be that the wires influence each other.
You could check if you have the same problems if you take IRQ1 (pin 3)

================

What is strange is that the numbers are much higher than you expect [about 5000]. Is this correct?

Do you have a datasheet of the reed switch used?
What is its upper switch frequency?
First thank you for all the replies as a newbie I really appreciate this forum.
Glad the HW ok

Re baud rate I changed to IRQ1 (pin 3), this work fine on 9600 but on 115200 the readings are all over the place??

Re reed switch I cant find data sheet but what I have done is change the switch for another and this is the result and is no more than 1% different to the electronic tacho.
Code:
rpm37
rpm4363
rpm4332
rpm4363
rpm4347
rpm4347
rpm4580  ^^^^^^^^ Here
rpm4332
rpm4363
rpm4332
rpm4363
rpm4363
rpm4562 ^^^^^^^^^ Here
rpm4347
rpm4347
rpm4347
rpm4363
rpm4347
rpm4347
rpm4562 ^^^^^^^^^^ Here
rpm4347
rpm4347
rpm4580  ^^^^^^^^^^^ Here
rpm4347
rpm4347
rpm4347
rpm4347
rpm4347
rpm4363
Just the few disparities marked. Also tried at lower speeds and slightly higher, the results were as good.
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19358
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Re baud rate I changed to IRQ1 (pin 3), this work fine on 9600 but on 115200 the readings are all over the place??

Serial output uses interrupts, and at a higher baud rate it will use more of them. This will throw out readings that rely on interrupts.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Serial output uses interrupts, and at a higher baud rate it will use more of them.
But a string of the same length will generate the same amount of interrupts, independent of the baudrate?  Or did I miss something in class?
Assuming the same amount of characters per second, BTW
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm from Argentina, I am working with Hall sensors, at an advanced level, I care about your ideas. I am new to the forum arduino over time I will learn to use it well. Four years ago I started working with arduino

care with the baud rate when one wants to measure many rpm, speed serial port of the microprocessor removes arduino speed
Logged

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rob
Here are the results of your last code
Code:
19444, 3785
19460, 3783
19476, 3777
19491, 3778
19508, 3783
19523, 3780
19539, 3782
19555, 3782
19571, 3780
19587, 3779
19603, 3780
19618, 3782
19635, 3780
19650, 3776
19666, 3776
19682, 3782
19698, 3785
19714, 3787
19730, 3785
19745, 3781
19762, 3778
19777, 3777

Nicogongora
I can see what you mean, this morning I have had consistent results with 9600 but going to 115200 I get fluctuating results.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That are quite smooth readings esp compared to the previous ones. You can smooth these readings even more in the loop() e.g. by only adjusting for 25% of the new rpm value;

Code:
loop()
{
  if (newRpm)
  {
    newRpm = false;
    int smoothrpm = (3*smoothrpm + rpm)/4;  // weighted average
    Serial.print(millis());
    Serial.print(", ");
    Serial.print(rpm );
    Serial.print(", ");
    Serial.println(smoothrpm );
  }
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll try that out but at the moment have to make a mount for the different reed switch, old was round threaded but new one is oblong.
Logged

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That are quite smooth readings esp compared to the previous ones. You can smooth these readings even more in the loop() e.g. by only adjusting for 25% of the new rpm value;

Code:
loop()
{
  if (newRpm)
  {
    newRpm = false;
    int smoothrpm = (3*smoothrpm + rpm)/4;  // weighted average
    Serial.print(millis());
    Serial.print(", ");
    Serial.print(rpm );
    Serial.print(", ");
    Serial.println(smoothrpm );
  }
}
Code:
int smoothrpm = (3*smoothrpm + rpm)/4;  // weighted average
I changed to
Code:
int smoothrpm = ((3*smoothrpm + rpm)/4)*4;  // weighted average
this is the result
Code:
rpm 4210   smooth rpm 4208
rpm 3647   smooth rpm 3644
rpm 3726   smooth rpm 3724
rpm 3692   smooth rpm 3692
rpm 3703   smooth rpm 3700
rpm 3715   smooth rpm 3712
rpm 3692   smooth rpm 3692
rpm 3692   smooth rpm 3692
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3692   smooth rpm 3692
rpm 3669   smooth rpm 3668
rpm 3669   smooth rpm 3668
rpm 3692   smooth rpm 3692
rpm 3669   smooth rpm 3668
rpm 3669   smooth rpm 3668
rpm 3680   smooth rpm 3680
rpm 3669   smooth rpm 3668
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3658   smooth rpm 3656
rpm 3669   smooth rpm 3668
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
Then tried this
Code:
int smoothrpm = ((9*smoothrpm + rpm)/10)*10;  // weighted average
gave this
Code:
rpm 3692   smooth rpm 3690
rpm 3692   smooth rpm 3690
rpm 3680   smooth rpm 3680
rpm 3692   smooth rpm 3690
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3669   smooth rpm 3660
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3669   smooth rpm 3660
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3669   smooth rpm 3660
rpm 3692   smooth rpm 3690
rpm 3669   smooth rpm 3660
rpm 3669   smooth rpm 3660
rpm 3870   smooth rpm 3870
rpm 3669   smooth rpm 3660
rpm 3680   smooth rpm 3680
rpm 3680   smooth rpm 3680
rpm 3658   smooth rpm 3650
rpm 3692   smooth rpm 3690
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Can you explain the *4 and the *10 ?    Looking at the code I expected other result (a growing value for smoothrpm).
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19358
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Serial output uses interrupts, and at a higher baud rate it will use more of them.
But a string of the same length will generate the same amount of interrupts, independent of the baudrate?  Or did I miss something in class?
Assuming the same amount of characters per second, BTW

Er, yes you are right. I was wrong to say it will use more of them (assuming you are printing the same string, per second). If you are printing non-stop you would use more per second.

I would suggest though, that at a higher baud rate, to empty the serial buffer of the string you have put there would involve a lot of interrupts in quick succession. Once the serial interrupt starts, the higher-priority external interrupt has to wait. This is likely to throw out the timing it takes. Even at a lower baud rate this would be a problem, it's just less likely the interrupts would coincide.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Newbie
*
Karma: 1
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
,

maybe a smarter solution then using a reed switsch(problem contact bouncing at higher speed) is using a Single-Chip-Encoder, like the iC-MH/MH8, and measure the change between two absolute position readings from the magnetic rotary encoder, or the time between two zero pulse. You might look at this two application: http://www.ichaus.biz/wp2_simple_measurement and http://www.ichaus.biz/wp_boost_performance .

Enjoy your project work!
Logged

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Can you explain the *4 and the *10 ?    Looking at the code I expected other result (a growing value for smoothrpm).

The out put was a 1/4 of the RPM; example
Code:
rpm 3703   smooth rpm 925
so I added *4, the 10 was to try and get an even more average.
Logged

New Delhi,India
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,
I suggest that you do not use the attach interrupt function at all,try using the pulseIn function,as what you want the is the pulse,whenever the magnetic fields react with the sensor.
Logged

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,
I suggest that you do not use the attach interrupt function at all,try using the pulseIn function,as what you want the is the pulse,whenever the magnetic fields react with the sensor.
What do others think?

Is it possible to add another interrupt function, again RPM but for a slow shaft speed (circa 50 to 100 rpm)?
Logged

Pages: 1 [2] 3   Go Up
Jump to: