Arduino Due Timers Help


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:

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/irqtc        channeldue pins
tc0tc002, 13
tc1tc0160, 61
tc2tc0258
tc3tc10none  <- line in example above
tc4tc11none
tc5tc12none
tc6tc204, 5
tc7tc213, 10
tc8tc2211, 12

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.



Arduino Forum > Products > Arduino Due (Moderator: fabioc84) > Arduino Due Timers Help


arduino

Comments