1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

How to use a Potentiometer interrupt in Pic 16f887

Discussion in 'Homework Help' started by BobSparky1996, Dec 11, 2017.

  1. BobSparky1996

    BobSparky1996 New Member

    Joined:
    Dec 9, 2017
    Messages:
    8
    Likes:
    0
    :)
     
    Last edited: Dec 11, 2017
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,378
    Likes:
    920
    Location:
    Rochdale UK
    ONLINE
    Did you try enabling the glogal interrupt flag with..

    bsf INTCON,GIE

    and the peripheral interrupt flag ..

    bsf INTCON,PEIE
     
  3. BobSparky1996

    BobSparky1996 New Member

    Joined:
    Dec 9, 2017
    Messages:
    8
    Likes:
    0
    Hi Ian, Yeah I tried enabling both but it still didnt fire - are there any others that need to be enabled? Or any specific order?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,378
    Likes:
    920
    Location:
    Rochdale UK
    ONLINE

    The ADC doesn't work like you think.... The Interrupt will only fire when you set the GO/DONE bit of the ADCON0 register, and then will fire when its ready regardless of what you do with the pot..

    To read the adc continually you need to set up the CCP module to match the timer via the "Special event trigger".

    Most here just poll the ADC...
     
  6. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,279
    Likes:
    355
    Location:
    Brisbane Australia
    The ADC interrupt only fires when an ADC has completed. You need to read your pot at a regular interval using a timer interrupt.
    Alternatively, check out the Special event trigger mode of the PWM module. On earlier pics you could use it to automatically start the ADC conversion and an interrupt would be generated when it completed.
    This feature seems to have been removed from the latest chips.

    Mike.
     
  7. BobSparky1996

    BobSparky1996 New Member

    Joined:
    Dec 9, 2017
    Messages:
    8
    Likes:
    0
    :)
     
    Last edited: Dec 11, 2017
  8. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,279
    Likes:
    355
    Location:
    Brisbane Australia
    As far as I'm aware using the Special Event Trigger to start the ADC is only available on CCP2 - not on CCP1. Which chip are you using?

    Edit, just checked the 16F883 datasheet and it seems it works on both modules.

    Mike.
     
  9. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,279
    Likes:
    355
    Location:
    Brisbane Australia
    To use the Special Event trigger,

    Setup timer 1 to count at a suitable speed - say 1uS per tick.
    Setup PWM as Special event with CCP1L and CCP1H equal to the event time - 20,000 will make it happen every 20mS.
    Setup the ADC to read your potentiometer - select the channel and turn it on - no acquisition time.
    Setup the ADC interrupt.
    In the ISR read the ADC result and use it.
    Only the ADC interrupt should be turned on.

    Mike.
     

Share This Page