hello, own arduino uno , i'm considering arduino due. i'm going use many timers drive dot-matrix printer head in order make music, mididesaster has made, simpler hardware. problem is: in datasheet of sam3x8e, 6 channels of timer counters mapped physical pins of processor. read in other topic due's timers using code, address unmapped timers, i'm not sure.
using code, can set timer of isrs tc0_handler through tc8_handler, see table of parameters below. possible use timers without physically mapped pin, such tc1 channel 0 (tc3_handler) shown here:i need generate independent frequencies (5hz - 2khz) , duty cycles @ least 8 channels sam3x8e in order drive printer's pins , need sure if processor able this.code: [select]
volatile boolean l;
//tc1 ch 0
void tc3_handler()
{
tc_getstatus(tc1, 0);
digitalwrite(13, l = !l);
}
void starttimer(tc *tc, uint32_t channel, irqn_type irq, uint32_t frequency) {
pmc_set_writeprotect(false);
pmc_enable_periph_clk((uint32_t)irq);
tc_configure(tc, channel, tc_cmr_wave | tc_cmr_wavsel_up_rc | tc_cmr_tcclks_timer_clock4);
uint32_t rc = variant_mck/128/frequency; //128 because selected timer_clock4 above
tc_setra(tc, channel, rc/2); //50% high, 50% low
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);
}
void setup(){
pinmode(13,output);
starttimer(tc1, 0, tc3_irqn, 4); //tc1 channel 0, irq channel , desired frequency
}
void loop(){
}
here table of parameters:
isr/irq tc channel due pins tc0 tc0 0 2, 13 tc1 tc0 1 60, 61 tc2 tc0 2 58 tc3 tc1 0 none <- line in example above tc4 tc1 1 none tc5 tc1 2 none tc6 tc2 0 4, 5 tc7 tc2 1 3, 10 tc8 tc2 2 11, 12
Arduino Forum > Products > Arduino Due (Moderator: fabioc84) > Arduino Due Timers Help
arduino
Comments
Post a Comment