PDA

View Full Version : Can an led be controlled by analog pin?



droptail
- 8th October 2008, 20:34
Is it possible to control an led (+5V output) using a pin that is set to analog? The ADCON1 options don't allow me the desired A/D pin combination's I require.

I am using a 16F716 & 16C711.

Thanks

skimask
- 8th October 2008, 21:25
Is it possible to control an led (+5V output) using a pin that is set to analog? The ADCON1 options don't allow me the desired A/D pin combination's I require.

I am using a 16F716 & 16C711.

Thanks

No, but you can switch the pins between analog and digital pin modes 'ON THE FLY'... You might end up with a pulsing LED, but it'll still work.

Darrel Taylor
- 8th October 2008, 22:04
Is it possible to control an led (+5V output) using a pin that is set to analog?
Yes, it's possible. But the technique required depends on how you are using the other Pins on PORTA.

Pins in analog mode can be put into output mode, and they will work just fine as long as no other Pins on that port are used for Digital input.

If another pin is using Digital OUTPUT, then a holding register can be used to eliminate the Read part of Read-Modify-Write.

If RA4 is an input to T0CKI, then that isn't considered a Digital input as far as R-M-W goes.

And yes, you can re-configure the analog ports "on-the fly", but that won't take care of the R-M-W problem if any of the pins are Digital INPUT.

What are the other pins on PORTA used for, and what is your current ADCON1 setting?
<br>

droptail
- 9th October 2008, 02:28
Yes, it's possible. But the technique required depends on how you are using the other Pins on PORTA.

Pins in analog mode can be put into output mode, and they will work just fine as long as no other Pins on that port are used for Digital input.

If another pin is using Digital OUTPUT, then a holding register can be used to eliminate the Read part of Read-Modify-Write.

If RA4 is an input to T0CKI, then that isn't considered a Digital input as far as R-M-W goes.

And yes, you can re-configure the analog ports "on-the fly", but that won't take care of the R-M-W problem if any of the pins are Digital INPUT.

What are the other pins on PORTA used for, and what is your current ADCON1 setting?
<br>

I had thought about continually flipping the ADCON1 register, but wasn't sure about the effect on everything, my continuous ADC, flickering led, etc.

No other pins on that Port are used as digital input. All PORTA pins are analog, (2) are used as ADC input. (RA4 is an input to T0CKI)
ADCON1 =0

Thanks for the input.

Darrel Taylor
- 9th October 2008, 02:48
Ok, so there are 4 analog pins, they are all in analog mode.

You are using 2 of them for analog input and want to use 1 for digital output.
That leaves 1 analog pin unaccounted for.

Is that one an OUTPUT too?
It makes a big difference.

If not, and it's just not being used, then you can use HIGH and LOW like normal on the pin with the LED.

If that other pin is also an output, you'll need to use a variable as a Latch (holding reg) to fix the R-M-W issue.
<br>

droptail
- 9th October 2008, 03:30
Ok, so there are 4 analog pins, they are all in analog mode.

You are using 2 of them for analog input and want to use 1 for digital output.
That leaves 1 analog pin unaccounted for.

Is that one an OUTPUT too?
It makes a big difference.

If not, and it's just not being used, then you can use HIGH and LOW like normal on the pin with the LED.

If that other pin is also an output, you'll need to use a variable as a Latch (holding reg) to fix the R-M-W issue.
<br>

Yes, TRISA =011X
A.0 is only used for an LCD output for testing, and is normally necessary. I can live without it.

Thanks
James

Darrel Taylor
- 9th October 2008, 03:52
Yes, TRISA =011X
Ah Ha! Makes perfect sense now.

You're "good to go".

Cheers,