Initialize_ADC help???

Hey, does anyone know if you can run 2 devices at once on different analog pins using the Initialize_ADC? If so can someone please point me in the right direction. Any help is greatly appreciated.

Why are you calling Initialize_ADC? I can’t even find it! (Please tell me this isn’t some new thing I missed.)

To use multiple analog channels, just call Get_Analog_Value() using two different pins.

I’m using Initialize_ADC from some of Kevin’s code. I’ll try working with that, thanks.

By Kevin he means Kevin Watson. You can reach his website here.

i’m not absolutely sure on this, but i have two ideas

  1. i would imagine that you would need to periodically switch which pin the adc is set to. In order to do this, i think all you need to do is just change the ADCON0bits.CHSx bit to reflect which analog input you wish you use

  2. after looking through the default code i noticed how they get analog values. When you call Get_Analog_Value() it makes a call to OpenADC(), i imagine you could use the same code, i believe the function it refers to is in adc.h

i hope i adressed what you were looking for

Thanks, I’m going to have to look around on this, but I hope it works. I have changed the ADCON0bits.CHSx to diferent pins, but I have yet to get two different pins to work in the same code. It either doesn’t work or tells me the error I posted previously. I’ll try the OenADC() and see if it works. Thanks again all.

What are you trying to do with your code? You mentioned that you wanted to do two simultaneous ADC conversions. This cannot be done because there is only one ADC on-board. You have to select the channel to convert (which automatically starts a conversion), wait for it to finish, grab the data, select new channel, wait for it to finish, …

-Kevin

Thanks a bunch Kevin, I’ll get back to this code now. (almost got it :wink: )

Kevin,
What our goal is to initialize the ADC one time, but to activate 2 analog pins during the call. That way we can have 2 inputs ready for us to grab when we want them.

Is this possible and if so how ?

i had one more thought, if you want to use 2 analog pins i am assuming that you are using a gyro and accelerometer at the same time, i actually just considered doing this myself and here’s my latest idea: set your timer to interrupt twice as frequently as needed for each device and then take the output from the adc for different pins each time. This may be too much of a burden on your system depending on what you are doing so you could just keep the same timer rate and alternate pins each time, but most likely this would be too slow for your purposes