Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

two stepper independent

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 112

poland.gif
PostPosted: Wed Feb 01, 2017 8:30 pm    Post subject: two stepper independent Reply with quote

Hello,

i would like to run two independent steppers and decided to use timer1 for 1-st stepper and timer2 for second stepper.
The code lokks like

Code:
$regfile = "m8adef.dat"  
$crystal = 8000000        

Config Timer1 = Timer, Prescale = 1, Compare_A = Disconnect, Clear_Timer = 1
Config Timer2 = Timer, Prescale = 1, Compare = Disconnect, Clear_Timer = 1
Config Twislave = &H20,Btr = 1,Bitrate = 100000,Gencall = 1

Dim temp1 as Integer, temp2 as Integer, fast as Integer, slow as Integer
Dim stan As Byte

$baud = 19200                                        
$hwstack = 32                                          
$swstack = 10                                          
$framesize = 40                                      

Config Pinb.1 = Output 'stepper1
Config Pinb.3 = Output 'stepper2

stepper1 Alias Portb.1
stepper2 Alias Portb.3
On Compare1a run_stepper1
On compare2 run_stepper2
Enable Interrupts            

  enable timer2 ' ??? should it be

stan=10
fast=350
slow=600

Do
 'slow down stepper1
 if stan=0 then
  stan=10
  for temp1=fast to slow step 10
   Compare1a=temp1
   waitus 200
  next temp1
  disable Compare1a
 end if

 'slow down stepper2
 if stan=3 then
  stan=10
  for temp2=fast to slow step 10
   Compare2=temp2
   waitus 200
  next temp2
  disable compare2
 end if

 'start stepper1
 if stan=1 then
  stan=10
  Enable Compare1a
  for temp1=slow to fast step -10
   Compare1a=temp1
   waitus 200
  next temp1
 end if

 'start stepper2
 if stan=4 then
  stan=10
  Enable compare2
  for temp2=slow to fast step -10
   Compare2=temp2
   waitus 200
  next temp2
 end if
Loop

Twi_stop_rstart_received:
Return
Twi_addressed_goread:
Return

Twi_addressed_gowrite:
Return

Twi_gotdata:
  stan=twi
Return

Twi_master_needs_byte:
 'Twi_btr
 Twi = stan
Return

Twi_master_need_nomore_byte:
Return

run_stepper1:
 Toggle stepper1  
Return

run_stepper2:
 Toggle stepper2  
Return
 



The problem is that for the 1-st stepper it works, but this code for the second stepper does not. Surely i did something wrong, but what should i change?
Previously i tested only timer1 for both steppers but UNsuccessful, because second stepper didn't rotate if the firs did. when first stopped second continued ...

Any help would be appreciated.

Martin

(BASCOM-AVR version : 2.0.7.6 , Latest : 2.0.7.8 )
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Wed Feb 01, 2017 10:28 pm    Post subject: Reply with quote

TIMER2 like TIMER0 is also 8BIT and can count only to 255.
So it can`t handle your "slow=600" and even "fast=350" Very Happy

Answear to the question in code - "Enable Timer2" means "enable interrupt when Timer2 overflow"
If Clear_Timer=1 is used this will never happend Very Happy
Back to top
View user's profile Visit poster's website
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 112

poland.gif
PostPosted: Thu Feb 02, 2017 4:25 pm    Post subject: Reply with quote

Thank you! I've so many times checked where could bug(or bugs..) be that i didn't notice
that timer2 is 8bit! Now works fine!

<SOLVED>
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum