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: