So I found some code on here for utilizing the DUE’s timers to create an interrupt. After messing around with it to see how fast I can get the DUE to flip the PORTD values, it is switching from high to low on the one pin at about 680.0 nanoseconds. I was wondering if there was a faster way to do this?
I have attached the code and pasted it below. I apologize in advance if I didn’t provide enough information and for the simple copy and paste of the code below. This is my first post.
void setup() {
// put your setup code here, to run once:
pinMode(14, OUTPUT);
pinMode(9, OUTPUT);
REG_PIOD_OWER = 0x0060;
startTimer(TC1,0,TC3_IRQn, 100000);
}
void TC3_Handler(){
TC_GetStatus(TC1, 0);
REG_PIOD_ODSR = REG_PIOD_ODSR ^ 0x00000010;
}
void loop() {
}
void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency){
//Enable or disable write protect of PMC registers.
pmc_set_writeprotect(false);
//Enable the specified peripheral clock.
pmc_enable_periph_clk((uint32_t)irq);
TC_Configure(tc, channel,TC_CMR_WAVE|TC_CMR_WAVSEL_UPDOWN_RC|TC_CMR_TCCLKS_TIMER_CLOCK1);//|TC_CMR_CPCSTOP);
uint32_t rc = 1;//VARIANT_MCK/128/frequency;
TC_SetRA(tc, channel, rc);
TC_SetRC(tc, channel, rc);
TC_Start(tc, channel);
tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPCS;
tc->TC_CHANNEL[channel].TC_IDR = ~TC_IER_CPCS;
NVIC_EnableIRQ(irq);
}
sketch_jan17a.ino (983 Bytes)