PWM Enabled but not turning on

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

wallywall
Posts: 1
Joined: Mon Feb 15, 2016 12:55 am

PWM Enabled but not turning on

Mon Feb 15, 2016 1:12 am

Hey Everyone!

Beginner but could really use some help. First project using ASF but I do think i'm finally starting to get a better feel for it. However, I am having issues enabling the PWM on my sam4e16e.

Defines

Code: Select all

#define PIN_PWM_PIEZO			PIO_PD22_IDX
#define PIN_PWM_PIEZO_FLAGS		(IOPORT_MODE_MUX_A)
#define PIN_PWM_PIEZO_CHANNEL	PWM_CHANNEL_2

Code: Select all

ioport_set_pin_mode(PIN_PWM_PIEZO, PIN_PWM_PIEZO_FLAGS);
ioport_disable_pin(PIN_PWM_PIEZO);
	
	
// Enable PWM peripheral clock
pmc_enable_periph_clk(ID_PWM);
pwm_channel_disable(PWM,PIN_PWM_PIEZO_CHANNEL);
	
pwm_clock_t clock_setting = {
        ul_clka = 2000 *100, // 2000 Hz
	.ul_clkb =0,
	.ul_mck = sysclk_get_cpu_hz()
};
pwm_init(PWM, &clock_setting);
	
pwm_channel_t _config;
_config.channel = PIN_PWM_PIEZO_CHANNEL;
_config.alignment = PWM_ALIGN_LEFT;
_config.polarity = PWM_LOW;
_config.ul_prescaler = PWM_CMR_CPRE_CLKA;
_config.ul_period = 100;
_config.ul_duty = 50;

pwm_channel_init(PWM, &_config);
pwm_channel_disable_interrupt(PWM, PIN_PWM_PIEZO_CHANNEL, 0);
	
	
pwm_channel_enable(PWM,PIN_PWM_PIEZO_CHANNEL);
	
Then in my main loop to test why this is failing I have

Code: Select all

if(pwm_channel_get_status(PWM) == (1<<4))
			ioport_set_pin_level(LED3_GPIO,ON);
else
	ioport_set_pin_level(LED3_GPIO,OFF);

Other debugging

Code: Select all

volatile uint32_t errors = pwm_fault_get_status(PWM);
This returns: 4197811


LED3_GPIO lights up when I enable the pwm and then runs off when I disable it as expected. The system clock seems fine as I am toggling a different LED and it is at the correct rate. Sort of pulling my hair out on this on. Any ideas? I've followed the examples which is how I got the code I have. Any help would be appreciated!
honzek68
Posts: 5
Joined: Wed Nov 26, 2014 7:01 pm

Re: PWM Enabled but not turning on

Mon Feb 29, 2016 11:29 am

Have a same problem. Have you already found the solution?


Thanks.

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 3 guests