PWM Input driver test

Test setup

The PWM input driver was tested with the agilent 33521A waveform generator.

Waveform generator setup:

  • Press the "Waveforms" button
    • Select the pulse waveform
    • Choose a frequency (I tested this with 1kHz since this is what the J1772 Spec requires for an EV charger on the PWM input
    • Choose an amplitude (I chose 3vpp, I tested it to work with voltages as low as 1.6vpp, although it may depend on the timer)
    • Choose a pulse width in us. This will be equal to the DC percent since we used 1kHz for our frequency
  • Press the modulate button
    • Turn the "modulate" option on
    • Select type "PWM"
    • Set width deviation to 0
    • Select the "shape" to be sine
  • When you want to begin generating the PWM signal, hit the "channel" key, and select output = on

PWM Slave setup:

  • Flash the PWM slave project onto a controller board
  • Attach the waveform generators ground to the controller board ground.
  • Attach the waveform generators output to pin A6 (check the source code to make sure this hasn't changed)
  • You can now open minicom to see the frequency and DC (minicom -D /dev/ttyACM0)

Test results

The driver will produce defined results for values a pulse width that is greater than or equal to 75ns. If a pulse width less than 75ns occurs the PWM driver reads this as 100% DC.

Otherwise, readings for period are accurate to +- 2 Hz, and DC readings are accurate to +- 1 % under ideal conditions.

As well, undefined behaviour occurs if the pin you choose is not connected to anything. In order to work around this, you can check if the frequency is in the expected range, and if it is not, discard the data.

Pin restrictions

This PWM driver requires capture compare / input capture functionality on the desired timer. As well, only channels 1 & 2 can be used because of restrictions in the stm32 library (eg, TIM3_CH1, TIM3_CH2). Therefore when designing hardware, make sure that a PWM input is attached to a pin that supports a timer that will work with the driver. I've tested this driver with pin A6, A7, and A8 and it's worked with the configuration above. As well, TIM2 cannot be used because it is used by our software timer library. If in doubt, you can use the pwm_slave project to test your configuration. Finally, the PWM input driver cannot use the same timer as the PWM output driver because the PWM output driver will use all the channels on a timer.

PWM output can use pins which support the following (untested, judging from source code):

  • TIM1
  • TIM3
  • TIM14
  • TIM15
  • TIM16
  • TIM17

PWM input can use these timers:

  • TIM1 (tested on channel 1)
  • TIM3 (tested on channels 1 and 2)
  • TIM14
  • TIM15
  • TIM16
  • TIM17

To check which timers correspond to which pins, see the stm32f072_af.xlsx spreadsheet on confluence.