Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing way to set TIM_CtrlPWMOutputs from timer feature classes. #173

Open
mikepurvis opened this issue Jun 13, 2016 · 2 comments
Open
Assignees

Comments

@mikepurvis
Copy link
Contributor

Calling this function is part of the deprecated initCompare scheme, but there's no way to do it using the feature classes.

This breaks initializing TIM1/8 as h-bridge motor controllers. Here's what you end up having to do:

template<class Pins>
struct timer_features<Timer1, Pins>
{
  typedef Timer1InternalClockFeature InternalClockFeature;
  typedef Timer1CustomGpioFeature<
      TIM1_CH1_OUT<Pins>,
      TIM1_CH1N<Pins>,
      TIM1_CH2_OUT<Pins>,
      TIM1_CH2N<Pins> > GpioDriveFeature;

  static void initDrive()
  {
    // Gah!
    TIM_CtrlPWMOutputs(tim, ENABLE);
  }
};

template<template <typename...> class DriveTimer, class TimerPins>
class DriveHardware
{
  typedef timer_features<DriveTimer, TimerPins> DriveTimerFeatures;

  template< template <typename...> class TimerChannelFeature >
  using DriveChannelFeature = TimerChannelFeature<
    TimerChannelOCModeFeature<TIM_OCMode_PWM1>,
    TimerChannelOCPolarityFeature<TIM_OCPolarity_High>,
    TimerChannelOCNPolarityFeature<TIM_OCPolarity_High>,
    TimerChannelOCPulseFeature<0> >;

  typedef DriveTimer<
    typename DriveTimerFeatures::InternalClockFeature,
    typename DriveTimerFeatures::GpioDriveFeature,
    DriveChannelFeature<TimerChannel1Feature>,
    DriveChannelFeature<TimerChannel2Feature>
  > DriveTimerT;

  DriveHardware(....)
  {
    [ ... ]
    // Eeep!
    DriveTimerFeatures::initDrive();
  }
}

With a feature class for enabling PWM output, the static function and oddball constructor call would be able to go away.

@andysworkshop
Copy link
Owner

I'll add this as part of a more general feature class to control the break functionality offered by some of the timers. I guess it's a safety feature that the MOE bit is initialized low after reset so you have to know about it even if you're not using the break feature that it was designed to support.

@andysworkshop
Copy link
Owner

Mike - see the timer_pwm_break demo. The call you want is timer.enableMainOutput(); that you get from the UnlockedTimerBreakFeature template.

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

No branches or pull requests

2 participants