pin control of resistance

Status
Not open for further replies.

onehorse

Well-known member
This is tangentially Teensy related since I am designing an add-on board for the Teensy which requires that a resistor from the sensor to GND be chosen to set the sensor integration time. I would like to be able to toggle the resistance value using digitalWrite(HIGH/LOW) to a pin. Can I just hook two resistors in parallel from the sensor and choose which one is grounded by using a HIGH/LOW signal to the gates of a dual N-type/P-type MosFet? If I hook up the resistor to the Source of an N-type mosfet and have the gate grounded, is the resistor "tri-stated" or High-Z? Likewise with 3V3 applied to a p-type mosfet? Does this make sense to anyone or am I smokin' it?
 
Not smoking it as bad as I do sometimes afaiac. I expect an N Channel mosfet is called for but maybe I am looking at inversely and actually the P channel would be required (just not sure I am thinking of relationship between gate and drain/source properly atm).

if you only want to show the sensor two different resistances then two resistors and one IO pin on MCU should do - R1 goes from Sensor to MCU-IOn, R2 goes from MCU-IOn to GND; float the IO pin on MCU when you want sensor to see full resistance of R1+R2, drive IO pin on MCU (hard) low when you only want the sensor to see R1.

It should be possible to approximate the action of a digital pot with 'N' resistors and 'N-1' mosfets - as soon as you have more than about 4 mosfets you should probably start looking at digital pots.
 
Last edited:
float the IO pin on MCU when you want sensor to see full resistance of R1+R2, drive IO pin on MCU (hard) low when you only want the sensor to see R1.

Excellent idea, for the timing tables are for R, 2R, and 4R but overlap so in reality only two values of resistance are needed to span the full range.

a pair of N-channel mosfets ought to work.

I'm not quite sure how. I can hook R1 from the sensor to the source of one n-type fet and when I apply HIGH to the gate, it will go to ground via the drain being grounded. But HIGH will also go to the other n-type mosfet gate. Wouldn't it do the same to R2? I was hoping that using a dual fet, one n-type and one p-type, I could toggle between either high z and GND so the current from the sensor would only go through either one or the other resistor.

In fact, this kind of toggling arises surprisingly often in circuit design. I suppose I could use some sort of logic chip but there must be a simple solution for using a HIGH/LOW input to select two outputs.
 
If I find time this evening (looking a bit challenged) I will try to draw at least one idea, if not a couple - if you insist on losing only one IO pin to the task then it probably won't mean using opposing kinds (of mosfets) unless current does something I cannot see it doing atm.

Been wrong lots of times; if I find time to draw stuff in protel I will check thread first to make sure I am not wasting the time I found :)
 
Thanks for taking a look. I'll have some time tomorrow to sketch up a circuit or two to test my opposing fet idea. But I'm not married to it. I would like to find a single GPIO toggle solution. Elegant as your string of resistor idea is, I want the user to choose the resistance by setting the GPIO either HIGH or LOW, which is common usage. What happens in your example when the GPIO is set to HIGH? And it's not good enough to just tell users DON'T DO THAT!

A simple alternative is to use an on-board solder jumper, but I was hoping for an elegant, electronic solution....
 
solution for using a HIGH/LOW input to select two outputs.

I'm not sure whether I have understood you correctly.
Perhaps an inverter (for one Bit, a simple transistor..) ?
Or for more bits, a binary-> decimal decoder/demultiplexer .. something like 74139 (there are more types, for more bits for example..)
 
Last edited:
I know a sketch would be best but what I want is to connect two resistors in parallel to the output of the sense pin of a sensor which determines the integration time of the sensor depending on the resistance value probably by monitoring the current flow through the resistor to ground for a fixed applied voltage. Now I would like to choose either one resistor value or the other by using a Teensy GPIO pin set to either digitalWrite(HIGH) or digitalWrite(LOW). Conceptually, I want the other end of the resistors to be either high impedence (no current flow) or ground (current flow), with the choice made by GPIO. That is, one is High Z while the other is GND, or vice versa.

A mosfet is simply a transistor but has some better characteristics like very low on resistance and very high off impedence. Mosfets also come in very small packages like 1 x 0.6 mm so are easy to stuff into almost any board no matter how appallingly small it already is. In fact, I would prefer a mosfet solution, but I am still a little fuzzy what it would look like. It's late, I'll design a likely circuit tomorrow...
 
I believe these just use a network of fets to do the multiplexing, so yes, we are talking about the same function and the same means. But the 4051 is a too gigantic package for my purposes, way too big. I want the function in a very small footprint. A dual mosfet comes in a 2 mm x 2 mm package. Not quite, but close to appallingly small!
 
I might not completely get the idea, but you need to generate a low/high impedance from a sensor pin to ground?
Why not put one resistor to ground (the high impedance) and then connect the other to the teensy, and use the pin as an open drain output. When conductive you get the parallel combination of the resistors. If you are worried about noise and Rds of the teensy, connect an external mosfet.
 
Last edited:
I looked at this digital pot which would work but is overkill and too big and expensive.

I think I will just use two resistors and a solder jumper; this is by far the easiest solution. No need to get too fancy even though it's fun to think about...
 
Is one end of the resistor grounded when used ? If so, then don't do digitalWrite(HIGH) or digitalWrite(LOW), but do pinMode(pin, INPUT) and pinMode(pin, OUTPUT); digitalWrite(LOW) -- this will tristate the pin (INPUT), and switch to drive it low (OUTPUT, LOW).

The Teensy's output drive strength isn't as strong as those analog switches (about 100 ohm ?), so there may be an error in the total resistance created (it will look as if you have an R about 100 ohms larger than the one switched.
 
Yes, one end is grounded in use, the "other" resistor should be floating.

Not sure I understand your point about pinMode. I was hoping to simply use the logic level to enable current flow through one or the other resistor via a fet or two where the pin output goes to the gate(s), not drive any current. In the simplest case, I would connect the resistor terminal to the source of an n-type mosfet and enable connection to the drain ground by toggling the gate HIGH or LOW. The hard part is how to use a single GPIO output to get a similar fet network to connect either one or the other resistor to ground while leaving the other at high impedence so no current flows.

sensor ----> resistor 1 ----GND
----> resistor 2 ----floating

OR

sensor ----> resistor 1 ----floating
----> resistor 2 ----GND
 
Last edited:
@onehorse:
What resistor values are we (you) actually talking about? And can you shed some light about the sensor?
Robsoles' answer in post #2 was the first thought that came to my mind as well. If the resistor values are not too low than that solution is definitely viable. JP3141 states basically the same as robsoles answer.

Paul
 
That is a really interesting idea. As long as you're only connecting the resistors to ground, maybe you can just use the N-channel transistors that are already built into the MK20 chip.

I did some work months ago to measure the on resistance of the Teensy 3.1 output transistors. They're approx 20 ohms at room temperature. But I didn't study leakage currents.

If you try this, the transistor should be turned off by disabling the pin (write zero to the config register), not just by making it an input.
 
The resistor values are 270 kOhm, 540 kOhm, and 1 MOhm. The sensor is Vishay's VEML6070 UV light sensor. The data integration time depends on a sense resistor. I could choose one value, or use a solder jumper to allow selection of two values, or use robsoles' idea, but I'm not quite sure I understand it.

I think he means attaching two resistors in series between the sensor and ground with the GPIO between the resistors. Then disabling the pin allows the combined resistance (say, 2 x 270 kOhm resistors in series) between the sensor and ground, while pinMode(OUTPUT) + digitalWrite(LOW) would select only 1 x 270 kOhm. Is this about right?

What is the syntax for writing a zero to the GPIO configuration register?
 
sounds like what I intended :)

I've got stuff to deal with but I will try to be more helpful in a short while.
 
Yeah -- like this:
Capture.PNG

where the 2 FETs are actually inside the I/O pin of the Teensy -- drive them as discussed above. Given >> 100's of kohm, the resistance of the switches is negligible.


when you have no FETs on (all I/O's as inputs, or off), you get 270+270+540 = 1.08 Mohm
With just M3 on (I/O as output LOW), you get 270k+270k = 540k
With M1 on (M3 then doesn't matter), you get 270k
 
There should be a way to set up the gates on Jp3141's circuit to be driven by a single IO pin on an MCU such that setting 'pinMode(x,OUTPUT);digitWrite(x,HIGH);' will turn on both fets, 'pinMode(x,INPUT_PULLUP);' will turn on one fet and 'pinMode(x,INPUT)'; will turn off both.

3 resistors chained from the IO pin on MCU with gates of fets on 'middle' nodes and GND on the far end, choose the right resistor values and I am pretty sure my idea will fly - all options on one MCU pin.
 
Thanks everyone for engaging on this somewhat inane topic; I am learning plenty!

I understand jp3141's circuit and will try it with just two resistors in series. What magic incantation do I need to set the pin configuration to zero, or is pinMode(x, INPUT) good enough?

'pinMode(x,OUTPUT);digitWrite(x,HIGH);' will turn on both fets,
...

'pinMode(x,INPUT)' (or zero configuration); will turn off both

Agreed.

'pinMode(x,INPUT_PULLUP);' will turn on one fet

But how does this work if the GPIO is connected to both gates?
 
Last edited:
Not wanting to spoil the fun of thinking about how to implement a switchable resistor using as less components as possible, but wouldn't it be more easy to use the VEML6070's internal integration time [a.k.a. refresh time] register?
According to the datasheet you can change the refreshtime over a range of .5T to 4T:

Refresh time setting.PNG

Ofcourse it all depends on the amount of UV your application needs to measure and how fast you want intensity data from your sensor, but you could start with a certain resistor value, based on figure 7 of the datasheet, and then play with the register to see whether it matches your needs.

Paul
 
Of course, and this is exactly how i designed the first breakout board. But the data sheet used to have another column for a 1 MOhm set resistor so you could extend the integration time to ~3 sec. In the current version, you can double the intagration time with a second resistor. In fact, the resistance is arbitrary and the times simply scale with resistance, so for some application you might well need two different resistances to span the greatest possible range in integration times. I just started wondering how to do this in an elegant electronic way. I never expected to learn about the internal guts of the Teensy!.
 
Last edited:
Status
Not open for further replies.
Back
Top