H Bridge Motor Control programming

To Control the speed of the elecrow H Bridge motor shield you apply a pwm signal to pin 9.
I understand the pwm ranges from 0 to 255 max.

The power input for the motor is 12 volts dc. If I analogWrite(9,254) I should get 12 volts, I get 8 volts. So I tried analogWrite(9,1022) , which I understand is not legal, I get the full 12 volts.

Any thoughts ?

Any thoughts ?

Get an oscilloscope.

What Arduino are you using?

With an Uno or Mega, for example, analogWrite(pin, 255); is identical to digitalWrite(pin, HIGH);

It is not easy to measure the voltage from a PWM signal because the whole concept of PID is based on the motor coils averaging the PWM. In theory a PWM signal alternates between High volts and zero volts at the PWM frequency.

Viewing the motor voltage with an oscilloscope will show you what is happening.

...R

Iam using an Uno. The voltage output I am talking about is on the elecrow Bridge shield, not the Uno pin 9.

The H Bridge will vary its output proportional to the Uno pin 9 pwm value to a maximum of the H Bridge input voltage, in this case 12 volts.

My main interest is why does analogWrite(9,1022) work, I thought 1022 was an illegal value for a pwm pin, yet it compiles and works.

My main interest is why does analogWrite(9,1022) work, I thought 1022 was an illegal value for a pwm pin, yet it compiles and works.

You have the source of analogWrite.
Why not take a look?

Grarpb:
My main interest is why does analogWrite(9,1022) work,

Perhaps it defaults to 255 ?

As @AWOL said, study the source code. Or save yourself the trouble and just use "legal" values.

...R

As mentioned earlier the "legal " value 255 does not give full output from the H Bridge shield where as the illegal value of 1022 does.

I've only been at this for a month, not sure what you mean by the source code.

Is this something to do with "timers" ans scaling ?

As mentioned earlier the "legal " value 255 does not give full output

Where does it say that? I only saw 254 mentioned.

How are you measuring these voltages? (Hint: A correct answer does not include the words "Cheap digital multimeter")

The source code is the actual code that implements the analogWrite function; on my computer, this is in /usr/share/arduino/hardware/arduino/cores/arduino/wiring_analog.c

On the elecrow.com "Dual motor H Bridge ", 255 locks up the Bridge, maximum allowed is 254 which should still give close to the h Bridge input voltage (12 volts dc) not the 8 volts I am getting.

I have read that the pwm can be affected by the timers, Pin9 uses timer1, and scale, also frequency was mentioned. I have no experience with timers.

I will try looking at the source code, not sure what I'm looking for but will try as suggested

For the last time - how are you measuring the voltage?

Iam talking about the h Bridge output voltage not the pwm Control voltage.

I have connected a dc motor, an led and multimeter to the Bridge output.

They all show reduced voltage at 254 compared to 1022.

My key question is how can an illegal value of 1022 compile and work. Even the manufacture of the Bridge says it should give an overflow.

The only possibility I can see, by Googling like crazy, is the pwm value may be affected by the "timer1" and possibly scale factor, neither of which I have working knowledge, hence my posting here and request for help

Grarpb:
They all show reduced voltage at 254 compared to 1022.

What happens if you try 255?

My key question is how can an illegal value of 1022 compile and work. Even the manufacture of the Bridge says it should give an overflow.

The only possibility I can see, by Googling like crazy, is the pwm value may be affected by the "timer1" and possibly scale factor, neither of which I have working knowledge, hence my posting here and request for help

I have no idea. But all the source code is included with the Arduino IDE so you can easily study it to find the answer.

...R

On the elecrow.com "Dual motor H Bridge ", 255 locks up the Bridge

What does that mean?

Iam talking about the h Bridge output voltage not the pwm Control voltage.

I'm not asking what you're measuring, I'm asking how.
Why won't you answer my questions?

" I have connected a dc motor, an led and multimeter to the Bridge output. "

Three methods used to determine if output is 12 volts or something less.

I have mentioned this numerous times.

Thanks for your previous responses, can't explain the problem any clearer, at this point I give up.

Did you read reply #1?