|
|
View previous topic :: View next topic |
Author |
Message |
spom
Joined: 12 Jul 2007 Posts: 32
|
stepping-motor control with PWM and L293D |
Posted: Tue Dec 04, 2007 5:07 am |
|
|
Hi,
I use a Pic 16F818, a no name bipolar stepping-motor with 50 steps, and a L293D(http://www.ortodoxism.ro/datasheets/texasinstruments/l293d.pdf).
I want to generate a PWM signal with the Pic, and then the motor should rotate 50 steps left, and then 50 steps right.
My code looks that way:
Code: |
#include <16f818.h>
#use delay(clock=8000000)
#fuses NOWDT,HS,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
void main()
{
setup_timer_2(T2_DIV_BY_4, 149, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(255L);
while(TRUE)
{
output_high(PIN_B0);
output_low(PIN_B1);
//50 steps and then turn around????
}
}
|
I don't know how to handle it that the motor change rotation after 50 steps.
Is the pwm right?
By the way: one inductor is connected to PIN 2 and 7 of the L293D and the other to PIN 10 and 15. Is that right?
Thanks! |
|
|
Ttelmah Guest
|
|
Posted: Tue Dec 04, 2007 5:17 am |
|
|
Basically, no.
The PWM, generates a continuous stream of pulses, allowing you to specify the mark space ratio. It does _not_ count pulses.
Almost exactly this question, was asked a while ago. A search should find it. Look for 'PWM stepper', asking the search to find 'all' terms, and you should get a number of threads about this. The simplest way for what you want,will be to ignore PWM completely.
Best Wishes |
|
|
spom
Joined: 12 Jul 2007 Posts: 32
|
|
Posted: Tue Dec 04, 2007 11:25 am |
|
|
Thanks!
But I've still had a problem. I connected one inductor with B0 and B1 of the PIC and the second inductor with B6 and B7 of the PIC.
Now my code:
Code: |
#include <16f818.h>
#use delay(clock=8000000)
#fuses NOWDT,HS,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
main()
{
int sequence[8] = {130,129,65,66};
int i=0;
int16 c=0;
while(1)
{
delay_us(2000);
output_B(sequence[i]);
i++;
if (i>3)
{
c++;
i=0;
}
if (c==500)
{
c=0;
delay_ms(1000);
}
}
}
|
But it doesn't work! Why?
Thank you for your help! |
|
|
Ttelmah Guest
|
|
Posted: Tue Dec 04, 2007 3:38 pm |
|
|
Try reversing one coil. If you have the phase of one coil reversed, it'll just sit and move back/forwards a tiny amount.
Best Wishes |
|
|
spom
Joined: 12 Jul 2007 Posts: 32
|
|
Posted: Sun Dec 09, 2007 6:38 am |
|
|
Sorry for my stupid questions again:
I changed my code accorgding to the example EX_STEP.C from CCS C and therefor my pin assignment:
Code: |
#include <16f818.h>
#use delay(clock=8000000)
#fuses NOWDT,HS,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#BYTE port_b = 6
#define FOUR_PHASE TRUE
#ifdef FOUR_PHASE
BYTE const POSITIONS[4] = {0b0101,
0b1001,
0b1010,
0b0110};
#else
BYTE const POSITIONS[8] = {0b0101,
0b0001,
0b1001,
0b1000,
0b1010,
0b0010,
0b0110,
0b0100};
#endif
drive_stepper(BYTE speed, char dir, BYTE steps)
{
static BYTE stepper_state = 0;
BYTE i;
for(i=0; i<steps; ++i) {
delay_ms(speed);
set_tris_b(0xf0);
port_b = POSITIONS[ stepper_state ];
if(dir!='R')
stepper_state=(stepper_state+1)&(sizeof(POSITIONS)-1);
else
stepper_state=(stepper_state-1)&(sizeof(POSITIONS)-1);
}
}
main()
{
BYTE speed, steps;
char dir;
while (TRUE)
{
speed = 20;
dir='F';
steps = 168;
drive_stepper(speed,dir,steps);
}
}
|
But the motor doesn't rotate. I feel an easy movement, but not 7.5°.
The contacts are right as the power supply fall down after switching on. So the motor need current.
Where is the fault?
Thanks! |
|
|
|
|
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
|