PDA

View Full Version : Where To Get Started With ADC (Pic 18f2550 / 4550)



jsags1
- 4th October 2014, 06:10
Hello everyone, i was wondering if any of you would be as kind as to give me some pointers on where to start with ADC with one of these particular chips (18f-2550/4550)

basically i need to understand how ADC works since im trying to build a USB Throttle cuadrant for a flight sim, i know the USB aspect of things (ive made a 32 button "Joystick" with no axis that works fine) but i have no idea on how to do the following using PBP3:

---conifgure Fuses for ADC operation (configuration bits)
---recieve analog input from Pot and turn it into a digital value (this would be an axis)
---have a second analog input for a second axis





(i already know how to make the descriptor and comm. with the pc via HID class)

any guide or well commented code would help me greatly, i appreciate any input and thanks for the time.

Scumari's examples here : http://www.picbasic.co.uk/forum/showthread.php?t=11950

are helpful but i dont understand how the ADC conversion works in that program,
if someone by any chance can explain or "comment" this code i would really appreciate it.
JSAGS

richard
- 4th October 2014, 11:52
JSAGS you will get a better response by posting the code you are having issues with along with a schematic of your setup . posting the same question over and over again under different headings will not solicit more responses. adc is a big subject ,you need to show us what you know and what you have tried so a suitable targeted response can be given .
a good start is to read the pbp manual

Heckler
- 4th October 2014, 19:53
From one of the GREATEST programmers to grace this forum... (may he rest in peace)

http://www.darreltaylor.com/DT_Analog/

dwight

Sherbrook
- 4th October 2014, 21:40
These are the registers used with the A/D converter

PIC 18F2550

Select the A/D inputs with the ADCON1 register. So to select AN0 and AN1 as analogue inputs with voltage references of PIC supply and PIC 0v set ADCON1 = %00001101
AN0 and AN1 must be made inputs with the TRIS register.

Next set the ADCON2 register. For a 10 bit result (0 - 1023) set ADCON2.7 to 1 (right justified). The A/D result will be in registers ADRESH and ADRESL. For an 8 bit result (0 to 255) clear ADCON2.7 to 0 (left justified). The A/D result will be in register ADRESH. The A/D converter needs a fixed time to settle and do the conversion. Set the rest of the bits according to the table in the datasheet for clock speed used.

The pic has only one A/D converter so it must be connected to the relevent A/D pin by the ADCON0 register and the converter turned on. So to select AN0 and turn the converter on, ADCON0 = %00000001. To select AN1, ADCON0 = %00000101. If you make AN3 analogue then AN0, AN1, AN2 will also be analogue input, see the datasheet.

To start the conversion set ADCON0.1 to 1.
Wait for the conversion to finish with for example
WHILE ADCON0.1 = 1 : WEND
The result will be in ADRESH/ADRESL for 16 bit results or ADRESH for 8 bit results depending on the setting of the format in ADCON2.

Hope this will get you started
Phil

Demon
- 4th October 2014, 22:30
Thread moved to FAQ, good info.

Robert

jsags1
- 7th October 2014, 06:13
Thanks for all the good info guy ill hope this gives me the kickstart i need (after midterms XD )

jsags1
- 17th October 2014, 05:26
thanks a lot for the input again, i managed to build my joystick, but eventually ran into some trouble again, please see these thread if you guys care to help me out a bit more :D i would really appreaciate the help..

http://www.picbasic.co.uk/forum/showthread.php?t=19519&p=129244#post129244