NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Tech-O-Meter

October 19, 2010
by Earnhardt
Earnhardt's Avatar

Hi ALL,

I’m a newbie to the microcontroller and this site; I just purchased & got the NerdKits and hope you Gals & Guys could help. I am looking for a fast and easy way use my nerdKit to get RPM information from a rotating motor shaft and then display it on GLCD. I was thinking of using a Hall Effect Sensor. Since I am new at this and in the need to get it done quickly anyone have simple Source Code and parts for the circuit design I could use. Once I get this RPM information to display on the GLCD I could work on changing and trying other things later.

October 19, 2010
by Ralphxyz
Ralphxyz's Avatar

Search the Nerdkit forum for RPM, this has been discussed a lot.

Ralph

October 19, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Earnhardt,

One of my favourite customer projects of all time is the Hamometer described in this forum post. He did pretty much what you are describing, used a hall effect sensor to measure RPMs. Depending on how fast your motor is spinning this might not work though.

Humberto

October 21, 2010
by esoderberg
esoderberg's Avatar

Earnhardt,

Below are the pertinent sections of code, pulled from a larger program, that I used to determine the RPM and velocity of a wheel. The setup sounds similar to Hamometer. I have two mags 180 degrees out from each other on the wheel shaft with a nearby mounted hall switch that is triggered on or off with each change in N/S polarity i.e. each pass of a magnet. I use an interrupt in the code to note the change from on to off. Timer setup below is from Nerdkits realtime clock. The velocity equation below assumes a .6 meter circumference wheel. The basic equation is v = delta d/ delta t; in below code delta d is .3 meters for each half rev and tt is delta time. The (t - ttlast)/20 part in the denominator of the velocity equation is there because the delta t value (tt) is only recalculated with an interrupt, which won't happen if the wheel stops, so I wanted the calculated velocity to decay to zero with t continuing to grow but with no new tt calculated. The numerator is multiplied by 10000 because my clock (t) is in .1 msec increments.

Eric

// Clock set up

void time_setup() {
  // setup Timer0:
  // CTC (Clear Timer on Compare Match mode)
  // TOP set by OCR0A register
  TCCR0A |= (1<<WGM01);
  // clocked from CLK/
  // which is 16000000/64, or 250000 increments per second
  TCCR0B = 0;
  TCCR0B |= (1<<CS01) | (1<<CS00);
  TCCR0B &= ~(1<<CS02);
  // set TOP to 4
  // because it counts 0, 1, 2,..23,24, 0, 1, 2 ...
  // so 0 through 24 equals 25 events
  OCR0A = 24;
  // enable interrupt on compare event
  // (250000 / 25 = 10000 per second)
  TIMSK0 |= (1<<OCIE0A);
}

// the_time will store the elapsed time
// (10000 = 1 second)
// 
// note that this will overflow eventually
//
// This variable is marked "volatile" because it is modified
// by an interrupt handler.  Without the "volatile" marking,
// the compiler might just assume that it doesn't change in 
// the flow of any given function (if the compiler doesn't
// see any code in that function modifying it -- sounds 
// reasonable, normally!).
//
// But with "volatile", it will always read it from memory 
// instead of making that assumption.

ISR(TIMER0_COMPA_vect){ // when Timer0 gets to its Output Compare value,
  // elapsed time (0.0001 seconds per count).
  t++;

 }

void init_tach(){

  // make PB0 input pin

  DDRB &= ~(1<<PB0);
  // pull up resistor on
  PORTB |=  (1<<PB0);

  //Enable Pin change interrupt
  PCICR |= (1<<PCIE0); // this enables interrupts on pins PCINT 7-0

 //set the mask on pin change interrupt 0 so that only PCINT0 (PB0) triggers interrupt

  PCMSK0 |=(1<<PCINT0);

 }

 // This is what gets executed on interupt for measuring frequency of hall switch input, set to trip with change to PB0

ISR(PCINT0_vect){

//Trigger on passing of mag by hall switch.

    tt=t-ttlast;//delta time between mag hits
    ttlast = t;

    }

// clock and intterupt variables

volatile uint32_t t=1;
uint32_t tt=0, ttlast=0;

    // in main

 time_setup();

 // turn on interrupt handler
  sei();

  //init tach to gather velocity data from hall switch

 init_tach();

// in continuing main program loop

      v = 3000/(((t - ttlast)/20)+tt);// tt is delta time between mag hits as computed in interrupt
October 25, 2010
by Earnhardt
Earnhardt's Avatar

Hi All,

Sorry for the delay in getting back with any of you. Thanks for all the information it's very helpful, I just finished up on the Temperature Sensor Circuit, and have taken a look at the Hamometer, this is somewhat the path I would like to go but in a bigger scale. Eric thanks for the code I’ll take a look and see if I could get it working. Take a look at the Rechargecar.com. How it works is they have a hall-effect sensor that’s connected to their product called the AutoBlockRPM this device provides power to the sensor and connects to a netbook via USB which they have written a small “exe” that’s is doing the conversion that is installed on the netbook then it outputs the RPM information to a Mimo display. How I know this is by talking with them. What I would like to do is basically the same thing but not use the netbook and use the nerdkit.

Post a Reply

Please log in to post a reply.

Did you know that you can follow NerdKits on Facebook, YouTube, and Twitter? Learn more...