Author Topic: programme for motor+encoder in pic16f877a  (Read 4239 times)

0 Members and 1 Guest are viewing this topic.

Offline rabochidTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
  • From the cradle to the grave
programme for motor+encoder in pic16f877a
« 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:

Offline rabochidTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
  • From the cradle to the grave
Re: programme for motor+encoder in pic16f877a
« Reply #1 on: November 27, 2010, 02:03:33 AM »
sorry for the comment  :P

Offline LunchBox!

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 2
Re: programme for motor+encoder in pic16f877a
« Reply #2 on: December 01, 2010, 12:19:41 AM »
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.



 


Get Your Ad Here