Stepper control with 16f877a and l6219

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
Its_Alive
Posts: 27
Joined: 01 May 2008 20:46

Stepper control with 16f877a and l6219

#1 Post by Its_Alive » 16 Nov 2012 17:15

Hi all, am trying to control a single 57BYG06 stepper motor using a 16f877a and L6219 motor control ic.
The problem I am having it that I don't know what signal I should be passing to inputs Phase 1 and Phase 2 on the control chip. any help with this would be greatly appreciated as I have been trawling internet and wracking my tiny brain for 2 days now :( .
Thanks in advance.

thunderer
Posts: 54
Joined: 07 Sep 2011 15:55

Re: Stepper control with 16f877a and l6219

#2 Post by thunderer » 17 Nov 2012 23:28

Hi,
Look at page 5 (Figure 1), then look at page 7 Table 3 pin# 10, 16 explanation. This is how you will drive your motor. You have a bipolar motor so the sequence shall be like the levels in the table (see this page http://mechatronics.mech.northwestern.e ... rive1.html). It is from another ST chip, the well known L293 driver.

In your case: if Phase 1 is High, then Out1A is High, Out1B is Low. A Phase 1 Low will give you the reverse levels. Same for Phase 2.

You have to program Phase 1 and 2 to have these levels at Out1 (A and B) and Out2 (A and B). The frequency of pulses will depend on your motor characteristics. I would stay between 100 and 500Hz if you do not have this info.

See this link too (http://www.shinano.com/motors/docs/SKC_ ... ration.pdf). Table 8.1 dual phase is your case.

Let me know if this helped, I love steppers, though I use them extremely rare.
The one who asks, learns and explores may look stupid for a second. The one who does not do that, stays stupid forever.

User thunderer on: RHCforum, elforum, mikroelektronika/Libstock, HOD, fanowar

Its_Alive
Posts: 27
Joined: 01 May 2008 20:46

Re: Stepper control with 16f877a and l6219

#3 Post by Its_Alive » 18 Nov 2012 03:08

Hi, thanks for reply and yes that helped a lot i now have motor turning slowly but squeling every time portd pin 1 goes high. Here is code i have so far (very basic but i'm getting there) if I change Delay_ms to get higher speed motor tries to turn in both dirs at same time. Can you see what i'm doing wrong.

Thanks again


Code: Select all

program Motor_control
sub procedure Delay
    Delay_ms(300)
end sub

main:

    PORTD = 0
    TRISD = 0

    while true
    
        PORTD = %11000101        
        Delay
        PORTD = %01000110        
        Delay
        PORTD = %00001010        
        Delay
        PORTD = %10001001        
        Delay
        
    wend
end.

Its_Alive
Posts: 27
Joined: 01 May 2008 20:46

Re: Stepper control with 16f877a and l6219

#4 Post by Its_Alive » 18 Nov 2012 16:32

Hi all, is there nobody else out there with any ideas on this. I have been struggling with this for days now and it's getting very frustrating. Im sure at least half of the 50 people that have viewed this thread could do this in there sleep, how are newbs going to learn if nobody helps them out, sorry if i'm being stupid and impatient but I have tried all ideas that I could come up with and getting no further.

Thanks in advance.

travismdev
Posts: 3
Joined: 18 Nov 2012 04:32
Location: Vegas
Contact:

Re: Stepper control with 16f877a and l6219

#5 Post by travismdev » 18 Nov 2012 19:32

I would check your wiring from the stepper to the driver making sure and that your supply voltage is correct for this stepper motor. I had the same issue with a A4988.

thunderer
Posts: 54
Joined: 07 Sep 2011 15:55

Re: Stepper control with 16f877a and l6219

#6 Post by thunderer » 18 Nov 2012 22:32

Its_Alive wrote:Hi, thanks for reply and yes that helped a lot i now have motor turning slowly but squeling every time portd pin 1 goes high. Here is code i have so far (very basic but i'm getting there) if I change Delay_ms to get higher speed motor tries to turn in both dirs at same time. Can you see what i'm doing wrong.
If the motor loses direction is because it may lose/skip steps (your frequency is too big, what delay have you put there?). Remember these motors have a big inertia, you have to allow that mechanical transition to happen.

I do not understand about the PORTD.1 pin going high problem, to me looks like you used PORTD.7 = PHASE 1, PORTD.6 = PHASE 2.

The frequency you've choosen (below) does seem OK for testing, low so no problems. Let us know your connection diagram, otherwise we guess (like I did below where PORTD.7 = PHASE 1, PORTD.6 = PHASE 2).

See my table below to check if you did it similarily:

L6219 pins status depending on the PHASE signals:

__________OUTPUTS__| INPUTS |_____PORTD setup bits considering only the PHASE signals
pin#_____1 | 21 | 2 | 5 | 15 | 10
pin status L | H | L | H | L | L - STEP1 = 0101 - PORTD = 00xx xxxx
pin status L | H | H | L | L | H - STEP2 = 0110 - PORTD = 01xx xxxx
pin status H | L | H | L | H | H - STEP3 = 1010 - PORTD = 11xx xxxx
pin status H | L | L | H | H | L - STEP4 = 1001 - PORTD = 10xx xxxx
Its_Alive wrote:

Code: Select all

program Motor_control
        PORTD = %11000101        
        Delay
        PORTD = %01000110        
        Delay
        PORTD = %00001010        
        Delay
        PORTD = %10001001        
        Delay
Last edited by thunderer on 19 Nov 2012 01:28, edited 8 times in total.
The one who asks, learns and explores may look stupid for a second. The one who does not do that, stays stupid forever.

User thunderer on: RHCforum, elforum, mikroelektronika/Libstock, HOD, fanowar

thunderer
Posts: 54
Joined: 07 Sep 2011 15:55

Re: Stepper control with 16f877a and l6219

#7 Post by thunderer » 18 Nov 2012 22:35

Its_Alive wrote:Hi all, is there nobody else out there with any ideas on this. I have been struggling with this for days now and it's getting very frustrating. Im sure at least half of the 50 people that have viewed this thread could do this in there sleep, how are newbs going to learn if nobody helps them out, sorry if i'm being stupid and impatient but I have tried all ideas that I could come up with and getting no further.

Thanks in advance.
Remember, this is a microcontrollers' forum, and users are voluntarily answering, no obligation to get involved.

Plus, some of us, in the weekend spend time with families or travelling... Be patient!
The one who asks, learns and explores may look stupid for a second. The one who does not do that, stays stupid forever.

User thunderer on: RHCforum, elforum, mikroelektronika/Libstock, HOD, fanowar

Ali Jounaki
Posts: 1
Joined: 17 Nov 2017 14:54

Re: Stepper control with 16f877a and l6219

#8 Post by Ali Jounaki » 17 Nov 2017 15:05

hi
i have this problem too.
i'm using stm32f103cb micro. and l6219 step motor and i have a 4 wire step motor.
i write this code but the motor moves just 1 step and stops.
i'll appreciate that someone help me in this case.
sorry to tell this issue on your topic.

Code: Select all

#include <stm32f10x.h>



TIM_TimeBaseInitTypeDef TIM_structure;
TIM_OCInitTypeDef pwm_structure;
GPIO_InitTypeDef GPIO_structure;



int i;

void hse_config(void);

void timer_config(void);

void pwm_config(void);

void rcc_config(void);

void gpio_config(void);



int main() {
	
	
	hse_config();
	
	rcc_config();
	
	gpio_config();
	
	GPIO_ResetBits(GPIOB,GPIO_Pin_1|GPIO_Pin_10);
	GPIO_ResetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_11);
	
  
	
	
	
while(1){
	
  timer_config();
	
  pwm_config();	

}
}


void hse_config(void) {
	
	RCC_HSEConfig(RCC_HSE_ON);
	RCC_WaitForHSEStartUp();
	RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);
	RCC_PLLCmd(ENABLE);
	while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY==RESET));
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
	
}

void timer_config(void) {
	
	
	
	
	TIM_structure.TIM_Prescaler=0;
	TIM_structure.TIM_CounterMode=TIM_CounterMode_Up;
	TIM_structure.TIM_Period=159;
	TIM_structure.TIM_ClockDivision=TIM_CKD_DIV1;
	TIM_structure.TIM_RepetitionCounter=0;
	
	
	TIM_TimeBaseInit(TIM3,&TIM_structure);

	TIM_TimeBaseInit(TIM2,&TIM_structure);
	
	
}

void pwm_config(void) {
	
	
	
	
	pwm_structure.TIM_OCMode=TIM_OCMode_PWM1;
	pwm_structure.TIM_OutputState=TIM_OutputState_Enable;
	pwm_structure.TIM_Pulse=79;
	pwm_structure.TIM_OCPolarity=TIM_OCPolarity_High;
	
	
	TIM_OC2Init(TIM3,&pwm_structure);
	TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);
	
	TIM_ARRPreloadConfig(TIM3,ENABLE);
	TIM_Cmd(TIM3,ENABLE);
	
	
	for(i=0;i<=5000;i++) /*delay for 5us*/
	{
		
		
	}
	
	pwm_structure.TIM_OCMode=TIM_OCMode_PWM1;
	pwm_structure.TIM_OutputState=TIM_OutputState_Enable;
	pwm_structure.TIM_Pulse=79;
	pwm_structure.TIM_OCPolarity=TIM_OCPolarity_High;
	
	
	TIM_OC3Init(TIM2,&pwm_structure);
	TIM_OC3PreloadConfig(TIM2,TIM_OCPreload_Enable);
	
	TIM_ARRPreloadConfig(TIM2,ENABLE);
	TIM_Cmd(TIM2,ENABLE);
	
}

void rcc_config(void){
		
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2|RCC_APB1Periph_TIM3,ENABLE);
	
}

void gpio_config(void){
	
	
	GPIO_InitTypeDef GPIO_structure;
	
	
	GPIO_structure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_10|GPIO_Pin_11;
	GPIO_structure.GPIO_Mode=GPIO_Mode_Out_PP;
	GPIO_structure.GPIO_Speed=GPIO_Speed_50MHz;
	
	GPIO_Init(GPIOB,&GPIO_structure);
	
	GPIO_structure.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_7;
	GPIO_structure.GPIO_Mode=GPIO_Mode_AF_PP;
	GPIO_structure.GPIO_Speed=GPIO_Speed_50MHz;
	
	GPIO_Init(GPIOA,&GPIO_structure);
	
}


here is my code.
thank you all

Post Reply

Return to “mikroBasic PRO for PIC General”