Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing the PWM frequency #478

Open
EhsanMasoumi opened this issue Feb 19, 2021 · 0 comments
Open

changing the PWM frequency #478

EhsanMasoumi opened this issue Feb 19, 2021 · 0 comments

Comments

@EhsanMasoumi
Copy link

Hi,

My motor is too load when I drive it by Arduino Due PWM waveform. The issue is that the default PWM frequency of Ardunio Due is 1000. I am wondering how can I increase that? I used this code in my sketch to make the interrupts but did not work.

void setupTimerPWM(){

PMC->PMC_PCER1 |= PMC_PCER1_PID34; // TC7 power ON - Timer Counter 2 channel 1 IS TC7 - See page 38

PIOC->PIO_PDR |= PIO_PDR_P28; // The pin is no more driven by GPIO
PIOC->PIO_ABSR |= PIO_PC28B_TIOA7; // Periperal type B - See page 859

TC2->TC_CHANNEL[1].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 TIOA7 on RA compare match -- See page 883
| TC_CMR_ACPC_SET; // Set TIOA7 on RC compare match

TC2->TC_CHANNEL[1].TC_RC = pwmRange; //<********************* Frequency = (Mck/2)/TC_RC Hz = 20 KHz
TC2->TC_CHANNEL[1].TC_RA = 1; //<******************** Duty cycle = (TC_RA/TC_RC) * 100 %

TC2->TC_CHANNEL[1].TC_IER = TC_IER_CPCS; // Interrupt on RC compare match
NVIC_EnableIRQ(TC7_IRQn);

TC2->TC_CHANNEL[1].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN;// Software trigger TC7 counter and enable

}

// interrupt handler
void TC7_Handler() {
static uint32_t Count;
TC2->TC_CHANNEL[1].TC_SR;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant