• 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

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#4
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...
 

Pommie

Well-Known Member
Most Helpful Member
#5
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.
 

Pommie

Well-Known Member
Most Helpful Member
#7
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.
 

Pommie

Well-Known Member
Most Helpful Member
#8
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.
 

Latest threads

EE World Online Articles

Loading

 
Top