PWM channel 0

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

Hi freaks,

I am struggling with ASF and it seems harder than I expected. After running a blink, I am trying to generate a PWM waveform on channel 0. This is my code:

#include 
#include 
pwm_channel_t pwm_channel_instance;
#define MY_LED IOPORT_CREATE_PIN(PIOC, 22)

int main (void)
{
	board_init();
	sysclk_init();
	ioport_set_pin_dir(MY_LED, IOPORT_DIR_OUTPUT);
	ioport_set_pin_level(MY_LED, LOW);
	
	
	 pwm_channel_t pwm_channel_instance;

	 pmc_enable_periph_clk(ID_PWM);

	 pwm_channel_disable(PWM, PWM_CHANNEL_0);

	 pwm_clock_t clock_setting = {
		 .ul_clka = 1000 * 100,
		 .ul_clkb = 1000 * 100,
		 .ul_mck = 84000000
	 };
	 pwm_init(PWM, &clock_setting);

	 pwm_channel_instance.ul_prescaler = PWM_CMR_CPRE_CLKA;
	 pwm_channel_instance.ul_period = 100;
	 pwm_channel_instance.ul_duty = 20;
	 pwm_channel_instance.channel = PWM_CHANNEL_0;
	 pwm_channel_init(PWM, &pwm_channel_instance);
	 pwm_channel_enable(PWM, PWM_CHANNEL_0);
while(1){
	delay_ms(1);
	ioport_set_pin_level(MY_LED, HIGH);
	delay_ms(1);
	ioport_set_pin_level(MY_LED, LOW);
}
}


I expect to get a PWM code on pin PWML0(PC2) but ge nothing. BTW, I read somewhere that LPCXpresso with codered IDE is way better with ready to use functions. Has anybody worked? I am wondering to move to LPC to save time digging in ASF.

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

I sent you a PM.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius