What is HPWM?

George Sephton

Senior Member
Hi,
I came across a script last year that showed 3 leds fading in and out using pwm, cool effect. But on the 40X2 there is only 2 PWM pins and I won't mind fading 3 lights. So what are the Hpwm pins? Can I fade lights with them?

I don't have the fading light script but i'll have a look and see what I can dig up and then would it be possible to use the c HPWM pins (D.5-D.7) to fade leds, in and out together, so one comes on while the other is half dim.

Finally what does the H mean in the all X2 parts? Suddenely everything's Hi2c, Hspi and Hserout.

Thanks,
George.
 

boriz

Senior Member
I think it stands for Hardware. As in this function is implemented directly in hardware and does not require any special software to achieve it.
 

George Sephton

Senior Member
Yes but I don't understand exactly what PWM is. Also why there is a pwm, pwmduty and pwmout yet only hpwm and hpwmduty...? If there was a hpwmout I wouldn't be asking because it seems too different.
 

hippy

Ex-Staff (retired)
Yes but I don't understand exactly what PWM is.
PWM can be thought of as the output of a series of on pulses and off pulses. The ratio of on to off times being used to affect the 'level' of something. Like pushing a car, short pushes and long breaks will give a speed level that's quite low, long pushes and short breaks give a speed level higher.


Also why there is a pwm, pwmduty and pwmout yet only hpwm and hpwmduty...? If there was a hpwmout I wouldn't be asking because it seems too different.
The PWM command is an entirely software controlled PWM which gives a number of pulses on an output pin.

The PWMOUT ( to distinguish it from PWM ) command uses on-chip hardware to control certain available pins. PWMDUTY allows the PWMOUT duty to be changed without re-initialising the hardware.

The HPWM command is similar to PWMOUT but provides additional control over certain aspects of the advanced on-chip hardware. HPWMDUTY allows the HPWM duty to be changed without re-initialising the hardware.

There is a HPWMOUT; it's just that it is called HPWM. I'll suggest HPWMOUT is added as a synonym for HPWM to future compilers.
 

Grant Fleming

Senior Member
PWM can be thought of as the output of a series of on pulses and off pulses. The ratio of on to off times being used to affect the 'level' of something. Like pushing a car, short pushes and long breaks will give a speed level that's quite low, long pushes and short breaks give a speed level higher.
Time for a newer model car Hippy?!
 

Dippy

Moderator
Maybe he's saving fuel?

All this sort of thing shows up clearly on an oscilloscope.
The ratio of the duration of ONs:OFFs is reflected in the Duty variable.
50% = half the time ON and half the time OFF.

If you average a complete cycle (duty) you can see how you can 'build up' ananlogue voltages. Do duty changes quickly enough and you can build up analogue waveforms e.g. sine waves.

Think of it as an on-off switch where you can control fast the on-off is done (frequency) and how long the ON time is compared to the OFF time (~duty).
 
Top