In SX Microcontrollers, SX/B Compiler and SX-Key Tool, bean wrote: Here is a link that explains how it works: [url=http://www.sxlist.com/techref/scenix/lib/io/adc_vp.htm]http://www.sxlist.com/techref/scenix/lib/io/adc_vp.htm[/url] [code] ANALOGIN InPin, OutPin, Value[, Prime] Reads an analog input voltage using the continuous calibration method All you need is 2 10K resistors and a 0.01uF capacitor(for 4MHz) or 0.001(for 50MHz) You can experiment with different resistor and/or capacitor values. Don't use resistor values below 220 ohms to protect the SX output pin. The variable Value will get set to the analog voltage at the input with 255 = Supply voltage. So if you get a reading of 127 and the supply voltage is 5 volts, then the input voltage is about 2.5 volts. Note that the input pin needs to be set to CMOS input threshold. By default the sx sets all pins to TTL threshold. The TTL theshold is 1.4Volts. That will make the full scale reading of 255 = 2.8 volts regardless of the supply voltage. The method needs to "prime" the capacitor to get a stable reading. By default the prime value is 1. If you get unstable readings either use a smaller cap value or increase the prime value. Prime must be a constant from 0 to 255. However larger prime values will increase the time it takes to get a reading. The time required to get a reading is 3825*(1+Prime)/Frequency. So with the default prime value of 1, if the clock is 4MHz it will take 3825*2/4000000 seconds or about 1.91 milliseconds to get a reading. For faster clocks either use a smaller cap value or a larger prime value. Note that this circuit has a fairly low input impedence. If you use a pot or resistor divider to create the analog voltage the ANALOGIN command may not reach the limits (0 or 255). A simple test using the 10K pots on the PDB yielded values from 0 to 241. The following is an example program: '------------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 InPin PIN RA.0 INPUT CMOS OutPin PIN RA.1 OUTPUT ' Analog Voltage >---/\/\/\-------+----+------------ SX Read Pin (RA.0) ' 10K | | ' ----- +--/\/\/\---- SX Write Pin (RA.1) ' ----- 10K ' 0.01uF / \ ' | ' | ' GND a VAR Byte PROGRAM Start NOSTARTUP Start: ANALOGIN InPin, OutPin, a, 2 WATCH a BREAK GOTO Start END [/code] You can also try looking in the help for the Javelin. It has a similar command. I thinks it's called "ADC" on the javelin. I hope this helps, Bean. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=149107#m149782 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)