View previous topic :: View next topic 
Author 
Message 
kiki
Joined: 06 Dec 2013 Posts: 21

Posted: Mon Mar 09, 2015 3:01 pm Post subject: steppermotor using atmega8(mach3) 


hi,everyone...
here i have done my project.i make program for stepper motor and the driver i used hbridge mosfet and the stepper motor running well but hahaha ,here is the problem: i have little problem when the stepper motor is running.the stepper motor sounded a bit rough and vibrates...
i am using stepper motor nema23 425 ozin dual shaft (1.8 degrees).and here the program i make :
$regfile = "m8def.dat"
$crystal = 12000000 'I used external crystal(11059200)
'$sim
Dim Count As Byte
Config Portc = Output
'============================
' portc= &b0000 A1
' ________ A2
' _________ B1
' __________ B2
'=============================
Config Pind.0 = Input
Config Pind.1 = Input
Config Pind.2 = Input
Config Pind.3 = Input
Config Pind.4 = Input
Config Portd.6 = Output
Config Portd.7 = Output
Config Pinb.0 = Input
Config Pinb.1 = Input
Stepper Alias Pind.0
Direction Alias Pind.1
Fullstep Alias Pind.2
Halfstep Alias Pind.3
Selector Alias Pind.4
Eror Alias Portd.6
Run Alias Portd.7
Atas Alias Pinb.0
Bawah Alias Pinb.1
Reset Stepper
Reset Direction
Reset Run
Set Selector
Count = 0
If Selector = 0 Then
Goto Auto
Else
Goto Manual
End If
'===============================================================================
Auto:
Do
If Fullstep = 0 And Halfstep = 0 Then
Do
Set Run
Waitms 100
Reset Run
Waitms 100
If Fullstep = 1 Or Halfstep = 1 Then Exit Do
Loop
End If
If Fullstep = 1 And Halfstep = 1 Then
Do
Set Run
Waitms 100
Reset Run
Waitms 100
If Fullstep = 0 Or Halfstep = 0 Then Exit Do
Loop
End If
If Fullstep = 0 And Halfstep = 1 Then Goto Full
If Halfstep = 0 And Fullstep = 1 Then Goto Half
Loop
'===============================================================================
Full:
Set Run
Waitms 1
Do
If Stepper = 1 And Direction = 0 Then
Incr Count
If Count = 9 Then Count = 1
If Count = 1 Then Portc = &B1001
If Count = 2 Then Portc = &B0001
If Count = 3 Then Portc = &B0101
If Count = 4 Then Portc = &B0100
If Count = 5 Then Portc = &B0110
If Count = 6 Then Portc = &B0010
If Count = 7 Then Portc = &B1010
If Count = 8 Then Portc = &B1000
Waitus 190
End If
If Stepper = 1 And Direction = 1 Then
Decr Count
If Count = 0 Or Count = 255 Then Count = 8
If Count = 8 Then Portc = &B1000
If Count = 7 Then Portc = &B1010
If Count = 6 Then Portc = &B0010
If Count = 5 Then Portc = &B0110
If Count = 4 Then Portc = &B0100
If Count = 3 Then Portc = &B0101
If Count = 2 Then Portc = &B0001
If Count = 1 Then Portc = &B1001
Waitus 190
End If
Portc = &B0000
Loop
'================================================================================
Half:
Set Run
Waitms 1
Do
If Stepper = 1 And Direction = 0 Then
Incr Count
If Count = 17 Then Count = 1
If Count = 1 Then Portc = &B1001
If Count = 2 Then Portc = &B1001
If Count = 3 Then Portc = &B1001
If Count = 4 Then Portc = &B0001
If Count = 5 Then Portc = &B0101
If Count = 6 Then Portc = &B0101
If Count = 7 Then Portc = &B0101
If Count = 8 Then Portc = &B0100
If Count = 9 Then Portc = &B0110
If Count = 10 Then Portc = &B0110
If Count = 11 Then Portc = &B0110
If Count = 12 Then Portc = &B0010
If Count = 13 Then Portc = &B1010
If Count = 14 Then Portc = &B1010
If Count = 15 Then Portc = &B1010
If Count = 16 Then Portc = &B1000
Waitus 85
End If
If Stepper = 1 And Direction = 1 Then
Decr Count
If Count = 255 Or Count = 0 Then Count = 16
If Count = 16 Then Portc = &B1000
If Count = 15 Then Portc = &B1010
If Count = 14 Then Portc = &B1010
If Count = 13 Then Portc = &B1010
If Count = 12 Then Portc = &B0010
If Count = 11 Then Portc = &B0110
If Count = 10 Then Portc = &B0110
If Count = 9 Then Portc = &B0110
If Count = 8 Then Portc = &B0100
If Count = 7 Then Portc = &B0101
If Count = 6 Then Portc = &B0101
If Count = 5 Then Portc = &B0101
If Count = 4 Then Portc = &B0001
If Count = 3 Then Portc = &B1001
If Count = 2 Then Portc = &B1001
If Count = 1 Then Portc = &B1001
Waitus 85
End If
Portc = &B0000
Loop
'===============================================================================
Manual:
Count = 0
Do
If Atas = 1 Then
Set Run
Incr Count
If Count = 9 Then Count = 1
If Count = 1 Then Portc = &B1001
If Count = 2 Then Portc = &B0001
If Count = 3 Then Portc = &B0101
If Count = 4 Then Portc = &B0100
If Count = 5 Then Portc = &B0110
If Count = 6 Then Portc = &B0010
If Count = 7 Then Portc = &B1010
If Count = 8 Then Portc = &B1000
Waitus 300
End If
If Bawah = 1 Then
Set Run
Decr Count
If Count = 0 Or Count = 255 Then Count = 8
If Count = 8 Then Portc = &B1000
If Count = 7 Then Portc = &B1010
If Count = 6 Then Portc = &B0010
If Count = 5 Then Portc = &B0110
If Count = 4 Then Portc = &B0100
If Count = 3 Then Portc = &B0101
If Count = 2 Then Portc = &B0001
If Count = 1 Then Portc = &B1001
Waitus 300
End If
If Atas = 0 And Bawah = 0 Then Portc = &B0000
Reset Run
Loop
Return
End
========================================
and the other problem,how to make portc not &b1111 or portc &b0000 but the portc is flowing..
so do anyone want to help me... how to make my program be perfectly, thanks.. 

Back to top 


bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg  Netherlands

Posted: Mon Mar 09, 2015 4:41 pm Post subject: Small wait between steps... 


Oke. What if you put a small wait between the steps. Have done the same and a waitus 40 did the trick here.
And perhaps you could put $hwstack, $swstack and $framesize inside your program.
Have fun
Ben Zijlstra 

Back to top 


albertsm
Joined: 09 Apr 2004 Posts: 5171 Location: Holland

Posted: Mon Mar 09, 2015 10:15 pm Post subject: 


instead of :
If Count = 1 Then Portc = &B1001
If Count = 2 Then Portc = &B0001
If Count = 3 Then Portc = &B0101
you could consider a lookup table and Lookup() function.
This has the advantage that each step executes in the same time, no matter the value.
And you can even reuse some of the tables.
As Ben suggested, there is a time required between the steps. voltage and delay/frequency can be very important. you can also change delay once stepper is moving.
you could set portc to input when done, with port value to 0 so it becomes high Z. _________________ Mark 

Back to top 


kiki
Joined: 06 Dec 2013 Posts: 21

Posted: Tue Mar 10, 2015 7:23 am Post subject: 


Oke thanks, I will test again the program..but I also have use the table() function and it same.because mach3 software that I use the steps signal can move fast and slow so in step signal is slowing down the stepper motor have vibrates. And I see the microstepping table for stepper motor it have voltage + , voltage 0, and voltage  so I am become confused about that. So in my mind I want to make my program/micro not have voltage + and not have voltage  because if we write the program portc=&b 1111 , the voltage of the portc must be+ and if we write the program portc=&b 0000 so the voltage of portc must be  right?
In my program I made: if count = 1 then portc=&b1001
In last execution I must put the portc=&b0000
Because if not my hbridge mosfet can crash their voltage and the mosfet must be broken. So I am thinking I want the I/o port not working/flowing their voltage but how...I have no idea.help me please friends. 

Back to top 


