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

Different duty cycles on PWM ports

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



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

Different duty cycles on PWM ports
PostPosted: Thu Oct 04, 2007 4:00 pm     Reply with quote

Hi.
Is it possible to output 2 different duty cycles on say pwm pin RB1, RB2 at the same time using the following type of code?

Code:
output_high(pin_C6);
                output_high(pin_C7);
                set_pwm1_duty(40);
                setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_C);   
                set_pwm2_duty(70);
                setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_D);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 4:44 pm     Reply with quote

I assume this is for a 16F886. The data sheet shows that there is only
one PWM generator driving pins P1A-P1D. This means there is only
one frequency and one duty cycle possible.

There are some options available with the output pins. You can invert
some of the outputs, so they would have the opposite duty cycle.
The enhanced PWM module is intended as a motor driver circuit.
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Thu Oct 04, 2007 5:29 pm     Reply with quote

I am using one 16f886 to drive 2 h-bridges. Each bridge needs 1 pwm input but the duty cycles need to be different as i am driving a small robot that has 2 motors. Running in the forward state the speed of the motors are different even with the same pwm output, so the robot doesn't run straight. Have you got any advice as to solve this problem??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 5:48 pm     Reply with quote

It sounds like you need a tachometer on each motor, and you need a
control loop in your program to maintain the correct speed on each one.
I haven't done anything in robotics. The robotics people may have other
suggestions.
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Thu Oct 04, 2007 6:22 pm     Reply with quote

I want to manually do the speed control with the normal analog joysticks that you find in remote's. I would prefer to use the input from the analog to determine the speed of each motor so it would be a completely manual thing. Do you have any sugestion or idee if it would be possible??
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Fri Oct 05, 2007 2:24 am     Reply with quote

as pcm said u could use a control loop and a tacho on each motor. the adc will set the referance speed from the joystick and the the control loop adjusts each motors speed via the pwm till the motor is running at the correct speed.

below is some code i wrote in c but not CCS for a dc motor controller. it would keep the motor at a steady speed even with the load on the motor being changed. the adc sets the referance speed and then ther is a PIC controlled to control the dutycycle of the pwm.

Code:
      Reference_Speed = adc_result/2;         

      if (Reference_Speed > 1500)
      Reference_Speed = 1500;
   
      if (Reference_Speed < 300)
      Reference_Speed = 300;

         
         if (Speed_Flag == 1)
         {
            Previous_Error_Speed = Error_Speed;

               Error_Speed = Reference_Speed - Actual_Speed;
         
                  KpN = 1;
                  KpD = 1;
           
               Proportional_Factor = Error_Speed * KpN / KpD;

                  KiN = 1;
                  KiD = 10;   
     
               Integral_Factor = Integral_Factor + (KiN * Error_Speed / KiD);
         
               if    (Integral_Factor > 30000)
               Integral_Factor = 30000;
         
               if (Integral_Factor < -30000)
               Integral_Factor = -30000;   
         
                  KdN = 1;
                  KdD = 1;

               Derivative_Factor = (Error_Speed - Previous_Error_Speed) * KdN / KdD;

               dutyCycleCount = Proportional_Factor + Integral_Factor + Derivative_Factor;

            Speed_Flag = 0;     
         }

      if (dutyCycleCount > 225)
      dutyCycleCount = 225;

      if (dutyCycleCount < 40)
      dutyCycleCount = 40;

         lcd_goto(0x00);
         printf("Ref SPD %4d RPM", Reference_Speed);

         lcd_goto(0x40);
         printf("Act SPD %4d RPM", Actual_Speed);

      DAC0 = Actual_Speed;
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Sat Oct 06, 2007 5:11 pm     Reply with quote

Thanks for the reply but for my purpose it would not work as i am not able to use any back reference from the motor. Basically all i want to do is control 2 DC motor's H-bridge PWM pins at different speeds from the pic via a remote control where the joystick is mounted on. I tried using pwm outputs from the standard pwm pins but as they cannot give out different duty cycles at the same time, i would have to find some other solution as maybe software pwm via 4 other pins that changes with the analog from the joystick.
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