about setting correct PWM output period

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi,

I'm just a little bit confused now about the correct value to set for PWM output.

The errata of UC3B said the PWM reset at 0x0001, not 0x0000, so this means if I want to have a PWM output of 2s period and 50% duty cycle. and my OSC0 is 16Mhz and my PBA is 16MHz/128 = 125KHz. And i set PWM clock as MCK/8 = 15625Hz.

then I should set PWM to left aligned and:

	// PWM controller configuration.
	pwm_opt.diva = AVR32_PWM_DIVA_CLK_OFF;
	pwm_opt.divb = AVR32_PWM_DIVB_CLK_OFF;
	pwm_opt.prea = AVR32_PWM_PREA_MCK;
	pwm_opt.preb = AVR32_PWM_PREB_MCK;
	
	pwm_init(&pwm_opt);
	
	pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED;       // Channel mode.
	pwm_channel.CMR.cpol = PWM_POLARITY_LOW;            // Channel polarity.
	pwm_channel.CMR.cpd = PWM_UPDATE_DUTY;              // Not used the first time.
	pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_8;  // Channel prescaler. 
	pwm_channel.cdty = 15625;   // Channel duty cycle, should be < CPRD.
	pwm_channel.cprd = 31250;  // Channel period.
	pwm_channel.cupd = 0;   // Channel update is not used here.
	
	pwm_channel_init(PWM_CHANNEL, &pwm_channel); // Set channel configuration to channel 0.
  
	gpio_enable_module_pin(PWM_CHANNEL_PIN, PWM_CHANNEL_FUNCTION);
	
  pwm_start_channels(1 << PWM_CHANNEL);  // Start channel 0.

Is this correct?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

anyone knows?