ATsam3x8e TC0 Interrupt

Discussion around product based on ARM Cortex M3 core.
This forum will be discontinued soon.

Moderators: nferre, ncollot

mdedonato
Posts: 3
Joined: Wed Oct 14, 2015 12:48 am

ATsam3x8e TC0 Interrupt

Wed Oct 14, 2015 12:58 am

I am trying to use the ATsam3x8e chip to control a stepper motor. I have TC0 in waveform mode outputting the correct pulse. The next step for me is to count the number of pulses so that I can stop the motor at the correct time. My thought was to do this in an interrupt and count there. I setup the interrupt to interrupt on RC compare, however for some reason the interrupt is being triggered at a much faster rate than the pulse. Any ideas? See the code below:

Code: Select all

	/* Pulse */
	ioport_set_pin_mode(motor->pulse_pin, motor->pulse_mux);

	/** Disable I/O to enable peripheral mode) */
	ioport_disable_pin(motor->pulse_pin);

	/* Enable clock */
	sysclk_enable_peripheral_clock(motor->tc_id);

	/* Init TC to waveform mode. */
	tc_init(motor->tc, motor->tc_ch,
	/* Waveform Clock Selection */
	motor->tc_clock | TC_CMR_WAVE /* Waveform mode is enabled */
	| TC_CMR_ACPC_TOGGLE /* RA Compare Effect: set */
	//| TC_CMR_ACPC_CLEAR /* RC Compare Effect: clear */
			//| TC_CMR_CPCTRG /* UP mode with automatic trigger on RC Compare */
			| TC_CMR_WAVSEL_UP_RC);

	uint32_t rc, ra;
	rc = (sysclk_get_peripheral_bus_hz(motor->tc) / motor->tc_clock) / 50000;

	tc_write_rc(motor->tc, motor->tc_ch, rc);

	tc_write_ra(motor->tc, motor->tc_ch, ra);

	NVIC_DisableIRQ(motor->irq);
	NVIC_ClearPendingIRQ(motor->irq);
	tc_enable_interrupt(motor->tc, motor->tc_ch, TC_IER_CPCS);
mdedonato
Posts: 3
Joined: Wed Oct 14, 2015 12:48 am

Re: ATsam3x8e TC0 Interrupt

Tue Dec 08, 2015 7:38 pm

Turns out you need to read the status register of the timer in the interrupt in order to have it behave normally.

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest