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

16F684 pwm motor control

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







16F684 pwm motor control
PostPosted: Wed Jul 29, 2009 7:19 am     Reply with quote

I'm using the pwm module of pic16f684 to control the speed of a DC motor. The only problem is when the duty cycle is zero the motor is still running. Could someone help me.

thank you
Ttelmah
Guest







PostPosted: Wed Jul 29, 2009 7:38 am     Reply with quote

Start by disconnecting the motor, set a duty cycle of zero, and measure what is coming out of the PWM pin. If you have a scope, use this, otherwise, wire up a LED, with a current limiting resistor, and attach this to the pin. Is it off?. If it is, then the problem is in the hardware you are using to drive the motor. Perhaps the transistor is not quite switching off?. If it is on, then simplify the code down to just a routine to setup the timer, and setting the duty cycle to zero. Does this solve the problem?. If not, then the 'odds' are that possibly the PWM output pin itself has been damaged. Classic for doing this, is using a transistor to drive a motor/inductor, without a 'trap' diode across it, or some other circuit to catch flyback. Without this, when the drive switches off, the inductance in the coil (and the generator effect for a motor), can generate a massive voltage, having nowhere to 'go', and eventually finds a route, from the collector to the base of the transistor, then from this into the output of the PIC....

Best Wishes
delifadzli



Joined: 12 Apr 2010
Posts: 27

View user's profile Send private message

PostPosted: Sun Jun 06, 2010 12:43 pm     Reply with quote

Code:
#include <16F877A.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use Delay(clock=20000000)

#include "C:\Users\deli\Desktop\satu\brum\Flexlcd2.c"

#define medium   500L
#define slow     100L
#define fast     700L

//#define medium          125L
//#define slow            63L
//#define fast            240L

void main()
{
  int16 temp_adc;
  float temp;
  int16 pwm_duty;




   setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(PIN_A1);
   set_adc_channel(1); //read analog input from channel 1
   output_low(PIN_C2);    // Set CCP1 output low
   setup_ccp1(CCP_PWM);   // Configure CCP1 as a PWM
   setup_timer_2(T2_DIV_BY_4, 249, 1);         // 5khz
   set_pwm1_duty(medium);  // Set for 50% duty cycle

   lcd_init();

   lcd_putc("\fsuhu leni:\n");

   while(1)

   {
    temp_adc = read_adc();

    temp = 5.00*temp_adc*100.00/1023.00;
    lcd_gotoxy(1,2);
    printf(lcd_putc,"%f",temp);
    delay_ms(3000);



     if ((temp_adc < 58) && (input(PIN_B7)==1))

      {
         temp_adc = slow;
      }
      else if ( (temp_adc >= 58) && (temp_adc < 70) && (input(PIN_B7)==1))
      {
         temp_adc = medium;
         }
      else if ((temp_adc >= 70) && (input(PIN_B7)==1))
         temp_adc = fast;

       else
       temp_adc = 0;

    set_pwm1_duty(temp_adc); //Change duty cycle and adjust
        }

}

Isn't in this code...I can produce zero speed--means motor turn off...I also had the same problem....other routine...seems to be ok, just for the turning off the motor- it cause the motor to run at full speed...?? why

input pinb7 just additional pin that i planned to use for another sensor..but in this time i just use a wire....
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