CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to calculate rpm for dc motor?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
wanraimi



Joined: 20 Feb 2013
Posts: 11

View user's profile Send private message Yahoo Messenger

How to calculate rpm for dc motor?
PostPosted: Sat Mar 16, 2013 3:01 pm     Reply with quote

I have a problem about how to display the rpm value on lcd (16*2). I'm using a dc motor and have a rotary encoder as sensor to calculate pulse. I found the formula rpm in internet (rpm=15*xpulse) but I don't know how to make a coding to use the formula and display to lcd. I'm using pic 18f458. Can anyone help me because I'm very new in C language programming.
temtronic



Joined: 01 Jul 2010
Posts: 9182
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 16, 2013 4:17 pm     Reply with quote

You can try using the 'search' option here. Put 'tachometer' in the box and see what comes up!

I question your 'algorithm' for RPM though..as RPM is based upon # of encoder pulses per revolution x time value. IE a 'quadrature' encoder will have 4X the number of pules a 'simple slot' encoder will have.
hth
jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Mar 16, 2013 5:43 pm     Reply with quote

Also try searching on 'tacho'.

Have a go at using some of the CCS examples to find out how to code in 'C' with CCS.
(CCS examples include LCD drivers.)

You need to tell us more about your encoder.

Your suggested formula will increment the 'RPM' reading in 15s.

This topic has been discussed, in depth, on the forum recently.

Mike
wanraimi



Joined: 20 Feb 2013
Posts: 11

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Mar 16, 2013 11:12 pm     Reply with quote

can i know more about tachometer, do sensor or not... another one my problem is to calculate the frequency to respond with rotary kit and lcd. can i get the coding example if there.
Ttelmah



Joined: 11 Mar 2010
Posts: 19391

View user's profile Send private message

PostPosted: Sun Mar 17, 2013 2:42 am     Reply with quote

Lets start with your formula. Wrong. This formula will _only_ work with one specific sensor giving a particular number of pulses per rev. It is not a 'generic' formula.

You need always to start with some data. How many pulses/rev is your sensor?.

Then there are two ways of measuring 'RPM':

The first is the obvious one. Count the number of pulses over a time interval. A simple multiplication (dependant on the interval and your sensor), will give 'RPM'. Problem is that this takes a long time. Imagine you have a shaft spinning at 50RPM, and a 2 pulse per rev sensor, this only gives a pulse every 0.6 second. Sample for one second, and you will see one pulse sometimes, and two pulses others, and get a 'result' that jumps between 30RPM and 60RPM. 100% jumps. Not exactly 'precision'....

The second, is instead to measure the time between the pulses. The PIC has a peripheral that helps you do this (the CCP), and with this, you can get a much more accurate, and quicker assessment of the speed. With our shaft, imagine you count in uSec, the time between pulses. You get 599999 600000 and 600001 counts as there is a tiny beat with the internal oscillator, giving speeds of:
30E6/599999 = 50.0000833 RPM
30E6/600000 = 50RPM
30E6/600001 = 49.9999RPM

Variations of just 0.0001% in the measurement, despite only taking 0.6 seconds to do the reading. Much better. The '30E6' here is not magic, it is simply the time (in 'counts') between pulses at 1RPM. So if instead you had a 10line sensor, then the figure would be 6E6. While if instead of working in uSec, you decided to work in 1/100000th second counts, the figures would drop by a factor of ten.

You need to stop worrying about coding, and instead work out what pulse rates you should get, how fast you want to measure etc.. Then with an idea of what needs to be done, step into thinking whether you want to use approach 1, or 2. A search of past threads on tachometers, will find a lot of information, both on hardware, and code.

Do some reading.

Best Wishes
wanraimi



Joined: 20 Feb 2013
Posts: 11

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Mar 17, 2013 4:57 am     Reply with quote

why i'm need to use the tachometer whereas I already have a LCD, because my project using LCD to display the speed, as far as I know the tachometer also display the speed of dc motor.

sorry but I need to said, I have long make a research about how to interact my rotary kit sensor with encoder and LCD display, my pulse count is at pin C0 I cannot find how to implement the coding to count the pulse are resulting from rotary kit and getting the rpm value then display to my lcd.
Ttelmah



Joined: 11 Mar 2010
Posts: 19391

View user's profile Send private message

PostPosted: Sun Mar 17, 2013 6:05 am     Reply with quote

Get your brain in gear.
Displaying the speed of the motor, _is_ a tachometer.
As you have been told, there are dozens (possibly even hundreds) of threads here describing how to generate a tachometer with a PIC.
Read them.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Mar 17, 2013 7:19 am     Reply with quote

Start with the trivial case. RPM = Revolutions Per Minute How many input pulses do you get for each revolution? Have your PIC count pulses for one minute. What should the count be for 1 RPM? How about 100 RPM? 10,000 RPM? What if the PIC only counts for one second?

Write the code to do this and play with it till you really understand what is going on.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Mar 17, 2013 8:46 am     Reply with quote

Try this link for starters.

http://www.ccsinfo.com/forum/viewtopic.php?t=49742&start=0

We're trying to help you work it out for yourself.
Lots of us here could easily do the coding.
We are not going to do that, because it's what we do for a living ($$ ££).
You will learn nothing if we do it for you.

We will help with a specific coding problem, when you get to that stage.

Mike
wanraimi



Joined: 20 Feb 2013
Posts: 11

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Mar 17, 2013 9:40 am     Reply with quote

okey thank you... i'm very appreciate and will try to learn from starter..
wanraimi



Joined: 20 Feb 2013
Posts: 11

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Mar 19, 2013 11:11 am     Reply with quote

I got this coding from web, but when I run this program the display only 60rpm and 0rpm, why this happen.
Code:


#include <16F628a.h>
#device *=16

#FUSES NOWDT      //No Watch Dog Timer
#FUSES XT         //Crystal osc <= 4mhz
#FUSES PUT        //Power Up Timer
#FUSES NOPROTECT  //Code not protected from reading
#FUSES BROWNOUT   //Reset when brownout detected
#FUSES MCLR       //Master Clear pin enabled
#FUSES NOLVP      //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD      //No EE protection

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8)

// Global Variables
unsigned int  loops, meas_done;
unsigned long RPM, sensor_pulses;


#int_EXT
void  EXT_isr(void)
{
  if(!meas_done)
    {sensor_pulses++; } // Sensor pulses (TTL level) must arrieve at PIN_B0
}                     

#int_TIMER2
void  TIMER2_isr(void)
{
  if(loops)
    {loops--;}
  else
    {meas_done=true; }   
}

void start_measurement()
{
   meas_done=false;
   loops = 20;         // 50ms * 20 = 1000ms
                       // This is the measurement window time
   set_timer2(0);       
   enable_interrupts(INT_TIMER2);// To create a measurement window
   enable_interrupts(INT_EXT);   // Generate an interrupt every pulse
}                                // comming from the sensor         


void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);setup_wdt(WDT_288MS);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,194,16);// overflow aprox every 50ms
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   ext_int_edge( H_TO_L );   
   enable_interrupts(GLOBAL);
         
   while(TRUE)
      {
       start_measurement();
     
       do
         {
          delay_ms(1000);
         }while(!meas_done);
       
       disable_interrupts(INT_TIMER2);
       disable_interrupts(INT_EXT);
       RPM = sensor_pulses * 60;
       sensor_pulses = 0;
     
       printf("RPM %04lu", RPM);
      }
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Mar 19, 2013 11:23 am     Reply with quote

Of course it does.

You're measuring the number of pulses in one second.

So:-

<1 pulse/s is 0 RPM.
1 pulse/s is 60 RPM.
2 pulse/s is 120 RPM

And so on.

Ttelmah and others have already explained how it works, there's loads more in the link I gave you, and on this forum.

Mike

Edit Also learn how to use the code button.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 19, 2013 11:52 am     Reply with quote

The bold parts below show that you are running this in Proteus:
Quote:

#include <16F628a.h>
#device *=16

#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES MCLR //Master Clear pin enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8)
temtronic



Joined: 01 Jul 2010
Posts: 9182
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 19, 2013 12:01 pm     Reply with quote

great catch PCM pgrmr !

Now we can all take a break until he gets REAL hardware!

cheers
Jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Mar 19, 2013 2:07 pm     Reply with quote

Please tell us about the real hardware you're using, and your design specification:-

1) What type of encoder are you using, (bought in with part No., home made, No of slots etc.).
2) Range of speeds expected.
3) Update rate.
4) School project, final year assignment, commercial product, hobby job.
5) Anything else, your electronics/programming experience etc.

The more you tell us, the better we can help.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group