/************* Timer Counter 0 Channel 0 to generate PWM pulses thru TIOA0 ************/
PMC->PMC_PCER0 |= PMC_PCER0_PID27; // Timer Counter 0 channel 0 IS TC0, TCO power ON
PMC->PMC_PCER0 |= PMC_PCER0_PID12; // PIOB power ON, page 38
PIOB->PIO_PDR |= PIO_PDR_P25;
PIOB->PIO_ABSR |= PIO_ABSR_P25; // PB25 is driven by the TC, peripheral type B, page 858
TC0->TC_CHANNEL[0].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 // MCK/2, clk on rising edge
| TC_CMR_WAVE // Waveform mode
| TC_CMR_WAVSEL_UP_RC // UP mode with automatic trigger on RC Compare
| TC_CMR_ACPA_CLEAR // Clear TIOA0 on RA compare match
| TC_CMR_ACPC_SET; // Set TIOA0 on RC compare match
I have so many questions. I have a tiny bit of experience with atmega avr, however none when it comes to the Atsam ARM. (Using a DUE)
You said up to 480 MHz frequency could be generated by PMC_PCKx, did you mean 48MHz? And how come you didn't use this method for the example of 1Mhz PWM?
Would setting the counters this way disable the functions delay() and millis()? In Atmega88p these functions are controlled by TC0 and so changing anything with TC0 would disable them, however, changing the other timers has no influence on these functions. Is it the same with my DUE as well?
In fact, PMC_PCKx allows you to output one of the internal clocks divided by a prescaler, and re-reading the datasheet, the maximum frequency output can be 480 MHz/2 = 240 MHz. Note that 480 MHz is the frequency needed by USB 2.0 High speed (see page 552, Sam3x datasheet).
To output a 1 MHz frequency, it should be more convenient to use a Timer Counter or a PWM channel. In either cases, search in the DUE sub forum for example sketches, or use TC-lib or PWM-lib from antodom.
The Arduino DUE's ATSAM3X8E micro-controller has its own PWM channels, in order to generate PWM signals without using any of the timers available in the micro-controller. Thus, there is no any conflicts with millis() or delay().
ard_newbie:
In fact, PMC_PCKx allows you to output one of the internal clocks divided by a prescaler, and re-reading the datasheet, the maximum frequency output can be 480 MHz/2 = 240 MHz. Note that 480 MHz is the frequency needed by USB 2.0 High speed (see page 552, Sam3x datasheet).
To output a 1 MHz frequency, it should be more convenient to use a Timer Counter or a PWM channel. In either cases, search in the DUE sub forum for example sketches, or use TC-lib or PWM-lib from antodom.
Hey thanks for your reply. I am aware of prescalers, but isn't the main clock (and the other internal clocks) of the DUE clocked at 84Mhz max?
antodom:
Hi there,
The Arduino DUE's ATSAM3X8E micro-controller has its own PWM channels, in order to generate PWM signals without using any of the timers available in the micro-controller. Thus, there is no any conflicts with millis() or delay().
Hi there
Sorry if I missed something obvious but while reading pwm_lib I could not figure out how to specify a phase shift when using several pwm pins
Is it possible or do I need to code something specifics?
pmw_lib do not abstract the possibility of synchronizing several PWM signals. This capability is present in ATSAM3X8E's PWM modules, but until now, I have not seen the necessity to add this functionality to the library. I will have a look to it.
thanks
that will be neat
In the meantime I will try to do something on my own.
but I am lazy (are we not all..?) and i hate to reinvent the wheel
ps I am also considering using C2000 microcontrollers instead
. they are a definite overkill for my application and I have never used them so I will have to face a steep learning curve.. which I am reluctant to do if I can avoid it.