Analog write pwm

Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet2016.pdf (3.9 MB)

Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet2016.pdf (3.9 MB)

It seems that you don't understand what PWM is.

An output pin can only be HIGH or LOW, (about) 0volt or (about) 5volt, nothing in between.
With value of 127, the pin is 50% of the time LOW and 50% of the time HIGH.

If you measure that with a voltmeter, then it might show 2.5volt, because a DMM is slow, and averages readings. If you measure that with a scope, then you see the voltage jump between 0volt and 5volt.

The logic voltage of a pin depends on the supply voltage of the MCU, which is rarely exactly 5.0volt. With a classic Nano it also depends on how you power it. Expect about 4.7volt on USB supply.
And then there is the internal resistance of the pin's mosfets (about 25ohm). They form a voltage divider with the load you're driving with the pin, lowering pin voltage.
Leo..

Clearly you did not understand my link I sent you in post#2

Have another look at it in the light of what @Wawa told you in post#23

If you still have the 270 ohm resistor connected and you look at the signal on an oscillocsope, you will see a square wave signal that goes from almost zero volts to 4.73V.
The average will be 2.365V.

1 Like

Hi JIM, Analog write 255 gives me 4.73v with the resistor. Without the resistor I get 5v as suggested. Then unfortunately all the other analog writes are too low because of the resistor drain. Can cause problems in programming.

You do if you use a capacitor grumpy mike. I use a 22uf. That averages it out.

Thats not correct. Read the help instructions.

Where does the 22uF cap fit in. Is that a 270ohm/22uF lowpass filter?
If so, then the load on the pin is not the current that a 270ohm resistor would cause.
Please tell us what your true goal is.
Leo..

vcc is 5v with an input of 7v. Some regulators may require a drop of 3v rather than 2v only. I am getting a very accurate 5v reading on the multimeter.

Note that the mosfet switches of the MCU can have an 'on' resistance of about 20 to 40 ohm.
That 270ohm resistor could have 270 / (20 + 270) * 5 = 4.65volt or 270 / (40 + 270) = 4.35volt across. That MCU mosfet resistance varies per pin and is temp dependent.
Leo..

The regulator on a classic Nano v3 is an LDO (low dropout), with a minimum dropout voltage of about 1volt. Only the old style regulators (LM7805, LM317, etc) required more than 2volt.
Leo..

The 22uf capacitor averages out the pwm signal. Unfortunately the 274 ohm resistor causes a drop in the output voltage of the pwm. If there is no 274 resistor the output for an analog write 255 is 5v. I have achieved what I wanted with these values regardless of the inaccuracies. To explain it all would require just too much explaining. I might as well write a book on electronics.

You could at least have explained the relationship betwen the 270ohm resistor and the 22uF capacitor. If this is a low pass filter (to change PWM into a voltage), then why a very low resistor value. Couldn't you have used a 10k resistor. Then the negative effect from the Rds(on) of the MCU mosfets would be much less of a problem.
Leo..

I would be very interested in reading the chapter on PWM.

Let's recap here, as I recall it is you asking the questions and then you are rejecting what every one else, many with a vast experience in these matters, have said.

In my book :-

I do show, on page 304, the same diagram of PWM that I showed in an animated version of on my webpage link. Page 305 shows two types of low pass filters with the formular for calculating the required roll of frequency of the filter. Is this then going to be different when you write your book?

So you might as well mark you problem as solved and stop wasting every one's time.

1 Like

You miss the point Grumpy Mike. I would rather have accurate data in the first place which I am getting from answers on this forum. I am not rejecting them as you say.
What has happened is I have by accident more than by design achieved what I wanted from my MCU. When I designed originally I assumed I was getting 5v from analog write 255 but I wasn't. So then with a little trial and error in my programming I managed to get the whole thing working.
When revisiting this program a year later I can see in writing down the values of hardware I made a huge blunder. I left out the decimal in a resistor value 3.6k so it read 36k. This is why it wasn't working now when I know it did a year earlier.

According to design, the unloaded DPin-3 is assumed to arrive at logic HIGH (4.2 V to Vcc = 5V) when analogWrite(3, 255); is executed. If you connect a load at DPin-3, then the load should be such that VOH does not drop below 3.0 V (VIH).
portIOElectCharac-2

1 Like

So is your problem solved or do you still need help?

Should be ok now jim. Thanks

Have a nice day