CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

need adc interrupt code for PIC18F6722

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ksraja



Joined: 08 Dec 2014
Posts: 8

View user's profile Send private message

need adc interrupt code for PIC18F6722
PostPosted: Wed Dec 10, 2014 11:24 pm     Reply with quote

Hi

My project is in robotics, here i want to read the position of motor where it is, so that I am using Potentiometer to read the position of motor.

Pls can anyone provide the adc interrupt code to complete the application.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Thu Dec 11, 2014 1:28 am     Reply with quote

Start at the beginning. What makes you think you need the interrupt?.

It generally takes longer to get into and out of the interrupt handler, than it does to complete an entire ADC reading. The only reason to use the ADC interrupt, is when you use something else to trigger the actual conversion.

So the sequence becomes:

The event happens (whatever it may be), and starts the ADC.
The ADC then interrupts when the conversion completes.
You take the reading.

The actual reading is simple - one line of code:

val=read_adc(ADC_READ_ONLY);

Nothing else (where 'val' is the variable you want the reading put into).

So the question is, what are you going to use to start the ADC?. This is where the complexity comes, not in the ADC interrupt. You can trigger it from a CCP, which therefore could represent a 'time', or an external trigger. You need to work out what you are going to trigger 'from' before starting to think about ADC interrupts.

If you search the forum, I have in the past posted examples of how to do the ADC readings at a specified time from the CCP.

There are also other ways of taking ADC readings involving time, without the ADC interrupt. For these the sequence is:

In a 'tick' (timer) interrupt:
Read the value from the ADC without performing the conversion
Start a new conversion.

With this at each 'tick' you load the value that was recorded by the ADC which is doing it's conversions 'in the background' between the timer interrupts. This has the big advantage of not involving the overhead of the ADC interrupt, and making the readings synchronous to the 'tick'. If the tick is say a multiple of your PWM frequency, then the readings are synchronous to the PWM, which is often ideal for power control.

Work out 'when' you want your readings to occur then we may be able to help showing you how to do this.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group