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 CCS Technical Support

PWM speed control / rpm meter problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PWM speed control / rpm meter problem
PostPosted: Thu Jan 20, 2011 6:48 am     Reply with quote

hi
I'm using pic16f877a to drive a motor at different speeds using PWM, and it works fine.
Now I'm using the same PIC to measure the motor speed using a pair of LED/PD, so I am measuring the speed depending on the frequency of the output signal, and that also works fine when I use a pulse wave to simulate the output signal (when I change the pulse wave frequency the speed reading changes).
My problem is that I need to control this speed depending on a threshold value of the speed, and I can't do that on simulation.
So I need a way to convert my variable PWM signal to a variable frequency signal.
i.e. when I change the duty cycle, the output frequency should change.

Is that possible ??
temtronic



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

View user's profile Send private message

PostPosted: Thu Jan 20, 2011 7:03 am     Reply with quote

Simple answer, yes.
If your 'speed sensor' routine (input speed), is timer based, you'll get a value for the period between the optocoupler 'blips'. Configure a timer to max out at max speed (ie 16 bits = max rotation). Then use the 'counts' as an input to the PWM portion of your program. You should already have a table of how PWM values control the motor.
Now you'll have a similar table for the speed sensor.
Obviously it won't be a simple replacement, some math will be involved to get the right motor speed for your setup, a simple lookup table might work.

Don't ask me how to setup your 'simulator' for this though, I only work in the real world as all simulators are full of 'bugs'.
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Fri Jan 21, 2011 7:52 am     Reply with quote

thanks
I'm using the following routine, can't figure out a way to follow your instructions:

Code:

#INT_EXT
void ext_isr()
{
N++;
}



int get_speed(void)
{
   float speed,m;
   long t=0;
   N=0;
   set_timer1(0);

   while(t<=62500){   // delay 0.5s
   t=get_timer1();
   }
   m=N;
   speed=m*0.5732;
   return(speed);
}
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 21, 2011 9:30 am     Reply with quote

Just check all the examples that CCS gives us! There's one about measuring 'pulse width' or search the forum here for 'tachometer', or 'pulse width'.
First sensor pulse triggers the ISR, 2nd stops it, the timer registers will be the 'count' of timer ticks for that duration.Use that number to configure your PWM function.
Obviously you'll have to do some math to get the right speed vs. sensor input and set limits ! ie: when no pulses arrive, you're stopped NOT full speed !!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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