PWM Module

This module provides a Service (pwm_service_general) to generate center-aligned Pulse-Width modulation(PWM) signals for both high-side and low-side FETs of your Drive module. PWM module can be used to cycle on-and-off a digital signal in order to control a load which requires electrical power. As shown in figure 1, the period and hence the frequency of a pwm signal is always fixed (the default value is 12 kHz). Only the on-time of PWM pulses can be changed. The on-time (for each inverter output can be adjusted by sending the corresponding pwm_value to pwm_service_general through an interface. By this technique, it is possible to modulate a given reference voltage.

The PWM Service should always run over an IF2 Tile so it can access the ports of your SOMANET Drive.

If PWM signals are used to drive an Drive module, the watchdog service should also be running to activate the Drive module ports.

../../../../../../_images/pwm_concept.png

How to use

Important

It is assumed that you are using SOMANET Base and your app includes the required board support files for your SOMANET device.

See also

You might find useful the SOMANET General PWM Demo app, which illustrates the use of some parts of this module.

  1. First, add all the SOMANET Motion Control modules to your app Makefile.

    USED_MODULES = lib_bldc_torque_control module_board-support module_utils module_pwm module_watchdog
    

    Note

    Not all modules will be required, but when using a library it is recommended to include always all the contained modules. This will help solving internal dependency issues.

  2. Include the PWM Service header pwm_server.h in your app.

  3. Include the WATCHDOG Service header watchdog_service.h in your app.

  4. Define the required pwm ports in the board-support-package of your Drive module. By default, these ports are defined for phase A, B and C of the Drive module.

  5. Define the required watchdog ports in the board-support-package of your Drive module. By default, these ports are defined in the board-support-package of each Drive module.

  6. Inside your main function, instantiate the interfaces array for the Service-Clients communication (both watchdog service and pwm service).

  7. At your IF2 tile, instantiate the Services (both PWM service and watchdog service)

  8. At whichever other core, now you can perform calls to the PWM Service through the interfaces connected to it.

    #include <CoreC2X.bsp>              //Board Support file for SOMANET Core C2X device
    #include <Drive1000-rev-c4.bsp>     //Board Support file for SOMANET Drive module
                                        //(select your board support files according to your device)
    
    #include <pwm_server.h> // 2
    #include <watchdog_service.h> // 3
    
    PwmPortsGeneral pwm_ports = SOMANET_DRIVE_PWM_PORTS_GENERAL; // 4
    WatchdogPorts wd_ports = SOMANET_DRIVE_WATCHDOG_PORTS; // 5
    
    int main(void)
    {
        interface update_pwm_general i_update_pwm; // 6
        interface WatchdogInterface i_watchdog[2]; // 6
    
        par
        {
            {
                delay_milliseconds(1000);
                send_pwm_values(i_update_pwm); // 8
            }
    
            /* PWM Service */
            {
                pwm_config_general(pwm_ports);
    
                delay_milliseconds(500);
                pwm_service_general(pwm_ports, i_update_pwm); // 7
            }
    
            /* Watchdog Service */
            {
                delay_milliseconds(200);
                watchdog_service(wd_ports, i_watchdog, IF2_TILE_USEC); // 7
            }
        }
    
        return 0;
    }
    

API

Interface

Warning

doxygenclass: Cannot find class “update_pwm” in doxygen xml output

Warning

doxygenclass: Cannot find class “update_pwm_general” in doxygen xml output

Service

void pwm_service_task(unsigned motor_id, PwmPorts &ports, server interface UpdatePWM i_update_pwm, server interface UpdateBrake i_update_brake, int tile_usec)

Service to generate center-alligned PWM signals for 3 inverter outputs.

it also provides PWM signals to turn on/off an electric brake.

Parameters:
  • motor_id – Motor ID (the default value is 0)
  • ports – Structure type for PWM ports
  • i_update_pwm – Interface to communicate with client and update the PWM values
  • duty_start_brake – PWM value which is used to start the electric brake
  • duty_maintain_brake – PWM value which is used to maintain the electric brake
  • time_start_brake – Required time to start the brake (in milliseconds)
  • tile_usec – Reference clock frequency of IF2 tile (in MHz)
Returns:

void

void pwm_service_general(PwmPortsGeneral &ports, server interface UpdatePWMGeneral i_update_pwm, int freq_kHz, int deadtime_ns)

Service to generate center-alligned PWM signals for 6 inverter outputs (2 power switch for each leg).

It recieves 6 pwm values through i_update_pwm class. The commutation frequency is 15 kHz.

Parameters:
  • ports – Structure type for general PWM ports
  • i_update_pwm – Interface to communicate with client and update the PWM values
  • freq_kHz – pwm frequency - kHz
  • deadtime_ns – deadtime in [ns] (depends on board)
Returns:

void

Definitions

Warning

doxygendefine: Cannot find define “GENERAL_PWM_MAX_VALUE” in doxygen xml output

Warning

doxygendefine: Cannot find define “GENERAL_PWM_MIN_VALUE” in doxygen xml output

_LOCK_ADC_TO_PWM

Define synchronisation mode for ADC sampling.

Default 1 is ‘ADC synchronised to PWM’

_MOTOR_ID

Define Motor Identifier (0 or 1)

Types

PwmPorts

Structure type for PWM ports.

Structure Members:

buffered out port:32 p_pwm

Array of 3 ports for the high-side PWM signals output.

buffered out port:32 p_pwm_inv

Array of 3 ports for the low-side PWM signals output.

buffered out port:32 p_pwm_phase_d

Port for the high-side PWM signal output of an optional 4th phase.

buffered out port:32 p_pwm_phase_d_inv

Port for the low-side PWM signal output of an optional 4th phase.

clock clk

Hardware clock used as time reference.

in port dummy_port

Any unused port.

Used internally for accurate timming

PwmPortsGeneral

Structure type for general purpose PWM ports.

Structure Members:

buffered out port:1 p_pwm_a

Nullable 1-bit port for phase A high-side PWM signal.

buffered out port:1 p_pwm_inv_a

Nullable 1-bit port for phase A low-side PWM signal.

buffered out port:1 p_pwm_b

Nullable 1-bit port for phase B high-side PWM signal.

buffered out port:1 p_pwm_inv_b

Nullable 1-bit port for phase B low-side PWM signal.

buffered out port:1 p_pwm_c

Nullable 1-bit port for phase C high-side PWM signal.

buffered out port:1 p_pwm_inv_c

Nullable 1-bit port for phase C low-side PWM signal.

buffered out port:1 p_pwm_u

Nullable 1-bit port for phase U high-side PWM signal.

buffered out port:1 p_pwm_inv_u

Nullable 1-bit port for phase U low-side PWM signal.

buffered out port:1 p_pwm_v

Nullable 1-bit port for phase V high-side PWM signal.

buffered out port:1 p_pwm_inv_v

Nullable 1-bit port for phase V low-side PWM signal.

buffered out port:1 p_pwm_w

Nullable 1-bit port for phase W high-side PWM signal.

buffered out port:1 p_pwm_inv_w

Nullable 1-bit port for phase W low-side PWM signal.

buffered out port:1 p_pwm_b1

Nullable 1-bit port for phase V high-side PWM signal.

buffered out port:1 p_pwm_inv_b1

Nullable 1-bit port for phase V low-side PWM signal.

buffered out port:1 p_pwm_b2

Nullable 1-bit port for phase W high-side PWM signal.

buffered out port:1 p_pwm_inv_b2

Nullable 1-bit port for phase W low-side PWM signal.

clock clk

Hardware clock used as time reference.

in port dummy_port

Any unused port.

Used internally for accurate timming

FetDriverPorts

Structure type to define the ports to manage the FET-driver in your SOMANET Drive device (if applicable).

Structure Members:

port p_coast

[Nullable] Port for management signals.

out port p_esf_rst_pwml_pwmh

[Nullable] 4-bit Port to enabling operation signals (if applicable in your SOMANET device).

port p_ff1

[Nullable] Port to read out faults (if applicable in your SOMANET device).

port p_ff2

[Nullable] Port to read out faults (if applicable in your SOMANET device).

PWM_SERV_TAG

Structure containing pwm server control data.

Structure Members:

int id
unsigned ref_time
int data_ready
PWM_PHASE_ETAG

Different PWM Phases.

Enum Values:

_PWM_PHASE_A
_PWM_PHASE_B
_PWM_PHASE_C
_NUM_PWM_PHASES

Functions

void predriver(FetDriverPorts &fet_driver_ports)

Initialize the predriver circuit in your SOMANET Drive device (if applicable)

Parameters:
  • fet_driver_ports – Structure of ports to manage the FET-driver in your SOMANET Drive device (if applicable).
Returns:

void

void pwm_config(PwmPorts &ports)

Configure the pwm ports before starting pwm service.

Parameters:
  • ports – Structure type for PWM ports
Returns:

void

void pwm_config_general(PwmPortsGeneral &ports)

Configure the pwm ports before starting pwm service.

Parameters:
  • ports – Structure type for PWM ports.
Returns:

void

unsigned long get_pwm_struct_address(PWM_ARRAY_TYP &pwm_ps)

Converts PWM structure reference to address.

Parameters:
  • pwm_ps – Pointer to PWM control structure
Returns:

Address

void convert_all_pulse_widths(PWM_COMMS_TYP &pwm_comms_ps, PWM_BUFFER_TYP &pwm_buf_ps, unsigned int pwm_max_value, unsigned int pwm_deadtime)

Convert all PWM pulse widths to pattern/time_offset port data.

Parameters:
  • pwm_comms_ps – Pointer to structure containing PWM communication data
  • pwm_buf_ps – Pointer to Structure containing buffered PWM output data
  • pwm_max_value – Maximum pwm value which can be sent to pwm server (number of clock ticks)
  • pwm_deadtime – Number of clock ticks in over deadtime period
Returns:

void

void convert_widths_in_shared_mem(PWM_COMMS_TYP &pwm_comms_ps, unsigned int pwm_max_value, unsigned int pwm_deadtime)

Converts PWM Pulse-width to port data in shared memory.

Parameters:
  • pwm_comms_ps – Pointer to structure containing PWM communication data
  • pwm_max_value – Maximum pwm value which can be sent to pwm server (number of clock ticks)
  • pwm_deadtime – Number of clock ticks in over deadtime period
Returns:

void