How to use a Potentiometer interrupt in Pic 16f887

Status
Not open for further replies.
Did you try enabling the glogal interrupt flag with..

bsf INTCON,GIE

and the peripheral interrupt flag ..

bsf INTCON,PEIE
 
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?
 
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...
 
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.
 
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.
 
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.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…