SAM3X8E Arduino DUE PWM channel 6

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

jure94
Posts: 2
Joined: Thu May 21, 2015 3:31 pm

SAM3X8E Arduino DUE PWM channel 6

Thu May 21, 2015 3:39 pm

Hello,



This if my first post on this forum :)
I have a problem with PWM on channel 6. I use arduino DUE dev. board and I am programming it in Atmel Studio 6.2 with ASF PWM driver. This is what my code looks like:

Code: Select all

#include <asf.h>
pwm_channel_t pwm_channel;
int main (void)
{
	// Insert system clock initialization code here (sysclk_init()).
	sysclk_init();
	board_init();

	// Insert application code here, after the board has been initialized.
	
	pmc_enable_periph_clk(ID_PWM);
	pwm_channel_disable(PWM, PWM_CHANNEL_6);
	pwm_clock_t pwm_clock ={
		.ul_clka = 1000*100,
		.ul_clkb = 0,
		.ul_mck = 84000000
	};
	pwm_init(PWM, &pwm_clock);
	
		pwm_channel.alignment = PWM_ALIGN_LEFT;
		pwm_channel.polarity = PWM_LOW;
		pwm_channel.ul_prescaler = PWM_CMR_CPRE_CLKA;
		pwm_channel.ul_duty = 50;
		pwm_channel.ul_period = 100;
		pwm_channel.channel = PWM_CHANNEL_6;
	pwm_channel_init(PWM, &pwm_channel);
		
	while(1)
	{
		
	}
}
However it does not work. I am just getting started with ASF and would appreciate a bit of help. This is basically just a copied example.
There are no problems when building the solution. I have checked with oscilloscope (pwm channel 6 should be on arduino due pin 7) but it is constantly at 3V.
jure94
Posts: 2
Joined: Thu May 21, 2015 3:31 pm

Re: SAM3X8E Arduino DUE PWM channel 6

Thu May 21, 2015 5:50 pm

So it seems to work now, but I have no idea why.
I included conf_board.h and conf_clock.h and inside conf_board.h uncommented the line #define CONF_BOARD_PWM_LED2. If I comment the define the pin is always high. Could someone explain to me why must the define be present? I tride to use "go to implementation" command but it takes me nowhere, so I am completely lost.
It is great that it works, but I would also like to know why :)

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests