PDA

View Full Version : A variable interval LED pulser??



jellis00
- 8th August 2010, 06:26
I need to pulse an LED (on for ~1 sec) at a variable interval from 1 sec to 3 minutes, as externally controlled by the user. I presume there is some way to use a potentiometer as a peripheral to an ADC input as a means of varying the interval between the output pulses to the LED, but not sure how to do this with the ADC input circuit or the required PICBASIC. Any ideas or examples would be appreciated!

Kamikaze47
- 8th August 2010, 07:55
You can connect one side of a pot to ground, the other side to +5v and the middle pin to an ADC pin. Then, take a look in the PBP manual under ADCIN - it will tell you how to read the value. If you are unsure what values to use in the defines, use PicMultiCalc (search this forum for it, if you dont have it).

Once you have ADC working, you can use PicMultiCalc again to work out the timer values to create a 1Hz timer. A simple counter within the timer interrupt will let you flash the led every second, every 2 seconds, or every what every number of seconds you want. Set the target of the counter based on the ADC result.

Mike, K8LH
- 8th August 2010, 15:03
Couldn't you also do it without timer interrupts? Something like this perhaps (please excuse the C code)?



while(1)
{
period = adcin(3); // read pot'
period = period / 10 + 1; // scale to 1..103 (seconds)
count = 1; // start new period
while(period < count) //
{ delay_ms(1000); // delay 1 second
count++; // bump count var'
}
led = 1; // turn on led
delay_us(500) // for 1/2 second
led = 0; // and off
delay_us(500) // for 1/2 second
}


You could use a circuit as simple as the "Spinning Class Strobe" (below) but you would need to change the potentiometer scale to represent a Period of 1 to 103 seconds.

Regards, Mike

mtrawczy
- 27th August 2010, 22:04
Mac is that you? it mark from inacomp

Mike, K8LH
- 28th August 2010, 01:45
Mac is that you? it mark from inacomp

Whoa! Blast from the past! Hi Mark... You got PM turned on?

Regards, Mike McLaren, K8LH