hi friends
I' used the following code to generate the pwm whit timer 1 on due board
I expect the output frequency on pin 9 &13 to be 50khz But the output frequency is only 650hz
Can anyone help me what is wrong in my cod ?
#include <timer.h>
int a=0;
int out1 = 9;
int out2 = 13;
Timer<1, micros> timer; // create a timer with 1 task and microsecond resolution
bool toggle_out(void *) {
if (a==200){
a=0;
}
a=a+1;
return true; // repeat? true
}
void setup() {
pinMode(out1, OUTPUT);
pinMode(out2, OUTPUT);
// call the toggle_out function every 1 micros
timer.every(1, toggle_out);
}
void loop() {
timer.tick(); // tick the timer
if (a<=100)
{
digitalWrite(out1, HIGH);
}
if (a>100)
{
digitalWrite(out1, LOW);
}
if ((a>100)&&(a<199))
{
digitalWrite(out2, HIGH);
}
pwm whit timer 1 for h bridge motor driver
Today at 05:32 am
hi friends
I' used the following code to generate the pwm whit timer 1 on due board
I expect the output frequency on pin 9 &13 to be 50khz But the output frequency is only 650hz
Can anyone help me what is wrong in my cod ?
#include <timer.h>
int a=0;
int out1 = 9;
int out2 = 13;
Timer<1, micros> timer; // create a timer with 1 task and microsecond resolution
bool toggle_out(void *) {
if (a==200){
a=0;
}
a=a+1;
return true; // repeat? true
}
void setup() {
pinMode(out1, OUTPUT);
pinMode(out2, OUTPUT);
// call the toggle_out function every 1 micros
timer.every(1, toggle_out);
}
void loop() {
timer.tick(); // tick the timer
if (a<=100)
{
digitalWrite(out1, HIGH);
}
if (a>100)
{
digitalWrite(out1, LOW);
}
if ((a>100)&&(a<199))
{
digitalWrite(out2, HIGH);
}