Problem with external interrupts (B0-B2) on 18f452


Results 1 to 16 of 16

Threaded View

  1. #1
    Join Date
    Jul 2011
    Location
    Miami
    Posts
    7

    Question Problem with external interrupts (B0-B2) on 18f452

    Hi,
    I am new to this forum, and am trying to find some wisdom on handling interrupts on 18f452. I am using timer 0 to trigger an interrupt once every second. That part is working fine. I am trying to detect and count pulses from a pulley that has 3 pulse generating sensors (Call them A, R, & B) I need to count pulses from R, While A & B determine direction. The timer will be used to calculate rate. My code appears to get the interrupts OK, but I am having difficulty determining which sensor it came from.

    There are four magnets in the pulley so I should get 12 interrupts per revolution.
    With the INTCON2 set to use the rising edge, I seem to get an interrupt every time there is a change in state on any of the three pins, thus 24 per revolution. For each sensor, most of the time, I get the appropriate int flag showing 0, while the other two show 1's, when the magnet goes off the sensor, it seems to generate another interrupt, with the values reversed. If this were consistent, I could use this and build on it. However, it isn't.

    If I change the code to trigger on falling edges, I get something quite different. Then I get only 12 interrupts per revolution (as I would expect), However, the int flags are all 1's most of the time but not always. And it is again, inconsistent.

    I'm fairly new to microchip programming with interrupts, so I don't know if my approach is flawed, I have something wrong in the code, or there is some hardware problem.

    My main control registers are as follows:
    trisb=%00000111
    T0CON=%10000011
    RCON.7=0
    INTCON=%10110000
    INTCON2=%10000000
    INTCON3=%11011000

    I would appreciate if someone could examine my code and tell me how to fix this.

    The code is attached as PulseCounter.txt

    My interrupt handler has some serial output to an LCD display so I can see the values of the int flags as they happen. I know that this will have to be removed in the final version
    Attached Files Attached Files

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts