Hi All
I had so touble on the Pulsout and tmr0 interrupt.
Can I send a pulse in 4.32 second to the stepper motor driver (UCN5804B)and at the same time doing tmr0 interrupt to do the time and date.
For example: 8am start run the stepper motor in period=4.32second and 5pm the stepper motor back to its initial position.
Below are my code: Please give advice thanks you very very much
The code is ok i think ,but the period is NOT what I want.
' The program is doing the solar tracker using stepper motor 1.8degree(5V,1A)
' ANd it must be track in 15 degree per hour
' The clock using TMR0 is to activate the tracker to start and stop.
' I will also need to display the time on the LCD
'
' For Example: When 8 am the stepper motor start run in 15 degree per hour.
' gearbox 100:1 RATIO
'
' This code that I write just run in period 65.53 milisecond.
' The code is NOT what i need.
'WHAT I NEED IS TO SEND PULSE IN 4.32 second.
'BELOW PULSOUT 0,6553 WHICH IS ONLY 65.53MILISECOND.
' Code below can run but the pulsout time period is not what I want (period=4.32 second)
hour VAR BYTE
bm VAR BYTE
bs VAR BYTE
day VAR WORD
month VAR BYTE
year VAR WORD
s VAR BYTE
t VAR BYTE
hour=0:minute=0:second=0:
'TMR0 will interrupt every 65,536 milliseconds
OPTION_REG=%01010111 ' prescaler= 1:256
INTCON=%10100000
ON INTERRUPT GoTo start
TRISB=0 ' all port b set to output
High 1 ' stepper motor stop (Enable=high)
High 2 ' CW direction
'************************************************* ************************************
main:
PulsOut 0, 6553 ' clock pulse to the stepper motor driver UCN5804B
' 65.53 milisecond
GoTo main
************************************************** ************************************
' Interrupt service routine (ISR)
Disable ' Disable interrupts during interrupt handler
start : t = t + 1 ' Count pieces of seconds
IF t < 15 Then exit ' 15 ticks per second (65.536ms pertick)
'**********Time elasped = 1 second ***********
t = 0
bs = bs + 1
IF bs >= 60 Then
bs = 0
bm= bm + 1
IF bm >= 60 Then
bm = 0
hour = hour + 1
IF hour >= 24 Then
hour = 0
EndIF
EndIF
EndIF
exit: INTCON.2 = 0 ' Reset timer interrupt flag
Resume
End
Bookmarks