Continue to Site

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.

  • 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.

How to use a Potentiometer interrupt in Pic 16f887

Status
Not open for further replies.
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top