0

BLDC Motor; 24pulses/Revolution @ 8 poles.
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BLDC Motor; 24pulses/Revolution @ 8 poles.

by greenbarron64 on Thu Jan 31, 2019 8:39 pm

Hi,

I've got two BLDC Motors, one is 8 poles and the other is 4 poles.

I need help reading the RPM using an Arduino UNO and printing to Serial.

I tired the code below gotten from; https://forum.arduino.cc/index.php?topic=455283.0 but it didn't work.

Code: Select all | TOGGLE FULL SIZE

volatile long pulses = 0 ;  // must be volatile if used in ISR

void int_func ()
{
  pulses ++ ;
}

long get_pulsecount ()  // safely read pulses when its not changing
{
  noInterrupts () ;
  long res = pulses ;  // don't zero the count, just sample it, less scope for bugs (easy debug)
  interrupts () ;
  return res ;
}

void setup ()
{
  pinMode (2, INPUT_PULLUP) ; // just in case its open-collector
  attachInterrupt (0, int_func, RISING) ;  // interrupt channel 0 is pin 2 (for Uno etc)
}

unsigned long timestamp = 0L ;
long prev_pulses = 0L ;

void loop ()
{
  if (millis () - timestamp >= 1000)  // triggered every second
  {
    timestamp += 1000 ;  // setup for next time

    long now_pulses = get_pulsecount () ;  // sample the count
    long count = now_pulses - prev_pulses ; // take difference from last sample
    prev_pulses = now_pulses ;  // update the previous value

    Serial.println (4 * count / 60.0) ;
  }
}


Please help.

greenbarron64
 
Posts: 15
Joined: Wed Jun 15, 2016 11:57 am

Re: BLDC Motor; 24pulses/Revolution @ 8 poles.

by adafruit_support_bill on Fri Feb 01, 2019 7:00 am

. . . but it didn't work.

Can you be more specific?
How exactly did you have everything connected?
What exactly did it do or not do when you tried to run it?

adafruit_support_bill
 
Posts: 72720
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.