Increasing the resolution of the PWM in STM32

Dear forum,

I am learning the coder capabilities and have connected a Nucleo-F303Re board to PLECS with success.
I connected a potentiometer to an analog input pin. This pin is then read into the carrier for a PWM generator set up using TIM1.

The PWM duty cycle seems to be possible to vary with fine resolution when I measure on the hardware.

However, in the simulation (looking at the scope), I get discrete steps of 0.25 in duty. I.e. the duty shown is either 0, 0.25, 0.5, 0.75 or 1

Even when I create a loopback from the output pins for the PWM, back to digital input pins and try to read them in the scope (in external mode), I get the same corse resolution in the PLECS scope.

Any idea why this could be? Could it have something to do with the update rate of the scope?

Reading the ADC pin shows fine resolution in the scope also in external mode. Thank you.

Hi Jonas,

My first guess would be that your base task frequency (defined by the discretization step size in the Coder Options menu) is four times the frequency of your PWM signal. The Digital In blocks are read once per step.

Your ADC measurements are independent from the discretization step size because you are using untriggered ADCs. These blocks use an internal source that continuously triggers the ADC conversion.

Note: We also provide a Capture block to measure PWM signals. The Capture block would be better suited to measuring the PWM duty cycle than Digital In or ADC blocks.