Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC - Outputting variable voltages

Status
Not open for further replies.

superflux

New Member
I want to see if I'm on the right track with this. I need a varied voltage leaving the PIC dependant on which way the SPDT switch is set.

And, what if I have a 3 way switch, can I just add another OUTPUT PORT >> RESISTOR >> DIODE?

Do I even need the DIODEs?

Thanks!

8932-varied_voltage.gif
 

blueroomelectronics

Well-Known Member
You could use the built in DAC and an OpAMP. It's a very course 16 level DAC though.

Notes:
Use PORTB and the internal pullups for the switch
You don't need to pullup unused I/O pins, just make them outputs in the code.
You will need decoupling caps.
 

atferrari

Well-Known Member
What about PWM

You could go away, using a PWM signal duly filtered (two simple RC cells) to get almost any DC output you want.

That would be the way I would go anyway.
 

superflux

New Member
Notes:
Use PORTB and the internal pullups for the switch
You don't need to pullup unused I/O pins, just make them outputs in the code.
You will need decoupling caps.

All of the PORTB pins will eventually be used by LEDs.

I was told, or maybe it was a recommendation, to use every pin in order to prevent possible issues with the PIC - interference maybe? It's 100% fine to set unused PORTs to output ant not expect any ill effects?

What size caps and how many? I use a 1 uf 25v cap close to the 5v supply and ground on every PIC. The incoming power gets a 100uf before it hits the regulator. I should have put it in this schematic - is that sufficient?

Thanks!
 

Nigel Goodwin

Super Moderator
Most Helpful Member
I was told, or maybe it was a recommendation, to use every pin in order to prevent possible issues with the PIC - interference maybe? It's 100% fine to set unused PORTs to output ant not expect any ill effects?

Yes, it's 100% fine, it's also 100% fine to set them as inputs as well.

The myth about unconnected inputs comes from the days of CMOS logic gates, where leaving inputs floating caused problems, it doesn't happen with PIC's.
 

binzer

Member
I want to see if I'm on the right track with this. I need a varied voltage leaving the PIC dependant on which way the SPDT switch is set.

And, what if I have a 3 way switch, can I just add another OUTPUT PORT >> RESISTOR >> DIODE?

Do I even need the DIODEs?

Thanks!

Your output will always be zero, your output is wrong, you probably wanted a resistor in the emitter??
 

superflux

New Member
Your output will always be zero, your output is wrong, you probably wanted a resistor in the emitter??

To my knowledge, this is a emitter follower scenario. The more voltage placed into the transistor, the higher the resulting voltage out the emitter - no?

Depending on the switch position, either PORTB 6 or 7 will be turned on via software, suppling 5 volts, to the selected port, dropped down slightly by the resistor/diode combo into the transistor.

I am all ears and willing to learn.

Thanks!
 

ericgibbs

Well-Known Member
Most Helpful Member
To my knowledge, this is a emitter follower scenario. The more voltage placed into the transistor, the higher the resulting voltage out the emitter - no?

Depending on the switch position, either PORTB 6 or 7 will be turned on via software, suppling 5 volts, to the selected port, dropped down slightly by the resistor/diode combo into the transistor.

I am all ears and willing to learn.

Thanks!

hi,
The emitter is grounded to 0V,it will always be 0V.
 

ronsimpson

Well-Known Member
Most Helpful Member
superflux, your output circuit is not good for many reasons.
What voltages do you want?
How much current? What are you driving?
go to wikipedia.com and look up r2r ladder (resistor ladder). In their example they use 5 port pins and 10 resistors to get 32 different voltages. The r2r ladder can be made longer or shorter.
 

superflux

New Member
How much current? What are you driving?
go to wikipedia.com and look up r2r ladder (resistor ladder).

I need to feed a computer on a motorcycle certain voltages to override some programming. I need very little current - less than .5 ma and voltage from 1.8v to 5v. It's going into the ADC on the ECM of the motorcycle.

I also have a similar situation for giving an LED dual brightness in a situation where PWM is not possible.

Will both schematics, shown below, fly? The top one actually uses an LED which should complete the circuit. However; it seems that with the bottom schematic, using R2R, that anything is possible - I could use that for sending the low current voltages I need as well as controlling LED brightness.

I sincerely appreciate the clarification and your time, guys!

8935-varied_voltage_led.gif


8936-varied_voltage_r2r.gif
 

ericgibbs

Well-Known Member
Most Helpful Member
hi,
The top circuit will not give the result you require.

The bottom circuit is more inline with the requirement.:)


EDIT:

Google: dac ladder network
This link will give you an idea.

https://www.ecelab.com/circuit-dac-r2r.htm
 
Last edited:

ronsimpson

Well-Known Member
Most Helpful Member
For the LED try this.
Two resistors, one LED, two pins.
Set both pins=0.
Use the tri-state conrole to switch in the resistors.
If both pins are 'input' then no light.
If one pin is 'output' then R1 sets LED current.
If the other pin is 'output' then R2 sets current.
If both pins are 'output' then R1//R2 sets current.
 

Attachments

  • Image2.jpg
    Image2.jpg
    25.9 KB · Views: 138

superflux

New Member
For the LED try this.
Two resistors, one LED, two pins.
Set both pins=0.
Use the tri-state conrole to switch in the resistors.

The reason I can't leave both set to OUTPUT and turn 1 on (1) and 1 off (0) would be that the one that is set to 'off' would simply GROUND the voltage coming from the one that was 'on' - correct?
 

superflux

New Member
Just looking for a couple set voltages around 4.3 and 4.7 volts for this project. However; I'm also looking for a design that would allow me to use this same design in other projects for dimming leds where PWM is not possible.
 

binzer

Member
To my knowledge, this is a emitter follower scenario. The more voltage placed into the transistor, the higher the resulting voltage out the emitter - no?

Depending on the switch position, either PORTB 6 or 7 will be turned on via software, suppling 5 volts, to the selected port, dropped down slightly by the resistor/diode combo into the transistor.

I am all ears and willing to learn.

Thanks!

Well your schematic shows the emitter is GROUNDED, thus output will always be zero.
It's obvious to me that there should be a resistor on the emitter and your output pulled from across it, just drawn wrong.
Mike.
 

be80be

Well-Known Member
I used a 12f508 with resistor ladder by setting any combination of the four pins high
I could go from 0 to 5 volts makes a real good led controller
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top