Skip to content

Instantly share code, notes, and snippets.

@joseluu
Created November 2, 2017 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseluu/fbc0281ecd5ef343ebc65a5da732e142 to your computer and use it in GitHub Desktop.
Save joseluu/fbc0281ecd5ef343ebc65a5da732e142 to your computer and use it in GitHub Desktop.
STM32F334 HRTIM PWM
compareCfg.CompareValue = min(period - 96, max(95, previousValue + update));
previousValue = compareCfg.CompareValue;
if (compareCfg.CompareValue < 96) {
   stopped_timer = true;
   HAL_HRTIM_WaveformOutputStop(&hhrtim1,
      HRTIM_OUTPUT_TC1);
   HAL_HRTIM_WaveformSetOutputLevel(&hhrtim1,
      HRTIM_TIMERINDEX_TIMER_C,
      HRTIM_OUTPUT_TC1,
      HRTIM_OUTPUTLEVEL_INACTIVE);
} else if (compareCfg.CompareValue >= period - 96) {
   stopped_timer = true;
   HAL_HRTIM_WaveformOutputStop(&hhrtim1,
      HRTIM_OUTPUT_TC1);
   HAL_HRTIM_WaveformSetOutputLevel(&hhrtim1,
      HRTIM_TIMERINDEX_TIMER_C,
      HRTIM_OUTPUT_TC1,
      HRTIM_OUTPUTLEVEL_ACTIVE);
} else {
   if (stopped_timer) {
      HAL_HRTIM_WaveformOutputStart(&hhrtim1,
      HRTIM_OUTPUT_TC1);
      stopped_timer = false;
   }
   HAL_HRTIM_WaveformCompareConfig(&hhrtim1,
      HRTIM_TIMERINDEX_TIMER_C,
      HRTIM_COMPAREUNIT_1,
      &compareCfg);
}
@joseluu
Copy link
Author

joseluu commented Nov 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment