Watching these vids after the event and I'm waiting for you to discover the joys of synchronous buck-boost shoot through and dead time implementation :D
I don't recall having this issue with a similar buck/boost/synchronous rectification project I did one weekend..but my memory of it is a bit fuzzy,been a while since I needed a dual/inverted PWM output. I think I just used the map() function,to invert the PWM value. I'd have to see if I still have a copy of the code. I was using an Arduino Mega though,maybe that's the difference.
Julian Ilett Hello. Can you prompt the issue of arduino pwm controlling the mosfets. It goes from 0 to 4.5 volts on linear mode on voltage. But should it be a step from 0 to 4.5 with pwm without any linearity on a voltage, to controlling the applications?. Sorry for the noob and such a kind of question. I do the DIY motor controller, and if I add a gate driver to mosfet with say 12v of driving voltage, the arduino don't give a damn on a pwm and just ON and OFF full power, no matter what pwm cycle is applied. Thanks.
The flipping was not a bug but a misuse of the library. You must NEVER mix library accesses and direct register accesses. You either use one or the other but not both. Inverting was also quite simple: just call the library with (100-dutycycle%)...
I've been trying to get complementary / none overlapping waveforms just using the 8 bit timer. There is inverted bits in the TCCR0A register for both OCR0A and OCR0B. it only works in CTC mode?
julian , while using timer 2 8bit for generating noninverting and inverting pwm using direct register write i see that inverting pwm2 is little bit phase shifted in respect to pwm1. what can be the issue. pinMode(3, OUTPUT); pinMode(11, OUTPUT); TCCR2A = _BV(COM2A1) | _BV(COM2B1) |_BV(COM2B0) | _BV(WGM21) | _BV(WGM20); TCCR2B = _BV(CS22); OCR2A = 55; OCR2B = 55;
Wow; you know years ago (way back when Christ was a Corporal!) I used to have a C=128 Commodore setup and subscribed to RUN magazine and a few others. They came with "FREE SOFTWARE!" in machine code, entered with a special assembler that you had to type in, or buy a floppy disk with it included. Of course you had no idea how the machine code worked because it was just a series of 8 bit numbers entered into the program, then assembled into a game or utility. I used to do them all! Had the wife read me the code, as I punched the numbers into the software, then we would play the games. Well at last, I can get a bit of understanding what all that was all about. Great to have a bit of education whilst I sit down here in our 35 foot Rexall Rexair Class A Motor Home with an old recliner sitting in the middle of the living room holding my aging body up in a rather comfortable position. We just returned from a walk around the block in the beautiful Arizona Sunshine! Oh by the way, did anyone ever tell you, we got your bridge from London? Yep, just 26 miles from where I sit, in Lake Havasu City, sits the London Bridge with a small imitation London community under it. We stop off for some of their wonderful Fish and Chips when we visit. By the way, have you tried that little Arduino with the extra pins yet? Just wondering, I use them all the time down here as I don't have a lot of room, and they are almost like having an Arduino and a breadboard in one. Oh for reference, it is 68 degrees F. here in Golden Shores Arizona, a bright and sunny day, so much nicer then it was when we left South Dakota a week ago, where it was 8 degrees F. with 5 inches of snow on the ground. --The nomadic snowbird---
This any help? const int pwmtop=128; void setup(){ TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); //Adjust timers. TCCR2B = _BV(WGM22) | _BV(CS20); OCR2A = pwmtop; //Go faster. pinMode(3, OUTPUT); //PWM drive } That'll crank up the PWM frequency as high as you reasonably can, at the expense of precision. You'll be down to 7-bit, not 8-bit. But if you're doing with a buck converter, the trade off is worthwhile to avoid needing an impractically huge inductor.
JULIAN ILETT YOU SHOULD DEFINITELY MAKE A VIDEO EXPLAINING HOW TO BUILD A CIRCUIT, CODE, APP AND ZERO CROSSING CIRCUIT WHICH CAN CONTROL AT LEAST 5 AC LIGHT BULBS AND BE ABLE TO NOT ONLY TURN THEM ON/OFF BUT DIM EACH ONE OF THEM SEPARATELY VIA BLUETOOTH HC-06 AND ANDROID APP. THAT WILL BE A CHALLENGE!!!
This is just what I am trying to do for a project at the moment, and you helped me a lot. Since you seem to have a better understanding of registers, and you said "I can make this work with whatever frequency I need." Can you please help me to bring it down to something like 3Hz?
Hi Julian. You may also like the new Atmega328PB with even more 16bits timers available (among plenty of other good stuff, like a second UART, more I2C, etc.)
So many issues like this in Arduino. It's probably a result of crowd sourced software development where hardly anyone knows the big picture. Pros and cons. Was it you or Dave that did the vidyeo on how slow the pin toggle is using the Arduino code as opposed to using the registers? On the other hand you get the same function on the ESP8266 even though it's all software below it and the same on the ARM, even though it's completely different again.
Fixing it in software would have been perfectly fine :) It keeps the abstraction layer intact :) Okay, it would have been even better if the Arduino PWM/analogWrite() library was a bit more capable. Aka, enable invert via the abstraction and act on it with a write. Or at least the fix should have included a -1 in the else state :) Good to remind me of that!
I just copied your code into the IDE and ran it on a DIP 328P I bought in 2013 and the waveforms DO overlap. This might require some further investigation.
Yeah I tried it on my Uno and Nano and it does not do that. There is no "dead time" at all. There is something different happening with your Nano. It's not supposed to do that.
this is a way better way to fix it you have found, and i take no joy in seeing ide bugs....but if i was doing it quick and dirty then i would have ...(not a real language but very basic.....) (oh how did you get the guard time on the inverted signal?) if pwm=100 then pinX=1:pinY=0 else if pwm=0 then pinX=0:pinY=1 else analog write pinX endif endif Would have been a quick and dirty bodge, but no way as neat as just hitting the hardware
Pwm with arduino ... Heh been some time since i saw that waveform on a screen (altough mine came from my soundcard ;D) .... I was changing the frequency for a 12V 150 watt pwm hot wire driver to a nicer frequency
you should sell muppts. and have attachments you can call them muppt baby's! for blue tooth and all the monitoring stuff. just like the other controllers. I want to get in to the arduinos so badly. but I'd have to dig my computer stuff out and likely have to build one that works. there is some thing wrong with all of them. just to get one desk top that I can use. they aren't so old to be grandmas computer. just your parents PC. less than 10 years old but not much. and of course I'm not buying a new one! that's money I can spend on stuff more important!!! great video. I hope you are teaching me something!!! I'm trying to learn! its not do easy when you don't personally have one to work with! greatly informative video. thanks!!,,
256 likes when I watched the video and eight dislikes. Now it has 257 likes, I feel a little guilty, just having destroyed the good side of power of two. We should reach 512, please help!
I prefer direct access to registers. I go into that hardware folder and look into the files. I like how the Arduino IDE still exposes the names and addresses, even though they can be quite cryptic. Many functions are written with a lot of error checking but if I wanna go fast, I can't have the cruft. It forces you to know what goes on below. I never use analog/digitalAnything in my loops, only in setup(). TL;DR, I like efficient code.
Watching these vids after the event and I'm waiting for you to discover the joys of synchronous buck-boost shoot through and dead time implementation :D
Please go into the detail of how the registers work in this case.
Would love to see more on registers with arduino!
You should do a video on arduino registers. Honestly I don't know the first thing about that sort of thing, but am definitely interested!
Cheers Mr. I. Hope your day is going well, sir.
This is beyond useful for a huge number of applications. Thank you Julian
Excellent solution for my problem! Only question how could I change the 2 pwm channels in order to change motor direction?
I don't recall having this issue with a similar buck/boost/synchronous rectification project I did one weekend..but my memory of it is a bit fuzzy,been a while since I needed a dual/inverted PWM output. I think I just used the map() function,to invert the PWM value. I'd have to see if I still have a copy of the code. I was using an Arduino Mega though,maybe that's the difference.
Hello, how would you change the frequency?
Julian Ilett
Hello. Can you prompt the issue of arduino pwm controlling the mosfets. It goes from 0 to 4.5 volts on linear mode on voltage. But should it be a step from 0 to 4.5 with pwm without any linearity on a voltage, to controlling the applications?. Sorry for the noob and such a kind of question. I do the DIY motor controller, and if I add a gate driver to mosfet with say 12v of driving voltage, the arduino don't give a damn on a pwm and just ON and OFF full power, no matter what pwm cycle is applied.
Thanks.
how do you disable phase correct or how can one get controlled phase shift between pwm signals?
what did you do to create the non overlap and create the space between the pulses..?
what pins are you using besides where the pot is .. It may be a dumb question but i am a newbie sorry ..
Julian thank you it is exactly what I was looking for.
Hi julian! does this work for timer 2, what should be changed? Thx
The flipping was not a bug but a misuse of the library. You must NEVER mix library accesses and direct register accesses. You either use one or the other but not both. Inverting was also quite simple: just call the library with (100-dutycycle%)...
I've been trying to get complementary / none overlapping waveforms just using the 8 bit timer. There is inverted bits in the TCCR0A register for both OCR0A and OCR0B. it only works in CTC mode?
Why not submit a pull request to fix this in the Arduino framework?
Also how do you set the frequency out ?? I need the 30Khz
This is ingenious - how is the frequency set?
Did you order that flashlight custom or customise it yourself? Really enjoy your videos. Thanks
Hi
How much non overlapping time you get?
And also is it sufficient for mosfets?
Could you please link the previous video where the problem occurs
Thanks Harold - I've done that now :)
You are only dividing the analogue read value by 2? Shouldn't this be divided by 4? Is the assignment to the register just dropping that extra bit?
julian , while using timer 2 8bit for generating noninverting and inverting pwm using direct register write i see that inverting pwm2 is little bit phase shifted in respect to pwm1. what can be the issue.
pinMode(3, OUTPUT);
pinMode(11, OUTPUT);
TCCR2A = _BV(COM2A1) | _BV(COM2B1) |_BV(COM2B0) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS22);
OCR2A = 55;
OCR2B = 55;
Wow; you know years ago (way back when Christ was a Corporal!) I used to have a C=128 Commodore setup and subscribed to RUN magazine and a few others. They came with "FREE SOFTWARE!" in machine code, entered with a special assembler that you had to type in, or buy a floppy disk with it included. Of course you had no idea how the machine code worked because it was just a series of 8 bit numbers entered into the program, then assembled into a game or utility. I used to do them all! Had the wife read me the code, as I punched the numbers into the software, then we would play the games. Well at last, I can get a bit of understanding what all that was all about. Great to have a bit of education whilst I sit down here in our 35 foot Rexall Rexair Class A Motor Home with an old recliner sitting in the middle of the living room holding my aging body up in a rather comfortable position. We just returned from a walk around the block in the beautiful Arizona Sunshine! Oh by the way, did anyone ever tell you, we got your bridge from London? Yep, just 26 miles from where I sit, in Lake Havasu City, sits the London Bridge with a small imitation London community under it. We stop off for some of their wonderful Fish and Chips when we visit.
By the way, have you tried that little Arduino with the extra pins yet? Just wondering, I use them all the time down here as I don't have a lot of room, and they are almost like having an Arduino and a breadboard in one. Oh for reference, it is 68 degrees F. here in Golden Shores Arizona, a bright and sunny day, so much nicer then it was when we left South Dakota a week ago, where it was 8 degrees F. with 5 inches of snow on the ground. --The nomadic snowbird---
i need to contact you sir regarding my bidirectional converter
This any help?
const int pwmtop=128;
void setup(){
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); //Adjust timers.
TCCR2B = _BV(WGM22) | _BV(CS20);
OCR2A = pwmtop; //Go faster.
pinMode(3, OUTPUT); //PWM drive
}
That'll crank up the PWM frequency as high as you reasonably can, at the expense of precision. You'll be down to 7-bit, not 8-bit. But if you're doing with a buck converter, the trade off is worthwhile to avoid needing an impractically huge inductor.
JULIAN ILETT YOU SHOULD DEFINITELY MAKE A VIDEO EXPLAINING HOW TO BUILD A CIRCUIT, CODE, APP AND ZERO CROSSING CIRCUIT WHICH CAN CONTROL AT LEAST 5 AC LIGHT BULBS AND BE ABLE TO NOT ONLY TURN THEM ON/OFF BUT DIM EACH ONE OF THEM SEPARATELY VIA BLUETOOTH HC-06 AND ANDROID APP. THAT WILL BE A CHALLENGE!!!
This is just what I am trying to do for a project at the moment, and you helped me a lot. Since you seem to have a better understanding of registers, and you said "I can make this work with whatever frequency I need." Can you please help me to bring it down to something like 3Hz?
You can get 30Hz easily enough - 3Hz is more difficult.
which pin should we use ,could you please help me
I'm using arduino mega
The mega is completely different, the program will have to be rewritten for it. It has different registers and semantics.
Hi Julian. You may also like the new Atmega328PB with even more 16bits timers available (among plenty of other good stuff, like a second UART, more I2C, etc.)
Oooh interesting. But will it work in the Arduino IDE?
So many issues like this in Arduino. It's probably a result of crowd sourced software development where hardly anyone knows the big picture. Pros and cons. Was it you or Dave that did the vidyeo on how slow the pin toggle is using the Arduino code as opposed to using the registers? On the other hand you get the same function on the ESP8266 even though it's all software below it and the same on the ARM, even though it's completely different again.
Fixing it in software would have been perfectly fine :) It keeps the abstraction layer intact :)
Okay, it would have been even better if the Arduino PWM/analogWrite() library was a bit more capable. Aka, enable invert via the abstraction and act on it with a write.
Or at least the fix should have included a -1 in the else state :) Good to remind me of that!
Hei, fine. Could you kindly release a code for 1kHz and for digital PIN #5 (T1), please. Next how to manage PWM it self.
I just copied your code into the IDE and ran it on a DIP 328P I bought in 2013 and the waveforms DO overlap. This might require some further investigation.
Yeah I tried it on my Uno and Nano and it does not do that. There is no "dead time" at all. There is something different happening with your Nano. It's not supposed to do that.
Please where's the code ?
this is a way better way to fix it you have found, and i take no joy in seeing ide bugs....but if i was doing it quick and dirty then i would have ...(not a real language but very basic.....) (oh how did you get the guard time on the inverted signal?)
if pwm=100 then pinX=1:pinY=0
else
if pwm=0 then pinX=0:pinY=1
else
analog write pinX
endif
endif
Would have been a quick and dirty bodge, but no way as neat as just hitting the hardware
Cool scope Jules
Pwm with arduino ... Heh been some time since i saw that waveform on a screen (altough mine came from my soundcard ;D) .... I was changing the frequency for a 12V 150 watt pwm hot wire driver to a nicer frequency
you should sell muppts. and have attachments you can call them muppt baby's! for blue tooth and all the monitoring stuff. just like the other controllers. I want to get in to the arduinos so badly. but I'd have to dig my computer stuff out and likely have to build one that works. there is some thing wrong with all of them. just to get one desk top that I can use. they aren't so old to be grandmas computer. just your parents PC. less than 10 years old but not much. and of course I'm not buying a new one! that's money I can spend on stuff more important!!! great video. I hope you are teaching me something!!! I'm trying to learn! its not do easy when you don't personally have one to work with! greatly informative video. thanks!!,,
King Arduino was the king of Italy like 1000 years ago
12:24 non overlapping section = it's called dead time ;)
Someone has been reading PWM controller datasheets.
Congratulations !
256 likes when I watched the video and eight dislikes. Now it has 257 likes, I feel a little guilty, just having destroyed the good side of power of two. We should reach 512, please help!
As usual, the first line of the code mystified me. The rest was gobbledygook. Thanks anyway.
P.S. If this is simple, don't go into complicated without a health warning on the video! ;-p
This is why I absolutely detest using other people's libraries, I much prefer to write low level drivers myself.
With you there mate!
Now I am able to get frequency of 31.12khz by changing top value to 0xFF 😋
I prefer direct access to registers. I go into that hardware folder and look into the files. I like how the Arduino IDE still exposes the names and addresses, even though they can be quite cryptic. Many functions are written with a lot of error checking but if I wanna go fast, I can't have the cruft. It forces you to know what goes on below. I never use analog/digitalAnything in my loops, only in setup(). TL;DR, I like efficient code.