The ETH32 includes two Pulse Width Modulation (PWM) output channels. PWM channels allow you to continuously output a configurable square wave pattern.
One typical use of a PWM signal is to provide variable speed control in a motor circuit. Like all outputs of the ETH32, the PWM outputs are low-current logic level outputs. Therefore in order to drive a load like a motor or other device, you will need to implement an appropriate transistor or FET circuit. With a PWM output, the transistor/FET will always be either fully off or fully on. Instead of controlling motor speed by altering voltage, the PWM signal alters the duty cycle of the motor. For example, the PWM signal may be configured to output a 10KHZ wave. If the PWM output is on for 75% of each wave cycle, the motor will run at a slower speed than if the PWM output is on for 100% of each cycle.
Some other typical uses of a PWM signal include more efficiently driving LED's and mechanical relays. For example, in the case of a mechanical relay, the signal can be briefly set to 100% duty cycle in order to pull the relay closed and then reduced to hold the relay closed, thereby reducing the current used in holding the relay closed.
Functions are provided by the API that make configuring the PWM channels very straightforward (eth32_set_pwm_parameters or SetPwmParameters). In addition, functions are provided that allow you to individually control several aspects of the PWM outputs. For those, you'll need a brief overview of the internal workings of the PWM outputs.
The PWM outputs are internally implemented using a 16-bit digital counter. Both outputs share the same counter. The counter is clocked at a rate of 2MHZ and the clock may be enabled or disabled at any time. For each output cycle, the square wave is created as follows: When the counter starts out at zero, the output signal is initially high. The counter clocks up and hits a configurable threshold at which point the output signal is set low. The counter continues clocking until it reaches the configurable rollover point, which resets the counter back to zero, sets the output signal high, and starts the entire cycle over again.
The rollover point of the counter is called the base period since it determines the length of each square wave output cycle. The threshold point is called the duty period since it determines how long the output will be on for each cycle.
Task | C / C++ | .NET Languages | Visual Basic 6 |
---|---|---|---|
Set PWM parameters (user friendly) | eth32_set_pwm_parameters | SetPwmParameters Method | SetPwmParameters Method |
Get PWM parameters (user friendly) | eth32_get_pwm_parameters | GetPwmParameters Method | GetPwmParameters Method |
Enable/disable PWM clock | PwmClockState Property | PwmClockState Property | |
Enable/disable PWM channel | PwmChannel Property | PwmChannel Property | |
Configure base period | PwmBasePeriod Property | PwmBasePeriod Property | |
Configure duty period | PwmDutyPeriod Property | PwmDutyPeriod Property |