Hi,
I'm very new to embedded development in general and chibios in particular.
I need to write a program that activates 4 individually controlled PWM channels on external pins on an STM32F4Discovery development board.
I managed to get PWM up and running but am facing two problems.
1. My PWM output oscillates between +1.5v and -1.5, I am using a power FET to drive high current LEDs with the PWM signal for controlling their brightness but as the power FET requires 3V to fully switch on I need to make my PWM signal Oscillate between +3V and 0V. is there any simple way in which I can achieve that in software?
my output pins are currently set like so:
palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(2)); // Port PB8
palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(2)); //Port PB9
2. I need to switch on the LEDs only when an external pin goes high and I need the LEDs to switch back off (ie. PWM output gets switched off) when the signal on the external pin goes low. I believe that I need to enable an external interrupt on an external pin with a conditional statement for pwmDisableChannelI() and pwmEnableChannelI() but I could not find any examples on enabling a simple external interrupt.
any help would be greatly appreciated!
thank you
Set PWM output range between VDD and GND
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Set PWM output range between VDD and GND
Hi,
The PWM output (and all outputs from the MCU) always go from GND to VDD, That 1.5V...-1,5V must be a measurement error.
If you need an interrupt (callback) from an input pin then look into the EXT driver, there are demos under ,/testhal.
Giovanni
The PWM output (and all outputs from the MCU) always go from GND to VDD, That 1.5V...-1,5V must be a measurement error.
If you need an interrupt (callback) from an input pin then look into the EXT driver, there are demos under ,/testhal.
Giovanni
Re: Set PWM output range between VDD and GND
Hi,
thank you for the quick reply, I will look into the EXT driver.
I should have probably noted that the GND point I am measuring from is the actual GND pin on the board, I assumed that there is no necessary initialisation for that and hence based on the GND pin ground point my oscilloscope shows the signal oscillating between -1.5v and 1.5v and the power FET does not react to the PWM control signal as it should for a 3v signal (ie. my LEDs are very dim even when set to 100% brightness as the FET does not fully switch on.
I will look into the issue again and do some more testing
thank you!
thank you for the quick reply, I will look into the EXT driver.
I should have probably noted that the GND point I am measuring from is the actual GND pin on the board, I assumed that there is no necessary initialisation for that and hence based on the GND pin ground point my oscilloscope shows the signal oscillating between -1.5v and 1.5v and the power FET does not react to the PWM control signal as it should for a 3v signal (ie. my LEDs are very dim even when set to 100% brightness as the FET does not fully switch on.
I will look into the issue again and do some more testing
thank you!
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Set PWM output range between VDD and GND
It should be something unrelated to software, I/Os always swing between 0 and 3 Volts.
Are the MCU and FETs un the same ground? are you sure 3V are sufficient in order to obtain the full current?
Giovanni
Are the MCU and FETs un the same ground? are you sure 3V are sufficient in order to obtain the full current?
Giovanni
Re: Set PWM output range between VDD and GND
my oscilloscope shows the signal oscillating between -1.5v and 1.5v
That may happen in case you use capacitive coupling..
The output of the F4 shall be coupled directly to the gate of the n-channel MOSFET via a small resistor (like 100ohm) to avoid over-current when charging/discharging the MOSFET's gate capacitance.
Also a 10kohm pull-down resistor (from the MOSFET's gate to the gnd) is usually required.
Mind you need a "logic level" MOSFET, otherwise it will not be properly switched on/off. There are power MOSFETs with Vgs (gate threshold voltage) of 4-9V which will not work when directly driven from F4.
In case you want to use such MOSFET, you must have a "MOSFET Gate driver" wired between F4 and the MOSFET's gate.
Re: Set PWM output range between VDD and GND
Are you sure you have the scope input configured in DC coupling? +/- 1.5V looks like AC coupling, i.e., the DC is removed (and the signal is centered to 0V).
If you measure the Vdd pin on the discovery board, w.r.t. gnd, what do you get?
If you measure the Vdd pin on the discovery board, w.r.t. gnd, what do you get?
Re: Set PWM output range between VDD and GND
Lets give a more detailed explanation as in why a mcu pin can never go below GND/VSS.
Take a look at this block diagram of an mcu pad.
You will see a few multiplexers, an input stage, an fet driven output stage and a pull-up/down stage.
And most important, protection diodes.
The moment the pad voltage goes above Vdd+0.5 or below Vss-0.5 the diodes will open and take everything.
If you really measure a negative voltage on your mcu pad, something will die. Or you measure with a wrong reference.
Take a look at this block diagram of an mcu pad.
You will see a few multiplexers, an input stage, an fet driven output stage and a pull-up/down stage.
And most important, protection diodes.
The moment the pad voltage goes above Vdd+0.5 or below Vss-0.5 the diodes will open and take everything.
If you really measure a negative voltage on your mcu pad, something will die. Or you measure with a wrong reference.
Re: Set PWM output range between VDD and GND
I am honestly not sure what was going on with my measurements back there but it is all sorted now.
I did have DC coupling and the voltage between VDD and GND was 3V as I was expecting. the MOSFETS I was driving had a Vgs of 2V, or so the datasheet stated. The problem was solved by simply changing the MOSFETs I was using.
Thank you everyone for your help! massively appreciated
I did have DC coupling and the voltage between VDD and GND was 3V as I was expecting. the MOSFETS I was driving had a Vgs of 2V, or so the datasheet stated. The problem was solved by simply changing the MOSFETs I was using.
Thank you everyone for your help! massively appreciated