Hello!
So I was trying to achieve a dead time using this code in the video and down below. The frequency used in the video and the code attached below is only for 31KHz. When I copied the code and uploaded it to my Arduino, it was working fine with expected results.
#define ANALOG_IN_PIN A0
void setup ()
{
//TCCR2B = TCCR2B & 0xF8 | 0x01;
//TCCR0B = TCCR0B & B11111000 | B00000001; // 62.5KHz //D4 & 13
//TCCR0A |= 0x30; // inversion
TCCR1B = TCCR1B & B11111000 | B00000001; // 31KHz //D11 & 12
TCCR1A |= 0x30; // inversion
}
void loop()
{
int duty = map(A0, 0, 1023, 0, 122);
analogWrite(4,duty)
analogWrite(13,255 - duty);
}
However, I need it to work with 62.5KHz. When I change the code to make it a 62.5KHz, we only got a dead-time on one end of the Squarewave but not the other, as shown below.
#define ANALOG_IN_PIN A0
void setup ()
{
TCCR0B = TCCR0B & B11111000 | B00000001; // 62.5KHz //D4 & 13
TCCR0A |= 0x30; // inversion
}
void loop()
{
int duty = map(31000, 0, 1023, 0, 122);
analogWrite(4,duty);
analogWrite(13,255 - duty);
}
Can someone help me navigate this problem!
Welcome to the forum
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
Please show the scope output for the initial code.
Which Arduino/controller are you using?
ishaqmkhan01:
int duty = map(31000, 0, 1023, 0, 122);
Please fix that crap.
Why do you use timer 0 which is used for system timing?
Why do you expect that the previously working code will continue working after you apply weird modifications to it?
I do not have time to read code from a video, I will help somebody else with the time.
system
Closed
June 2, 2023, 9:48pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.