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

DC motor control with PWM
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mcad



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 4:56 pm     Reply with quote

Ok, sir.
I am going to try what you suggested in lab tomorrow.
Thanks again for your helps...
regards, and best wishes
mcad



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 5:08 pm     Reply with quote

Upps,
Sir, I noticed something that's why I have decided to increment and decrement 1.
The reason is that we do not know the value of the duty if the value is taken from the ADC channel.
So, suppose that it is always less than 10. So, does not this create a problem, sir ?

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 5:12 pm     Reply with quote

Here is a program that shows how to read the ADC and use the value
to set the PWM duty cycle:
http://www.ccsinfo.com/forum/viewtopic.php?t=26308&start=5
This uses the PWM in 8-bit mode.
mcad



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 5:21 pm     Reply with quote

Sir, thanks for your link but I have already known it.
I just ask that if suppose that the value taken from the ADC as a digital is smaller than ten regularly, so and the user want to slow down the motor by pressing the button which decrement is 10 times, what will happen ?

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 5:25 pm     Reply with quote

I don't understand what you want. You have ADC input and you have
button input. Which method is used to get the pwm duty cycle ?
mcad



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 5:30 pm     Reply with quote

Sir,
I am trying to perform that the user can change the speed of the DC motor via the user buttons (speed up and slow down buttons).
So, when the user press the related button, the operation affects the value of the duty cycle, does not it ? So, I mean if the dtuy cycle is smaller than the value which is requested by the user as a decrement, what does happen ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 6:07 pm     Reply with quote

This is a coding problem. You need to learn how to do this.
Here's an example. You only decrement by 10 if the current pwm
value is 10 or greater. If it's less than 10, then just set the pwm to 0.
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#define DECREMENT_VALUE  10

//======================================
void main()
{
int8 duty_cycle;

if(duty_cycle >= DECREMENT_VALUE)
   duty_cycle -= DECREMENT_VALUE;
else
   duty_cycle = 0;

set_pwm1_duty(duty_cycle);

while(1);
}
Guest








PostPosted: Mon Nov 26, 2007 2:40 am     Reply with quote

Hi Sir,
Thank you for your reply and all clarifications. By the way, sorry for my late reply as I fell asleep.

I am going to apply your suggestions with my own thoughts today.

Again thanks,
regards
mcad



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 2:42 am     Reply with quote

Upps,
Sorry, it seems that I am continuing to sleep.
I wrongly sent the reply as a Guest wiothut logging in.
Again sorry.
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 Previous  1, 2
Page 2 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