| Swordfish Tutorial - ADC (Control LED Blink Speed) |
|
|
| Saturday, 04 April 2009 08:22 | |
|
This tutorial/example covers another quick guide on how to use Analogue to Digital conversions with a PIC micro. It's achieved by interfacing with a 1K potentiometer to determine how fast the LED will blink. Some other aspects covered in this example include the use of the 18F4550 with the internal oscillator and basic function use.
Simulation video of circuit
Basically the PIC micro will sample AN0 (PORTA.0) and get a reading from 0 to 1023 (0V to 5V). From there, I use the DelaymS command to alter the time that the LED is on and off for. Its very basic, but does cover a couple of underlying features such as the use of a function;
Device = 18F2550 // Setup the device/clock information Clock = 8 Config FOSC = INTOSCIO_EC Include "ADC.bas" // Include the ADC.bas library Dim LED as PORTC.0 // Declare the LED pin function Get_ADC_Sample() as word // Function to grab the ADC sample result = ADC.Read(0) // Grab an ADC sample from channel 0 result = result * 2 // Scale the answer up by a factor of 2 end function OSCCON = %01110110 // Setup the internal OSC for 8Mhz Input(PORTA.0) // Make AN0 an input While True // Create an infinate loop High(LED) // Make the LED pin High Delayms(100 + Get_ADC_Sample) // Delay for 0.1 seconds + the ADC result Low(LED) // Make the LED pin Low Delayms(100 + Get_ADC_Sample) // Delay for 0.1 seconds + the ADC result Wend
Comments (2)
Joomla components by Compojoom
|
|
| Last Updated ( Tuesday, 13 October 2009 09:32 ) |
Whos Online
- dha
- ta1dr
- Jon Chandler
Forum Activity
Credit Where Credit's Due - jon chandler Tuesday, 16 March 2010 12:01 - [9 replies]
Marching LEDs - mrdeb Saturday, 13 March 2010 22:54 - [7 replies]
USB 8 Channel Servo Controller - andyo Saturday, 13 March 2010 01:19 - [2 replies]
Dedicated Servo Controller - graham Friday, 12 March 2010 17:58 - [0 replies]
Must have....delta temperature glowies! - graham Friday, 12 March 2010 17:31 - [3 replies]
A 'throw-away" PIC board - jon chandler Friday, 12 March 2010 13:41 - [31 replies]
iHID - graham Friday, 12 March 2010 02:04 - [5 replies]
Recent Comments
- 2010-03-18 05:40:21 azuga...
Gamers ought to know link:http://www.buyazugagold.com [azuga gold[/u...]
- 2010-03-17 22:58:18 Jon C...
Graham, Thanks for fixing the spacing on the array. This is how i...
- 2010-03-17 21:14:34 ASDne...
Thanks Graham, It is a problem with Flowcode because the demo wa...
- 2010-03-17 19:50:32 Graha...
Looks like you've pretty much solved every minor issue that was enc...
- 2010-03-17 11:42:03 Jon C...
The low-cost servo does have one other feature. The origina...
- 2010-03-17 10:56:44 Graha...
I am not familiar with flowcode, though did you try powering the bo...
- 2010-03-15 21:47:55 ASDne...
Hello there, I am still trying to get the LCD to work but I am pro...
- 2010-03-15 13:16:38 Graha...
Hi Hop, I've finally got some time this weekend to delve into the ...




I plan to build a Therminine?? (musical instrument using photo transistors)
using this ADC several resistors instead of cDS (tooo slow to respond)in an array thus making numerious voltage dividers.
saw similar on HACK A DAY site