View previous topic :: View next topic |
Author |
Message |
Boyce
Joined: 07 Feb 2010 Posts: 39
|
Two PWM slopes using one 16F690 for microstepping |
Posted: Tue Mar 02, 2010 7:23 am |
|
|
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
|
|
Posted: Tue Mar 02, 2010 9:18 am |
|
|
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
|
|
Posted: Tue Mar 02, 2010 10:48 am |
|
|
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
|
Code to help microstep stepping motors |
Posted: Tue Mar 02, 2010 10:15 pm |
|
|
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 |
|
 |
|