- The HRPWM block typically expects duty cycle inputs in a fixed-point format. This is because the hardware operates with fixed-point arithmetic to control the PWM signal.
- The input is usually represented as a fraction of the PWM period, where 0 corresponds to 0% duty cycle and 1 corresponds to 100% duty cycle.
- If your design uses double precision floating-point numbers (ranging from 0.0 to 1.0 for duty cycle), you need to convert these to a fixed-point representation.
- The correct format often involves using a scaled integer representation that matches the resolution of the PWM hardware. For instance, a 16-bit PWM might expect values in a range from 0 to 65535 to represent 0% to 100%.
- You can use “Data Type Conversion” block to convert the floating-point input to a fixed-point format. Set the output data type to uint16 or another appropriate fixed-point type based on your PWM resolution.
- You can use a “Saturation” block to ensure that the converted value stays within the valid range (0 to 65535 for 16-bit).
- The “floor” function is used in the conversion to ensure that the floating-point value is rounded down to the nearest integer.
- “HRPWM” block: https://www.mathworks.com/help/releases/R2021b/supportpkg/texasinstrumentsc2000/ref/c280xc2802xc2803xc2805xc2806xc2833xc2834xf28m3xf2807xf2837xdf2837xsf2838xf28004xf28002xepwm.html
- “Data Type Conversion” block: https://www.mathworks.com/help/releases/R2021b/simulink/slref/datatypeconversion.html
- “Saturation” block: https://www.mathworks.com/help/releases/R2021b/simulink/slref/saturation.html