Author Topic: Using the hall sensor from a bldc motor to get rpm on arduino  (Read 2067 times)

0 Members and 1 Guest are viewing this topic.

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
I have a few projects that I am going to start on.  One is to get the rpm data from my sensored bldc motors.  I am trying to improve upon the sample rate of the flywheel dyno I have.  The flywheel dyno uses a 10hz sample rate with an optical sensor.  Due to the low sample rate, the torque curve isn't accurate near 0 rpm.  I realize I can't get torque at 0 rpm with a flywheel dyno, but I hope to get closer to 0 than my current setup which starts outputting torque data after about 500 milliseconds.  Sense the hall sensors are used to accurately control the speed of the motor, I assume it will be sufficient for a higher sample rate.  The motor in question will be a 3 phase 2 pole bldc motor.  Max RPM will be about 22k, but I have motors that can get up to 60k.  My intention is to read this data with an arduino and hopefully output it to a spread sheet where I can plot the data vs time.  Then use the MOI of my flywheel to get mechanical power and torque.  I also plan on using ACS772ECB-200B-PFF-T on one of the phases to get the phase current as the sensor on the dyno is connected in series with the battery.  I haven't looked into a voltage sensor yet, but I plan on adding that as well.

What I am trying to do here is to learn, and test the validity of the dyno I bought.  Btw, I am extremely new to arduino, so some of my questions may be basic.

The closest I have found to what I am trying to do is from the following link:  https://www.utsavrshah.in/Microcontroller%20resources/RPM%20measurement%20using%20Arduino/RPM%20Measurement%20using%20Arduino.html

I would like to output the data to a csv though. 
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5817
  • Country: de
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #1 on: May 22, 2023, 07:55:31 pm »
Measuring rpm using the Hall sensors on motor is absolutely feasible, but you'll only get one pulse per revolution. If that's OK, go ahead.
BTW: the Hall sensors do not "control the speed of the motor", they control the commutation of the stator.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #2 on: May 22, 2023, 08:34:15 pm »
If each phase has its own sensor wire, wouldn't it be 2 pulses per revolution?  6 step commutation?  Or am I not thinking about that correctly?
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5817
  • Country: de
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #3 on: May 22, 2023, 08:46:22 pm »
Well, you can sniff all three Hall sensors if you like, which will give you three pulses/revolution. but as they're all in a fixed 120 degrees relationship it will give no additional information/precision. But yes, the frequency will be 3x higher (demanding 3x higher processing speed without any advantage).
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #4 on: May 22, 2023, 09:54:36 pm »
Sniffing all 3 sensors is for another project. That one is going to find the actual angle of the sensors. They are supposed to be 120* off but they vary by a couple of degrees depending on the board. Some are way off. 

So for more understanding. The poles will pass the sensor and create a voltage above and below a 2.5v reference. We are saying one pulse is peak to peak above 2.5, right?  I should be able to calculate rotor strength from this as well? 


I’m going to measure on my scope and see what I find.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4384
  • Country: dk
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #5 on: May 22, 2023, 10:08:01 pm »
Measuring rpm using the Hall sensors on motor is absolutely feasible, but you'll only get one pulse per revolution. If that's OK, go ahead.
BTW: the Hall sensors do not "control the speed of the motor", they control the commutation of the stator.

number of pulses will depend on the number of magnets in the motor
 

Offline Circlotron

  • Super Contributor
  • ***
  • Posts: 3158
  • Country: au
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #6 on: May 22, 2023, 10:17:15 pm »
Is the BLDC motor driving the dyno flywheel or is it simply being rotated while connected to the flywheel and the hall sensors measuring the rotation?
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5817
  • Country: de
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #7 on: May 22, 2023, 10:40:49 pm »
number of pulses will depend on the number of magnets in the motor
True. But from the OP's description, it seems to be a normal N-S anchor/rotor.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #8 on: May 22, 2023, 10:56:09 pm »
The rotor is a standard rotor with one pole pair.  It is an in runner type, I think that is the correct term.  And the motor is driving the flywheel.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4384
  • Country: dk
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #9 on: May 22, 2023, 10:57:08 pm »
take the signal from the optical sensor and measure period instead of frequency at low speeds. Maybe add more target for the sensor so you get more than one pulse per revolution
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #10 on: May 23, 2023, 12:16:39 am »
The current setup uses 4 read points per rotation for the optical sensor.  I don't know how the programming actually reads that data, but it outputs to a csv at 10hz.

I put my scope on the sensors and the output works, so that is good.  I measure all 3 and they look like they are offset by 120*.  I am completely new to all of this and just bought my scope maybe a month or two ago.  Would there be a math function to compare the 3 signals?  IE, get the actual offset?

I am posting a pic of the scope signal.  Sorry, I have to learn to capture with the PC still. 


 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5817
  • Country: de
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #11 on: May 23, 2023, 12:46:43 am »
'Scope picture looks perfect. Nice edges, 120 degrees apart, what more can you wish for?
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #12 on: May 23, 2023, 01:12:22 am »
Well...  This motor is a "stock" class motor.  We look for every little bit to get the edge.  Having the sensors be perfect is the goal.  Also I have a device that measures the sensor angles, just curious if I could do that with the scope to verify the accuracy.  Also all this is learning for me, and it is quite fun and I get an idea in my head and now I am trying to see it.
 

Offline Circlotron

  • Super Contributor
  • ***
  • Posts: 3158
  • Country: au
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #13 on: May 23, 2023, 02:50:23 am »
Set rpm and scope sweep speed so that channel 1 first rising edge is on the first graticule line and it's next rising edge is on the 6th graticule line. Then channel 2 should be 2 divisions across from channel 1 and channel 3 should be another 2 divisions across from channel 2.
« Last Edit: May 23, 2023, 02:52:31 am by Circlotron »
 

Online JustMeHere

  • Frequent Contributor
  • **
  • Posts: 718
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #14 on: May 23, 2023, 07:11:10 am »
Check out these videos covering how to do this with hardware timers, input compare, and interrupts.


 
The following users thanked this post: trilerian

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #15 on: May 23, 2023, 07:47:09 pm »
Those videos are great, thanks!  I will get to the interrupts.  But first I I connected everything together just to read the rpm sensor with the arduino.

I am starting off pretty basic with a 16x2 lcd without a backlight.  So, sorry.  This really is a learning process for everything.  I have 16x2 with the i2c, but I need to figure out the code with that.

I measured the sensor A with the arduino and sensor C with my scope.  They were within a couple of Hz.  Also I am including a pic of the optic sensor output from the dyno. 

« Last Edit: May 23, 2023, 07:48:58 pm by trilerian »
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #16 on: May 23, 2023, 07:49:33 pm »
And…
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #17 on: May 23, 2023, 09:23:27 pm »
I was able to edit the code to use an lcd with the i2c.  Now I am running into another issue.  Ideally I would like to power this setup off 2 power supplies that I have (with the help of this forum) modified for a lower output voltage.  A single PS didn't provide enough amperage so I have 2 in parallel.  However, because the ESC uses the DC power from the power supply to feed the sensor board, it makes the output noisy.  While the scope doesn't have any issue with it, the arduino can add extra counts to the rise because of the noise.  If I run the motor off a battery the issue goes away.  So please bear with me here, I know I am new.  Can I make an RC filter for this noise?


Edit:  I used my scope to look at the frequency of the noise.  It looks to be around 600khz to 700khz on the bottom and 150khz to 400khz on the top.  The frequency gets higher as the frequency it is riding on gets higher. 
« Last Edit: May 23, 2023, 09:35:03 pm by trilerian »
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5817
  • Country: de
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #18 on: May 23, 2023, 09:59:36 pm »
The best way is to run the power stage and the control electronics from two separate power supplies. As you've noticed, the power stage can generate a lot of noise. The main challenge is keeping the power and signal grounds apart (but still connected).
 
The following users thanked this post: trilerian

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #19 on: May 24, 2023, 12:23:35 pm »
So how do I achieve this?  For right now, the arduino is being powered by my laptop, while the dyno setup is powered by a dc source.  Either a power supply which connects to an esc which connects to the bldc motor, or a battery that connects to the esc...   Their is a six pin sensor harness that goes from the motor to the esc.  The pin outs are common ground, sensor C, sensor B, sensor A, temperature, 5v.  So this powers the sensor board and the pulses come back on it to the esc.  When using the scope I use the common ground and one of the sensor pinouts.  But for the pinout going to the arduino I just use the sensor.  Should I be putting the common ground from the sensor board to the ground pin on the arduino? I know this would be the case if the entire system was running from the same source, but it isn't.  Btw, I do have a 10k resister in series between the sensor lead and the arduino.  That helps a lot with the miscounts.  It was very random before putting that resistor in. 
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 162
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #20 on: May 29, 2023, 09:16:06 pm »
So, I am trying to get this setup to read the initial value faster.  There seems to be a refresh that happens until the the unit starts reading, then everything is fine.  I would like the initial refresh to be faster so I can get the frequency closer to 0.  Right now I don't start picking it up till around 33Hz.

Here is the arduino code I am using.  I scraped this together from different sources.

I have print to lcd because when I am not running the terminal emulator I want an output.  I will need to make changes so the lcd can display data at a lower rate than the serial, right now the data goes faster than the lcd can print. 


#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header


hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip


int Htime;              //integer for storing high time

int Ltime;                //integer for storing low time

float Ttime;            // integer for storing total time of a cycle

float frequency;        //storing frequency

// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;



void setup()

{

    pinMode(8,INPUT);

    lcd.begin(LCD_COLS, LCD_ROWS);
   Serial.begin(115200);
}

void loop()

{

    lcd.clear();

    lcd.setCursor(0,0);

    lcd.print("Frequency of signal");


    Htime=pulseIn(8,HIGH);      //read high time

    Ltime=pulseIn(8,LOW);        //read low time

   

    Ttime = Htime+Ltime;


    frequency=1000000/Ttime;    //getting frequency with Ttime is in Micro seconds

    lcd.setCursor(0,1);

    lcd.print(frequency);

    lcd.print(" Hz");
   Serial.println (frequency*60);

    delay(10);

}



 

Online JustMeHere

  • Frequent Contributor
  • **
  • Posts: 718
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #21 on: June 03, 2023, 03:40:44 pm »
Your algorithm isn't really sampling frequency.  It's looking at one up and one down pulse.  Then it sleeps.  You should be counting the number of pulses that happens over a period of time.  Ex:  Sample the signal for 100ms and count 10 pulses, you get a frequency of 10 Hz (note my math may be wrong). 

This is best done using the hardware and interrupts I mentioned above.  Trying to count this in software will be problematic because you also end up timing the execution speed of your program.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4384
  • Country: dk
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #22 on: June 03, 2023, 05:49:06 pm »
Your algorithm isn't really sampling frequency.  It's looking at one up and one down pulse.  Then it sleeps.  You should be counting the number of pulses that happens over a period of time.  Ex:  Sample the signal for 100ms and count 10 pulses, you get a frequency of 10 Hz (note my math may be wrong). 

~100Hz ;) 

at low frequencies it is much more accurate to measure the period
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8089
  • Country: fi
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #23 on: June 03, 2023, 06:18:52 pm »
Well, you can sniff all three Hall sensors if you like, which will give you three pulses/revolution. but as they're all in a fixed 120 degrees relationship it will give no additional information/precision. But yes, the frequency will be 3x higher (demanding 3x higher processing speed without any advantage).

With the usual configuration, it's six, not three pulses per electrical revolution so 60 degree accuracy, and this is electrical degrees which equals mechanical degrees only in 1 pole pair per phase motors. OP is talking about RPM so mechanical revolutions, which is then any integer multiple of six - usually at least 12 because I think 1-pole-pair-per-phase BLDC motors are quite rare.

BTW: the Hall sensors do not "control the speed of the motor", they control the commutation of the stator.

Of course hall sensors can be used for speed loop, too, why not; that's pretty usual thing to do. Using them primarily for commutation does not exclude other types of uses for the same data.
« Last Edit: June 03, 2023, 06:20:57 pm by Siwastaja »
 

Online JustMeHere

  • Frequent Contributor
  • **
  • Posts: 718
  • Country: us
Re: Using the hall sensor from a bldc motor to get rpm on arduino
« Reply #24 on: June 04, 2023, 07:03:00 pm »
Any chance you're using voltage to control the speed of the fan?  The pulse Vmax is the same as the voltage driving the fan (at least the one I played with on my scope did this.)  You may be generating runt pulses.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf