Esempio n. 1
0
int mdaq_pwm_setup(uint8_t channel, uint32_t period, uint8_t polarity)
{
#if (!defined MATLAB_MEX_FILE) && (!defined MDL_REF_SIM_TGT)
	period *= PWM_PERIOD_TO_US;
	mdaq_pwm_period[channel] = period;
	ehrpwm_pwm_set_prd(channel, period, polarity);
	ehrpwm_pwm_set_dty(channel, 0);
#endif 
	return 0;
}
Esempio n. 2
0
int mdaq_pwm_set_duty(uint8_t channel, float duty)
{
#if (!defined MATLAB_MEX_FILE) && (!defined MDL_REF_SIM_TGT)
	uint32_t tmp;

	if (duty > 100.0)
		duty = 100.0; 
	if (duty < 0.0)
		duty = 0.0;

	tmp = (uint32_t)((float)mdaq_pwm_period[channel] * (duty / 100.0));
	return ehrpwm_pwm_set_dty(channel, tmp);
#endif 
}
Esempio n. 3
0
static int ehrpwm_pwm_config(struct pwm_device *p,
	struct pwm_config *c)
{
	int ret = 0;

	switch (c->config_mask) {
	case BIT(PWM_CONFIG_PERIOD_TICKS):
		if (p->max_period_ticks &&
				(p->max_period_ticks >= c->period_ticks))
			p->period_ticks = p->max_period_ticks;
		else
			p->period_ticks = c->period_ticks;

		ret = ehrpwm_pwm_set_prd(p);
		break;

	case BIT(PWM_CONFIG_DUTY_TICKS):
		p->duty_ticks = c->duty_ticks;
		ret = ehrpwm_pwm_set_dty(p);
		break;

	case BIT(PWM_CONFIG_POLARITY):
		p->active_high = c->polarity;
		ret = ehrpwm_pwm_set_pol(p);
		break;

	case BIT(PWM_CONFIG_START):
		 ret = ehrpwm_pwm_start(p);
		 break;

	case BIT(PWM_CONFIG_STOP):
		ret = ehrpwm_pwm_stop(p);
		break;

	default:
		dev_dbg(p->dev, "%s: Invalid configuration\n", __func__);
		ret = -EINVAL;
	}

	return ret;
}