PIC16F84A using pulsout and TMR0
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
Thanks for the reply....some question below....
Hi all
Thanks to HenrikOlsson and mister_e that give me the marvelous advice.
I had tested it on the lab but the period is 4.6 and something 4.5. After I change it to For 0 To 2020 it will work 4.3 and something 4.2.
I just measure it using stopwatch.
For accuracy of the clock I will assign TMR0 = 12 {((fosc/4)*(256-12)*256)=0.9994}. Is that OK????
Mister_e has suggest me to use 10us pause. Which mean that the for loop have to increase to 216000 rite???
Sorry..I don't undestand the statement below:-
*****If you need accuracy, you may decide to fine-tune it using MPLAB stopwatch OR measure it using an extra i/o and a scope.
Another solution... Use 2 variables, flags and 1 Timer.*****************
not seeing some code . . .
Hi DragonBall_6,
As I didn't see it listed in your code, do you have appropriate define osc X in your code and question 2 is have you set config fuses to HS when trying to use fast oscillator speed?
JS
same question again eeprom finish
If I doesnt want to use external eeprom and I had used up all the internal eeprom space. As I know there was a way to store the data in the program like below:-
asm:
da:1,2,23
endasm
I do not familiar with this could any one one lead me thru this method? Thank
I just want to store 200 data in there.
Thanks