Created
October 24, 2024 18:53
-
-
Save ximeg/5f339f95b3c7c3d70536d08a7b17aff4 to your computer and use it in GitHub Desktop.
TC waveform output on SAM3X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void init_TC0_waveform() | |
{ | |
sysclk_enable_peripheral_clock(ID_TC0); | |
tc_init(TC0, 0, | |
TC_CMR_TCCLKS_TIMER_CLOCK4 | // select clock source | |
TC_CMR_WAVE | // waveform mode | |
TC_CMR_EEVT_XC0 | // external event selection - enables TIOB output! | |
TC_CMR_ASWTRG_SET | // set A on timer start | |
TC_CMR_ACPA_CLEAR | // clear A on compare event A | |
TC_CMR_ACPC_SET | // set A on compare event C | |
TC_CMR_BSWTRG_SET | // set B on timer start | |
TC_CMR_BCPB_CLEAR | // clear B on compare event B | |
TC_CMR_BCPC_SET | // set B on compare event C | |
TC_CMR_WAVSEL_UP_RC // reset timer on event C | |
); | |
tc_write_ra(TC0, 0, 900000); | |
tc_write_rb(TC0, 0, 700000); | |
tc_write_rc(TC0, 0, 1000000); | |
ioport_set_pin_mode(PIO_PB27_IDX, IOPORT_MODE_MUX_B); // TIOB0 - D13 | |
ioport_disable_pin(PIO_PB27_IDX); | |
ioport_set_pin_mode(PIO_PB25_IDX, IOPORT_MODE_MUX_B); // TIOA0 - D2 | |
ioport_disable_pin(PIO_PB25_IDX); | |
tc_start(TC0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment