Пример #1
0
void PWM_Handler(void)
#endif
{
	static uint32_t ul_count = 0;  /* PWM counter value */
	static uint32_t ul_duty = INIT_DUTY_VALUE;  /* PWM duty cycle rate */
	static uint8_t fade_in = 1;  /* LED fade in flag */

#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
	uint32_t events = pwm_channel_get_interrupt_status(PWM0);
#else
	uint32_t events = pwm_channel_get_interrupt_status(PWM);
#endif

	/* Interrupt on PIN_PWM_LED0_CHANNEL */
	if ((events & (1 << PIN_PWM_LED0_CHANNEL)) ==
	(1 << PIN_PWM_LED0_CHANNEL)) {
		ul_count++;

		/* Fade in/out */
		if (ul_count == (PWM_FREQUENCY / (PERIOD_VALUE - INIT_DUTY_VALUE))) {
			/* Fade in */
			if (fade_in) {
				ul_duty++;
				if (ul_duty == PERIOD_VALUE) {
					fade_in = 0;
				}
				} else {
				/* Fade out */
				ul_duty--;
				if (ul_duty == INIT_DUTY_VALUE) {
					fade_in = 1;
				}
			}

			/* Set new duty cycle */
			ul_count = 0;
			g_pwm_channel_led.channel = PIN_PWM_LED0_CHANNEL;
#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
			pwm_channel_update_duty(PWM0, &g_pwm_channel_led, ul_duty);
#else
			pwm_channel_update_duty(PWM, &g_pwm_channel_led, ul_duty);
#endif
			g_pwm_channel_led.channel = PIN_PWM_LED1_CHANNEL;
#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
			pwm_channel_update_duty(PWM0, &g_pwm_channel_led, ul_duty);
#else
			pwm_channel_update_duty(PWM, &g_pwm_channel_led, ul_duty);
#endif
		}
	}
}
/**
 * \brief Interrupt handler for the PWM controller.
 */
void PWM0_Handler(void)
{
	static uint32_t ul_count = 0;  /* PWM counter value */
	static uint32_t ul_duty = INIT_DUTY_VALUE;  /* PWM duty cycle rate */
	static uint8_t fade_in = 1;  /* LED fade in flag */

	uint32_t events = pwm_channel_get_interrupt_status(PWM0);

	/* Interrupt on PIN_PWM_LED0_CHANNEL */
	if ((events & (1 << PIN_PWM_LED0_CHANNEL)) ==
	(1 << PIN_PWM_LED0_CHANNEL)) {
		ul_count++;

		/* Fade in/out */
		if (ul_count == (PWM_FREQUENCY / (PERIOD_VALUE - INIT_DUTY_VALUE))) {
			/* Fade in */
			if (fade_in) {
				ul_duty++;
				if (ul_duty == PERIOD_VALUE) {
					fade_in = 0;
					}
				} else {
				/* Fade out */
				ul_duty--;
				if (ul_duty == INIT_DUTY_VALUE) {
					fade_in = 1;
				}
			}

			/* Set new duty cycle */
			ul_count = 0;
			g_pwm_channel_led.channel = PIN_PWM_LED0_CHANNEL;
//jsi 16feb16			pwm_channel_update_duty(PWM0, &g_pwm_channel_led, ul_duty);
					pwm_channel_update_duty(PWM0, &g_pwm_channel_led, (PERIOD_VALUE/2)); //jsi 16feb16 just fixed for now
//jsi 15feb16			g_pwm_channel_led.channel = PIN_PWM_LED1_CHANNEL;
//jsi 15feb16			pwm_channel_update_duty(PWM0, &g_pwm_channel_led, ul_duty);
		}
	}
}
Пример #3
0
void PWM_Handler(void)
{
	/* Para utilizar interrupção do pwm configurar e habilitar em six_step.c */
	
	static uint32_t ul_count = 0;  /* PWM counter value */
	static uint32_t ul_count2 = 0;
	static uint8_t sub = 1; // 1 -> subindo; 0 -> descendo;
	
	uint32_t events = pwm_channel_get_interrupt_status(PWM);

	/* Interrupt on PIN_PWM_IN1_CHANNEL */
	if ((events & (1 << PIN_PWM_IN1_CHANNEL)) == (1 << PIN_PWM_IN1_CHANNEL))
	{
		ul_count++;
		if (ul_count == (PWM_FREQUENCY*10 / (PERIOD_VALUE - INIT_DUTY_VALUE))) // a cada 50ms
		{
			ul_count = 0;
			ul_count2++;
			
			/*rotina para verificar se o motor está rodando*/
			if(motor_aux!=0)
			{
				motor_run = 1;
				motor_aux = 0;
			}
			else motor_run = 0;
			
			/*rotina para realizar o ensaio 1 - ensaio de rampa */
			if (ensaio == 1)
			{
				if (sub)
				{
					if(ul_duty < PERIOD_VALUE) ul_duty++;
					else sub = 0;
				}
				else
				{
					if(ul_duty > INIT_DUTY_VALUE) ul_duty--;
					else sub = 1;
				}
			}
			if (ul_count2 == 20) // a cada 1s
			{
				ul_count2 = 0;
				/*rotina para realizar ensaio 2 - acionamento degrau */
				if	(ensaio == 2)
				{
					if (sub)
					{
						if(ul_duty < PERIOD_VALUE) ul_duty = ul_duty + 20;
						else sub = 0;
					}
					else
					{
						if(ul_duty > INIT_DUTY_VALUE) ul_duty = ul_duty - 20;
						else sub = 1;
					}
				}
			}
		}
	}
}