Pwm output not 5v

Hi

Im trying to control a few things via pwm. 2 of 3 are working but i cant get motor speed control to work.

I have a 12v mains power going into a 5v bec. Which supplys arduino.

I supply the power + to motor and setup pwm on digital pin 9. Set fast pwm. And analogwrite to pin with pwm duty rate. Say 50 percent. This is outputted to a n channel mosfet which switches the earth side of the motor.

On other pwm pins i get 5v output. But on the motor pin i get half of 5v for 50 percent. Etc. I tried different pins but no joy.

More i think about it. Must be code but im not sure and cant get my head round it

Iv attached some code. Pretty new to coding

float mapf(float x, float in_min, float in_max, float out_min, float out_max) {
x = constrain(x, in_min, in_max);
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void burn_fan() {
int percent_map = mapf(fan_speed, 0, 100, 0, 255);
analogWrite(burn_fan_pin, percent_map);
}

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

Iv attached arduino file as was to bit to post

Everything works apart from PWM burn fan control.

At 255 pwm (or 100%) i get 5v Digital pin 9 output and full 12v across supply + and Mosfet output(center Pin).

At half that pwm (or 50%) duty i get same voltage across supply + and mosfet output but get 2.36v at the mosfet from D9 pwm signal

Is this normal? I can only test with a multimeter as dont have scope but im sure it makes sense to have 5v and control is with pulse lenght …

Sadly its impossible to show my wiring but on picture i can, see attached. has components on too. Prob only current difference atm is across the mosfets i have 10k pulldown resistors

On picture i currently dont have water pump even coded or installed so ignore that, but everything else works. but dont use PWM for control like a fan.

Do i need a dedicated pwm fan control for 2 wire fans? or will this work? Should I see voltage at mosfet center pin and main supply 12v +

circuit.jpg

heater5wz.ino (11 KB)

Measuring the voltage of a PWM waveform is next to impossible with a DVM; at best you might get an average.

Send a slow ON/OFF signal to the pin, similar to the ‘Blink’ sketch.

You should see 0v to 12v at the Drain of the N channel MOSFET.

Is this a logic MOSFET? (I see from your image it is)

When using a single device to switch an inductive load you need a free-wheel diode across the load to prevent damage, and the average across the load voltage is not linear with PWM - search for "decay mode" to see the kind of waveform involved and you should be able to see why.

Hi guys. Thanks for the replys

I am using a logic level mosfet with protection diode.

So really this should work no issues... im not sure why its not....

Before trying on real load i hooked up a led on 5v circuit with mosfet switching the earth and it worked.

I understand about the need for scope for pwm. But i thought what ever pwm value from 0 to 255 id still see 5v at digital pwm pin out regardless. I fuess that wouldnt be the case.

Does the code look ok for the control for burn_fan?

Thanks
Paul

Paul2k1uk:
But i thought what ever pwm value from 0 to 255 id still see 5v at digital pwm pin out regardless. I fuess that wouldnt be the case.

Your DMM in DC mode is looking at the PWM and displays the AVERAGE of what it sees.
As you change the duty cycle so will the DC voltage.

If at first you did not have a load on any of the MOSFET drains, then of course you would be getting erroneous measurements.
You have to have current flowing through the MOSFET for it to control.
If there is no load, then there is no current.
The LED load draws enough current for the MOSFET to work.
What are you going to use as a 12V supply and do you have fuses to protect your loads.

Tom.... :slight_smile:

Hi tom

The supply is 12v car battery. Fused supply to a 12v motor that pumps fresh air into a combustion chamber to mix with fuel. Fuel pulses are controlled by a mosfet also which works fine. This is also then ignited by a glow plug. Which is also controlled by its own mosfet. Correctly working.

I think i need to try again and see. If everything looks ok

Thanks
Paul

Most DMM's use an integrating ADC, which means they average very linearly. Some newer ones use fast ADCs which sample at points in time rather than averaging, leading to flickering display value on a time-varying signal.

Some have both, using the integrating ADC to drive the numerical display, and the fast ADC to drive a bar-graph graphic allowing fluctuations to be noticed even if the average is steady.

Paul2k1uk:
Hi tom

The supply is 12v car battery. Fused supply to a 12v motor that pumps fresh air into a combustion chamber to mix with fuel. Fuel pulses are controlled by a mosfet also which works fine. This is also then ignited by a glow plug. Which is also controlled by its own mosfet. Correctly working.

I think i need to try again and see. If everything looks ok

Thanks
Paul

What is the project, sounds interesting?

TomGeorge:
What is the project, sounds interesting?

On my car i have a parking heater. That is connected to the coolant system. On cold mornings it starts up when engine is running and heats up the water to help with heating and engines run better hot.

Sadly the original ecu is toast with a internal fault where system crashes mid heat. So im replacing it with a arduino brain. With a idea to run this independent from the engine checks and maybe have it power up remotely via bluetooth or wifi :slight_smile:

Thanks for your interest :slight_smile:

Paul