The PWM library using the "Reset-Synchronized PWM mode" of "multi-function timer pulse unit 2 (MTU2)".

Dependents:   Motor_Control_using_lib Motor_Control_API

PwmOutResetSync

In the reset-synchronized PWM mode, three-phase output of positive PWM waveforms that share a common wave transition point can be obtained by combining channels 3 and 4.
When set for reset-synchronized PWM mode, the TIOC3B, TIOC4A, and TIOC4B pins function as PWM output pins and TCNT3 functions as an upcounter.
RZ/A1H infomation.

Output PinDescriptionPin to connect to
TIOC3BPWM output pin 1P8_11, (P7_9), (P3_5)
TIOC4APWM output pin 2P3_8, P4_4, (P7_12), (P11_0)
TIOC4BPWM output pin 3P3_9, P4_5, (P7_13), (P11_1)

():On the GR-PEACH, it can not be used.


API

Import library

Public Member Functions

PwmOutResetSync (PinName pin)
Create a PwmOutResetSync connected to the specified pin.
virtual ~PwmOutResetSync ()
Destructor.
void write (float value)
Set the ouput duty-cycle, specified as a percentage (float)
float read ()
Return the current output duty-cycle setting, measured as a percentage (float)
void pulsewidth (float seconds)
Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
void pulsewidth_ms (int ms)
Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
void pulsewidth_us (int us)
Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
PwmOutResetSync & operator= (float value)
A operator shorthand for write()
operator float ()
An operator shorthand for read()

Static Public Member Functions

static void period (float seconds)
Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
static void period_ms (int ms)
Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
static void period_us (int us)
Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.

Interface

See the Pinout page for more details

PwmOutResetSync.h

Committer:
dkato
Date:
2016-09-08
Revision:
3:2ceb3de67371
Parent:
2:2dbc9553463c

File content as of revision 3:2ceb3de67371:


#ifndef PWMOUT_RESET_SYNC_H
#define PWMOUT_RESET_SYNC_H

#if !defined(TARGET_RZ_A1H)
#error The PwmOutResetSync library is not supported on this target
#endif

#include "platform.h"
#include "pwmout_rst_sync_api.h"

/** A pulse-width modulation digital output
 *
 * Example
 * @code
 * // Moter Control.
 * #include "mbed.h"
 * #include "PwmOutResetSync.h"
 *
 * PwmOutResetSync pwm_l(P4_4);
 * PwmOutResetSync pwm_r(P4_5);
 *
 * int main() {
 *     while(1) {
 *         pwm_l = 0.5;
 *         pwm_r = 0.5;
 *         wait(1);
 *         pwm_l = 0.0;
 *         pwm_r = 0.8;
 *         wait(1);
 *     }
 * }
 * @endcode
 *
 * @note
 *  The PWMs all share the same period - if you change the period for
 *  one, you change it for all.
 *  Routines that change the period maintain the duty cycle for its PWM.
 */
class PwmOutResetSync {

public:

    /** Create a PwmOutResetSync connected to the specified pin
     *
     *  @param pin PwmOutResetSync pin to connect to
     *
     *  @attention
     *   Output Pins for Reset-Synchronized PWM Mode.
     *   [TIOC3B : P8_11, (P7_9), (P3_5)],
     *   [TIOC4A : P3_8, P4_4, (P7_12), (P11_0)],
     *   [TIOC4B : P3_9, P4_5, (P7_13), (P11_1)]
     *   ():On the GR-PEACH, it can not be used.
     *
     */
    PwmOutResetSync(PinName pin) {
        pwmout_rst_sync_init(&_pwm, pin);
    }

    /** Destructor
     *
     */
    virtual ~PwmOutResetSync() {
        pwmout_rst_sync_free(&_pwm);
    }

    /** Set the ouput duty-cycle, specified as a percentage (float)
     *
     *  @param value A floating-point value representing the output duty-cycle,
     *    specified as a percentage. The value should lie between
     *    0.0f (representing on 0%) and 1.0f (representing on 100%).
     *    Values outside this range will be saturated to 0.0f or 1.0f.
     */
    void write(float value) {
        pwmout_rst_sync_write(&_pwm, value);
    }

    /** Return the current output duty-cycle setting, measured as a percentage (float)
     *
     *  @returns
     *    A floating-point value representing the current duty-cycle being output on the pin,
     *    measured as a percentage. The returned value will lie between
     *    0.0f (representing on 0%) and 1.0f (representing on 100%).
     *
     *  @note
     *  This value may not match exactly the value set by a previous <write>.
     */
    float read() {
        return pwmout_rst_sync_read(&_pwm);
    }

    /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
     *
     *  @param seconds Specified in seconds (float). The maximum period is 2s. When you set
     *   a number greater than 2s, 2s is set.
     *
     *  @note
     *   The resolution is currently in microseconds; periods smaller than this
     *   will be set to zero.
     */
    static void period(float seconds) {
        pwmout_rst_sync_period(seconds);
    }

    /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
     *
     *  @param seconds Specified in milli-seconds (int). The maximum period is 2s. When you set
     *   a number greater than 2s, 2s is set.
     */
    static void period_ms(int ms) {
        pwmout_rst_sync_period_ms(ms);
    }

    /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
     *
     *  @param seconds Specified in micro-seconds (int). The maximum period is 2s. When you set
     *   a number greater than 2s, 2s is set.
     */
    static void period_us(int us) {
        pwmout_rst_sync_period_us(us);
    }

    /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
     */
    void pulsewidth(float seconds) {
        pwmout_rst_sync_pulsewidth(&_pwm, seconds);
    }

    /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
     */
    void pulsewidth_ms(int ms) {
        pwmout_rst_sync_pulsewidth_ms(&_pwm, ms);
    }

    /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
     */
    void pulsewidth_us(int us) {
        pwmout_rst_sync_pulsewidth_us(&_pwm, us);
    }

    /** A operator shorthand for write()
     */
    PwmOutResetSync& operator= (float value) {
        write(value);
        return *this;
    }

    PwmOutResetSync& operator= (PwmOutResetSync& rhs) {
        write(rhs.read());
        return *this;
    }

    /** An operator shorthand for read()
     */
    operator float() {
        return read();
    }

protected:
    pwmout_rst_sync_t _pwm;
};

#endif