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

Two PWM slopes using one 16F690 for microstepping

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



Joined: 07 Feb 2010
Posts: 39

View user's profile Send private message

Two PWM slopes using one 16F690 for microstepping
PostPosted: Tue Mar 02, 2010 7:23 am     Reply with quote

PCW 4.104 PIC16F690

I am working on a microstepping step motor drive.

There is a need for simultaneous rising and falling PWM pulses. One way to do this is to steer the PWM to, say, pin C5 and then reproduce the PWM using:

input_state(pin_C5); and !input_state(pin_C5);

Works but has jitter problems, even at low speeds.
Code:

setup_timer_2(T2_DIV_BY_16, period, 16);

setup_ccp1(CCP_PWM | CCP_PULSE_STEERING_A ); //pin C5 ramp up

for(;;)
{
   set_pwm1_duty(q);
 
  if(q>period)
   {
      q=0;
   }

   Pup= input_state(pin_C5);
   Pdn=!input_state(pin_C5);

//   Code generating drive signal sequences

}//end for

The problem is that the Pup and Pdn signals have a lot of variable jitter. The PWM at pin C5 is very smooth.

How can I get smooth Pup and Pdn PWM's from a single 16F690?
Thanks,
Boyce
_________________
boyceg1@gmail.com
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Tue Mar 02, 2010 9:18 am     Reply with quote

This can't possibly work. The built-in PWM is automatic once a duty cycle is set, whereas the software has to read the pin and set another pin, and you can't entirely control the rate at which it runs.

The right way to do this is with an external inverter.

But if you really are allergic to any external hardware, you could (maybe) use an on-board comparator comparing the PWM output with a fixed reference. It's a mighty kludge but I think it would work, allowing for some delay for the comparator to operate.
Guest








PostPosted: Tue Mar 02, 2010 10:48 am     Reply with quote

Quote:
This can't possibly work. The built-in PWM is automatic once a duty cycle is set, whereas the software has to read the pin and set another pin, and you can't entirely control the rate at which it runs.


It works well at *very* slow speeds. I could use and external inverter for pin C5, but need to feed that response back to the 4 phases of the motor.

I was hoping for a better software solution using the on chip PWM. I will look at chips that have two PWM's.

External driver looks like the best solution. However, the very low speed performance will be good enough for one of my applications.

There is a way to microstep drive two winding stepping motors using only one PWM. However, the required two H-bridge's are a bit hardware intensive, too.

Thanks,
Boyce
Boyce



Joined: 07 Feb 2010
Posts: 39

View user's profile Send private message

Code to help microstep stepping motors
PostPosted: Tue Mar 02, 2010 10:15 pm     Reply with quote

Code:
/*******************************
PCW 4.104  PIC 16F690
This gives me the performance I am looking for to do microstepping.
It gives two sets of two outputs.  Each set has one rise while the
other falls as needed to microstep from one motor pole to the next.
Boyce
********************************/

for(;;)
{  if(q>=period){q=0; C++; }

   delay_ms(1);

//P1A=C5   P1B=C4    P1C=C3    P1D=C2 

   if(C==0)
   {  set_pwm1_duty(q);
      setup_ccp1(CCP_PWM_L_H | CCP_PULSE_STEERING_A | CCP_PULSE_STEERING_B);
   }//end if(C=0)                                                         
 
   if(C==1)
   {  set_pwm1_duty(q);
      setup_ccp1(CCP_PWM_H_L | CCP_PULSE_STEERING_A | CCP_PULSE_STEERING_B);
   }//end if(C=1)

   if(C==2)
   {  set_pwm1_duty(q);
      setup_ccp1(CCP_PWM_L_H | CCP_PULSE_STEERING_C | CCP_PULSE_STEERING_D);
   }//end if(C=1)

   if(C==3)
   {  set_pwm1_duty(q);
      setup_ccp1(CCP_PWM_H_L | CCP_PULSE_STEERING_C | CCP_PULSE_STEERING_D);
   }//end if(C=1)

   if(C>=4) C=0;

   q++;

  }//end for

_________________
boyceg1@gmail.com
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