#avr Logs

Nov 03 2020

#avr Calendar

02:31 PM guanche: I'm trying to switch a mosfet with a bluepill, using PWM (2Khz max), do you guys think this would be ok?
02:37 PM guanche: https://postimg.cc/ZWktXnqS
02:39 PM cehteh: looks overly complicated :D
02:40 PM guanche: how would you do it then?
02:40 PM LeoNerd: Uh yeah that's rather over-the-top
02:40 PM cehteh: why the optocoupler? and you need a flyback diode over the inductive load
02:41 PM cehteh: and 2khz isnt really much
02:41 PM LeoNerd: Optocoupler is doing nothing. The class-A amplifier is really unnecessay for a gate drive
02:41 PM guanche: there is one, the optocoupler because I want it to be isolated from the rest
02:41 PM LeoNerd: It'll waste a lot of current
02:42 PM cehteh: possibly you can drive the gate directly from the optocoupler
02:42 PM cehteh: when you need insulation
02:42 PM guanche: so better to remove it then? and how would I switch the mosfet then?
02:42 PM guanche: I thougth it wouldn't let it open fast enough
02:42 PM cehteh: but you send the 11v vin to the bluepill so thats not insulated, common GND as well or?
02:43 PM guanche: yes, it's common gnd, but the bluepill has it's own LDO, not fully insulated yes
02:43 PM LeoNerd: The optocoupler has shared grounds, so this isn't isolating
02:43 PM cehteh: yes switching times depend on mosfet/opto, dunno if its fast enough, but 2khz sounds pretty low anyway
02:43 PM LeoNerd: 2kHz is practically DC, even to an optocoupler
02:44 PM guanche: sure, so if I were to remove the opto, how would I go into swithing the mosfet?
02:44 PM cehteh: well depends on pullups and stuff but i would agree
02:44 PM LeoNerd: It's an nFET. Does the bluepill output already a sufficient voltage to drive the gate on?
02:45 PM cehteh: there are dmosfet IC's when you are really worried, but prolly thats when you have more than a few hundred khz switching frequenncy
02:45 PM LeoNerd: I don't have the datasheet to hand; what's Vgs of that FET?
02:45 PM guanche: no, 3v3 is not enough for it
02:45 PM cehteh: 3.3v could be bit low, for most mosfets
02:45 PM LeoNerd: Ah; so use a second FET from the +11V
02:45 PM guanche: 20V VGS (th), but works well at 5V, for what I want it for
02:45 PM cehteh: but you a simple 2n7000 may fix that
02:45 PM LeoNerd: Good ol' 2n7000
02:46 PM guanche: you mean switching it with an npn driven by the gpio?
02:46 PM cehteh: its not good at 3.3v either but for 2khz it shoudl be good enough
02:46 PM cehteh: or npn
02:46 PM cehteh: if in doubt i check for drvier IC's some are easily sourcveable and cheap and then just forget about it
02:47 PM LeoNerd: Yeah that'd be my next suggestion, one of those prebuilt FET gate driver chips
02:47 PM guanche: not really cheap here though
02:47 PM LeoNerd: As compared the opto + two bipolars + other bits and pieces you have here?
02:47 PM cehteh: how much current do you switch?
02:47 PM LeoNerd: Plus board space
02:47 PM cehteh: and why only 2khz?
02:48 PM cehteh: what kind of inductive load is that?
02:48 PM guanche: all of those components are salvaged, I'm switching a search coil, this is what I'm doing:
02:48 PM guanche: http://www.digiwood.ee/8-electronic-projects/2-metal-detector-circuit
02:48 PM cehteh: ah ok
02:48 PM guanche: 2Khz is a maximum I set it to, the guy actually uses 500Hz
02:49 PM cehteh: yeah i thought about some motor or so
02:49 PM guanche: no, hehe
02:49 PM LeoNerd: Some people call 500Hz "DC" ;)
02:49 PM guanche: haha
02:49 PM cehteh: soem relays can do 500hz :D
02:50 PM cehteh: anyway you need D2 / flyback
02:50 PM cehteh: dunno whats D1 is good for, but i havent read the text
02:50 PM cehteh: C1/Coil wild do a nice dance :D
02:51 PM guanche: it's probably protecting the mosfet from the negative part, yeah
02:51 PM LeoNerd: D1 appears to be a larger version of the inherent body diode in the FET
02:51 PM cehteh: nope reverse
02:52 PM cehteh: maybe the fet breaks through at the induced voltage
02:52 PM guanche: so what do you suggest? I haven't even tried to drive the mosfet directly with the bluepill, maybe it even works for this, but if it weren't?
02:52 PM LeoNerd: two FETs
02:53 PM LeoNerd: If Vgs is sufficient then direct drive
02:53 PM cehteh: haha
02:53 PM cehteh: npn for driving would be good
02:53 PM LeoNerd: If not, a second pFET inbetween as a gate driver
02:53 PM LeoNerd: Or a single bipolar in there, yah
02:53 PM cehteh: but at 2khz you likely wont need a push/pull driver
02:54 PM guanche: yes, it's not like is really needed, the roughest part is going to be the DAC, though
02:54 PM cehteh: and even if, you cna do a push/pull driver as well, one bipolar more
02:54 PM cehteh: DAC?
02:55 PM guanche: yes, the guy uses a PIC because it saves of parts, a DAC is needed to analyze the signal and determine if there's metal on the path of the coil
02:55 PM cehteh: ADC you mean?
02:56 PM guanche: the ADC is needed for the first analysis, a DAC to analyze the pulse returned from the environment
02:56 PM cehteh: how that?
02:57 PM guanche: well, the guy explains is there, you basically use an opamp with an R2R ladder to control it, and so you can determine even the type of metal the coil is seeing
02:57 PM guanche: this PIC has a 5-bit DAC on it the guy uses for this
02:58 PM cehteh: ah i see
02:58 PM cehteh: moent you saied bluepill .. doesnt the bluepill have buildin DAC?
02:58 PM guanche: what I'll do is to try an ULN2803 to drive an R2R ladder, to then feed the opamp and read the result with the ADC
02:58 PM cehteh: my redpills have :D
02:59 PM guanche: not the f103
02:59 PM cehteh: costs?
02:59 PM guanche: nothing, I've got all the parts
02:59 PM cehteh: lol ok
02:59 PM cehteh: do you have a ADC port free?
03:00 PM guanche: yes, the f103 has several and this application does only require one
03:00 PM cehteh: instead of a r2r ladder you can generate pwm and filter it to analog/DC ... feedback to ADC for measuring/PID to calibrate its value
03:01 PM cehteh: possibly PCM if doable instead PWM
03:01 PM guanche: oh, I didn't think of that, that's a good idea
03:01 PM cehteh: dunno if thats fast enough
03:02 PM guanche: I'd also need to check how the opamp behaves, never done that before
03:02 PM cehteh: well you only need a sweep its not timing critical as long you ADC its value you can use that
03:03 PM cehteh: f103 doesnt have a analog comparator input?
03:03 PM guanche: I was looking at the firmware, and all he does is to lower the voltage on each cycle to find the crest of the signal
03:03 PM cehteh: yeah
03:04 PM guanche: yes, but it's not somthing you can tweak as far as I can say
03:04 PM cehteh: possible can be done in difernt ways
03:04 PM guanche: sure
03:04 PM cehteh: but be careful to protect all pings from voltage peaks with protection diodes
03:04 PM cehteh: pins
03:04 PM cehteh: fatass coil doesnt look comfortable for a µC
03:04 PM guanche: if I use the PCM you mean
03:05 PM cehteh: either way, always in that circuit
03:05 PM guanche: otherwise all I needed is to read opamps output, which I can clamp easily
03:06 PM cehteh: dunno how much opamps like 1kV on the input :D
03:06 PM guanche: well, there are zenners there
03:06 PM cehteh: you really need flyback paths and clip the voltage with diodes
03:06 PM cehteh: yeah
03:07 PM guanche: I'd prefer using an atmega, which I'm more comfortable with, but I don't know if the ADC will be up for it (probably yes)
03:07 PM cehteh: in your circuit they where not
03:07 PM guanche: but if it wasn't, I'd need to start all over again
03:07 PM guanche: not in mine's, it was just a "preview" of what I thougth
03:08 PM guanche: neither you can see the capacitor from the tank there
03:08 PM cehteh: the opamp one
03:08 PM guanche: what opamp?
03:08 PM cehteh: err optocoupler
03:09 PM guanche: ah yes, that was me conentrating on switching the mosfet, mostly
03:10 PM guanche: so first I should try simply with a pulldown an a small resistor to the gate of the mosfet, directly, won't that cause harm in any way?
03:12 PM cehteh: should be ok and then drive with a pnp ...
03:13 PM guanche: I'll try tomorrow and have a look at the oscilloscope, I already have the blupeill programmed to output the PWM the guy mentions, and the coil wound
03:15 PM guanche: however I went for the totem pole because it's seems to be it would be better to bang the mosfet open, so that it gives more power to the coil, and detects better, I'll see
03:15 PM LeoNerd: FETs are voltage- driven, not current
03:15 PM LeoNerd: Your class A driver is for supplying current, which isn't needed here
03:16 PM guanche: yes, but do you think an stm32 can bang open that mosfet?
03:16 PM LeoNerd: A small (resistance; large value) pullup/down resistor and a single bypass transistor are perfectly sufficient to control a FET gate
03:16 PM LeoNerd: Not on its own, because of Vgs, which I believe you quoted as 5V?
03:16 PM LeoNerd: Again I haven't read the..
03:16 PM LeoNerd: screwit you're making me work now. I shall read the datasheet
03:16 PM guanche: no, it's 20V, but this mosfet works OK at 5V, for this application
03:16 PM guanche: no, don't worry LeoNerd
03:17 PM guanche: just a regular mosfet
03:17 PM LeoNerd: IRL6130
03:17 PM LeoNerd: I don't believe 20V
03:17 PM LeoNerd: I suspecy you are reading the wrong bit
03:17 PM guanche: that's what it says on VGS (th), let me check
03:18 PM LeoNerd: IRL6130 - are you quite sure?
03:18 PM LeoNerd: https://www.google.com/search?q=IRL6130+fet
03:21 PM el-especial: it's IRLI630, and I actually have 2sk2161, let me now check the details
03:22 PM LeoNerd: 2SK2161 - 2.5V
03:22 PM LeoNerd: So your bluepill is fine
03:22 PM LeoNerd: Stick a single series current-limiting resistor to avoid ringing at switch times, and call it done
03:23 PM LeoNerd: It even says "low voltage drive" in the headline list at the top of the data sheet. That's usually code-words for "can be driven directly from your MCU"
03:23 PM el-especial: oh I see it now, it's VGS
03:24 PM el-especial: yes, I knew it could be driven from 5V, I don't know why I got into that it was a normal mosfet that happened to be happy at 5V
11:45 PM day_ is now known as day