Society of Robots - Robot Forum
Software => Software => Topic started by: rabochid on November 27, 2010, 01:58:19 AM
-
hi I try to program a motor + encoder with a PIC16F877 using the timer1 interrupt the program running in the simulation (I use Proteus for the simulation) but when I implement the program ,without stopping the motor is running
speed max motor 550rev/m
encoder 120 cnt/rev
I use mikrobasic pro for pic
my code:
program Timer1_Interrupt
dim counter as word
sub procedure Interrupt()
if(PORTC=0x52) then
Inc(counter) ' Increment value of counter on every interrupt
end if
PIR1.TMR1IF = 0 ' clear TMR1IF
TMR1L = 0x00
end sub
main: ' Configure AN pins as digital I/O
PORTC = 0x50 ' Initialize PORTB
TRISC = 0x06 ' PORTB is output
T1CON = 1 ' Timer1 settings
PIR1.TMR1IF = 0 ' clear TMR1IF
TMR1H = 0x80 ' Initialize Timer1 register
TMR1L = 0x00
PIE1.TMR1IE = 1 ' enable Timer1 interrupt
counter = 0 ' initialize counter
INTCON = 0xC0 ' Set GIE, PEIE
while TRUE
if (counter =1000) then '
PORTC = 0x40 '
counter = 0 ' reset counter
end if
wend
end.
and here is my schema electrique:
-
sorry for the comment :P
-
I dont know C at all yet and your description is confusing me..... but im assuming "T1CON = 1" sets the TMR1ON bite. if that is the case, why not do that after you have set up interrupts and cleared flags etc?
" if (counter =1000) then " what if it is larger than 1000 when it hits that instruction?
I havn't done any C since highschool and it was only a bit of it. So im just stabbing in the dark with a spoon here.