One such application is in high-frequency circuits. It can be used for almost any application that one can think of. TC2->TC_CHANNEL.Arduino Uno is one of the most commonly used Development boards these days. TC2->TC_CHANNEL.TC_RC = 1300 //TC_CHANNEL.TC_RA = 40 //TC_CHANNEL.TC_IER = TC_IER_CPCS // Interrupt on RC compare match | TC_CMR_ACPC_SET // Set TIOA6 on RC compare match | TC_CMR_ACPA_CLEAR // Clear TIOA6 on RA compare match - See page 883 If TC_CHANNEL is TIOA7, is it correct to assume that TC_CHANNEL is TIOA6 ? PIOC->PIO_ABSR |= PIO_PC25B_TIOA6 // Periperal type B as well, by page 859 PIOC->PIO_PDR |= PIO_PDR_P25 // Assuming the "C" should come from the PIOC => PC25 PMC->PMC_PCER1 |= PMC_PCER1_PID33 // TC6 power ON? not sure how to change the PCER index in this line using page 38 (or others) in the datasheet. * TIOA6 Frequency = 32.3 KHz over pin 5 */ Well, me not being an RT embedded developer, I was wondering if you could take a quick look to check if this code should work? I apologize if the answer is right under my nose, but would very much appreciate the experts' help on this. I don't mind having it a little more cumbersome / less abstracted on the Due, as long as it would work. On the mega it was as simple as adding in the beginning: I also need to have the ability to change the duty cycle on the fly (as to say, I need a usage similar to calling analogWrite(x) to a digital pin, just not in the default 490 Hz frequency). And that it is not supported in pwm_lib because it's peripheral is TIOA6 and not a PWM channel.ĭid not quite understand the difference between TIOA6 and TC2, or how to get this pin to generate a PWM signal at a constant frequency of >20 KHz (preferred 33KHz). Took me a while to find the pwm_lib (google has very bad results regarding the pwm frequency issue), only to find out that the pin I am already connected to (and cannot re-adjust) is pin5, which is PC25. TC2->TC_CHANNEL.TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN // Software trigger TC7 counter and enableĭigitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)) // Toggle every 1 Hz TC2->TC_CHANNEL.TC_RC = 2100 //TC_CHANNEL.TC_RA = 100 //TC_CHANNEL.TC_IER = TC_IER_CPCS // Interrupt on RC compare match | TC_CMR_ACPC_SET // Set TIOA7 on RC compare match | TC_CMR_ACPA_CLEAR // Clear TIOA7 on RA compare match - See page 883 | TC_CMR_WAVSEL_UP_RC // UP mode with automatic trigger on RC Compare TC2->TC_CHANNEL.TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 // MCK/2, clk on rising edge PIOC->PIO_ABSR |= PIO_PC28B_TIOA7 // Periperal type B - See page 859 PIOC->PIO_PDR |= PIO_PDR_P28 // The pin is no more driven by GPIO PMC->PMC_PCER1 |= PMC_PCER1_PID34 // TC7 power ON - Timer Counter 2 channel 1 IS TC7 - See page 38 * TIOA7 Frequency = 20 KHz over pin 3 */ TC3_Handler() is the Timer Interrupt Handler for Timer Counter 1 Channel 0, whereas TC1->TC_CHANNEL.TC_SR is the status register for this same timer. These signals are output by Timer Counter 2.īeware : There may be some confusion with Timer Counter names, namely e.g. Pin 4 -> TIOB6 ( Timer Counter 2 Channel 0 is TC6) Pin 3 -> TIOA7 ( Timer Counter 2 Channel 1 is TC7) Look carefully at the Greynomad pinout diagram to see which signals can be output. Effectively, analogWrite() outputs a single PWM frequency ! To output a PWM signal, depending on the PWM frequency you are willing to output, choose between the PWM peripheral or the Timer Counter.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |