5V PWM output possible ?

michael_l
Sat Aug 20, 2016 4:36 pm
Is it possible to get 5V output using pull-up resistor ?

I tried this but it does not seem to be working. Always get 3.3V

pinMode(LCD_LED, PWM_OPEN_DRAIN);


mrburnette
Sat Aug 20, 2016 4:45 pm
https://learn.sparkfun.com/tutorials/us … -converter

Build or buy

Ray


michael_l
Sat Aug 20, 2016 4:48 pm
mrburnette wrote:https://learn.sparkfun.com/tutorials/us … -converter

Build or buy

Ray


Pito
Sat Aug 20, 2016 7:03 pm
5V tolerant pin does not necessarily mean it could be used for driving a load via open collector with 5V.
The pins usually have got an ESD protection circuit, 2 or 4 Si clamp diodes. The F103 refman shows 2 diodes, so when pulling a resistor up to 5V on one side, the output will stay at Vdd(3.3v) + Vf_diode(0.3..0.5V). The current flows from 5V–>load resistor–>diode–>3.3Vdd.

Hmm, when digging into the refman (gpio pins), on the schematics there is also a “VDD_FT” as an option connected to upper clamp diode with an remark:
VDD_FT is a potential specific to 5-Volt tolerant I/Os and different from VDD

So it seems 5V should work with open drain if the VDD_FT is activated.. :)

Another remark:
FT = Five-volt tolerant. In order to sustain a voltage higher than VDD+0.3 the internal pull-up/pull-down resistors must be
disabled.


michael_l
Sat Aug 20, 2016 8:23 pm
Pito wrote:5V tolerant pin does not necessarily mean it could be used for driving a load via open collector with 5V.
The pins usually have got an ESD protection circuit, 2 or 4 Si clamp diodes. The F103 refman shows 2 diodes, so when pulling a resistor up to 5V on one side, the output will stay at Vdd(3.3v) + Vf_diode(0.3..0.5V). The current flows from 5V–>load resistor–>diode–>3.3Vdd.

Hmm, when digging into the refman (gpio pins), on the schematics there is also a “VDD_FT” as an option connected to upper clamp diode with an remark:
VDD_FT is a potential specific to 5-Volt tolerant I/Os and different from VDD

So it seems 5V should work with open drain if the VDD_FT is activated.. :)

Another remark:
FT = Five-volt tolerant. In order to sustain a voltage higher than VDD+0.3 the internal pull-up/pull-down resistors must be
disabled.


RogerClark
Sat Aug 20, 2016 10:06 pm
I think the pin mode is OUTPUT_OPEN_DRAIN

see

https://github.com/rogerclarkmelbourne/ … tal_f1.cpp

BTW.
If this works, I am sure a lot of people would be interested, as I know other devices e.f. 7 seg red LED displays that only work if you have 5 V data lines


Pito
Sun Aug 21, 2016 7:00 am
I’ve spent an hour browsing the topic, however people are rather confused as it does not work as expected. The issue is the VDD_FT – when this voltage would be, let say 5V (where it comes from?? a charge pump?? how it is activated??), than it can work. What the people see in reality is the similar behavior as the OP indicates. Maybe a silicon bug? What errata does say??
Errata for STM32F103XX – document ES096
http://www.st.com/content/st_com/en/sup … rata_sheet

GPIO output.JPG
GPIO output.JPG (11.66 KiB) Viewed 4295 times

RogerClark
Sun Aug 21, 2016 8:08 am
If you are running from USB, you should be able to get to that 5V by tapping off the input to the 3.3V regulator

If you are powering the whole thing from an external 3.3V supply and have no other source of 5V, I agree, the only option is to use a charge pump.

Depending on how much current you need, I suppose you may be able to use the PWM on one of the pins to generate the square waves for the charge pump, but it may take too much current for a single GPIO pin (and of course you would need various descrete components to build the charge pump


Pito
Sun Aug 21, 2016 9:20 am
The charge pump for the VDD_FT must be internal one (on the chip) as the VDD_FT is the internal stuff.
Moreover an internal charge pump which may limit voltage to 5V with ie LED currents is a nogo :)
There must be a different trick with the VDD_FT, but nobody knows it..
Anyhow, I would rather recommend to OP an npn transistor driving the power mosfet (and invert the PWM polarity).

driver mosfet.JPG
driver mosfet.JPG (4.56 KiB) Viewed 4287 times

RogerClark
Sun Aug 21, 2016 9:54 am
Hi Pito

If the pin is set to OUTPUT_OPEN_DRAIN cant it be pulled high by an external pullup from 5V if the pin is 5V tolerant ?


Pito
Sun Aug 21, 2016 9:59 am
I did not find any indication on the web it works that way. I did not try on my Maple Mini.
As you can see from the STM GPIO schematics above, there is the D1 (on top) diode, which limits the output voltage (also in OPEN DRAIN MODE) to Vdd+0.3V, or, VDD_FT+0.3V (where 0.3V is the forward voltage of D1 for small currents).
If VDD_FT would be 5V, than the max voltage you may see on the OPEN DRAIN output loaded with a reasonable valued resistor would be 5V+0.3V (when OD gpio set to HIGH, and internal pullup/down resistors are disabled).

Pito
Sun Aug 21, 2016 10:36 am
Ok so I’ve found a spare 9V battery for my multimeter :)

With this:
void setup() {
// put your setup code here, to run once:
pinMode(PB8, OUTPUT_OPEN_DRAIN);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(PB8, LOW);
delay(2000);
digitalWrite(PB8, HIGH);
delay(2000);
}


michael_l
Sun Aug 21, 2016 11:03 am
Found an old cd4069 which does seem to do the the trick :-)

Pito: Thanks for the info. Will try that. That is actually what I wanted originally. But I’ll need to try PWM_OPEN_DRAIN instead.

Yes you’re the first :-)


testato
Tue Sep 13, 2016 8:20 pm
double post

testato
Tue Sep 13, 2016 8:21 pm
double post

testato
Tue Sep 13, 2016 8:21 pm
Pito wrote:
(when OD gpio set to HIGH…..).

Pito
Wed Sep 14, 2016 7:52 am
Of course you can set an OD output to High or Low.
With Open Drain you get High or Low as well, it is expected there is a pull-up at the pin.
There is no HighZ with a pull-up wired.

stancecoke
Wed Sep 14, 2016 5:34 pm
michael_l wrote:

But I’ll need to try PWM_OPEN_DRAIN instead.


michael_l
Fri Sep 30, 2016 3:48 pm
for some reason I can’t get this to work..
const uint8_t PwmLeikkYA = PB8;
....
#define __LEIKKURITERAN_NOSTO_NOPEUS_ 127
....
pinMode(PwmLeikkYA, PWM_OPEN_DRAIN);
....
pwmWrite(PwmLeikkYA , __LEIKKURITERAN_NOSTO_NOPEUS_ );

RogerClark
Fri Sep 30, 2016 9:14 pm
try pwmWrite()

michael_l
Sat Oct 01, 2016 7:16 am
Yeah, 5V PWM works with e.g. pwmWrite(PB8, 0x8000) – I was using too small value for duty_cycle (127). Didn’t know pwmWrite uses larger value range .

testato
Thu Dec 01, 2016 8:41 pm
Pito wrote:Of course you can set an OD output to High or Low.
With Open Drain you get High or Low as well, it is expected there is a pull-up at the pin.
There is no HighZ with a pull-up wired.

Leave a Reply

Your email address will not be published. Required fields are marked *