Fast PWM Duty Cycle

Tick Tock Clock Kits

Moderators: adafruit_support_bill, adafruit

Fast PWM Duty Cycle

Postby stinkbutt » Mon Jun 14, 2010 3:47 pm

OK, I've been poring over the code for the Ice Clock, trying to understand how everything fits together. However, I've found something that makes no sense to me. The voltages output by the Boost Converter do not appear to match up with the duty cycle on the (transistor) switch:

Image

From the design, we know the output voltage of the boost converter's given by:

Image

So for the tens of volts we want to drive the VFD with, we want duty cycles around 0.6 to 0.82. All well and good. We also know that the switch in the boost converter's driven directly by the microcontroller off pin 12 (PD6) off the microcontroller. So we look in the code and we find that pin 12 on the microcontroller is OC0A, and controlled by fast PWM:

Code: Select all
  // fast PWM, set OC0A (boost output pin) on match
  TCCR0A = _BV(WGM00) | _BV(WGM01); 

  // Use the fastest clock
  TCCR0B = _BV(CS00);

  TCCR0A |= _BV(COM0A1);
  TIMSK0 |= _BV(TOIE0); // turn on the interrupt for muxing


Great. Only problem is we don't appear to be driving that pin with that duty cycle. The duty cycle of FPWM is controlled by OCR0A and is given by D = 1 - OCR0A/TOP (because the HEXFET conducts when it's LOW, not high) where TOP is always 255 in fast PWM:

Code: Select all
  if (brightness <= 30) {
    OCR0A = 30;
  } else if (brightness <= 35) {
    OCR0A = 35;
  } else if (brightness <= 40) {
    OCR0A = 40;
  } else if (brightness <= 45) {
    OCR0A = 45;
  } else if (brightness <= 50) {
    OCR0A = 50;
  } else if (brightness <= 55) {
    OCR0A = 55;
  } else if (brightness <= 60) {
    OCR0A = 60;
  } else if (brightness <= 65) {
    OCR0A = 65;
  } else if (brightness <= 70) {
    OCR0A = 70;
  } else if (brightness <= 75) {
    OCR0A = 75;
  } else if (brightness <= 80) {
    OCR0A = 80;
  } else if (brightness <= 85) {
    OCR0A = 85;
  } else if (brightness <= 90) {
    OCR0A = 90;
  } else {
    OCR0A = 30;
  }


All this is in the design already, and I think I understand it. Here's the problem: When I increase the brightness, the duty cycle decreases, but the output voltage of the boost converter and the commensurate brightness of the VFD increases.

What am I missing?
Red M&M, Blue M&M: They all wind up the same color
stinkbutt
 
Posts: 583
Joined: Wed Feb 17, 2010 1:40 am

Re: Fast PWM Duty Cycle

Postby stinkbutt » Wed Jun 16, 2010 4:26 pm

This is not encouraging. Two days, dozens of pageviews, nobody knows how the boost converter works?
Red M&M, Blue M&M: They all wind up the same color
stinkbutt
 
Posts: 583
Joined: Wed Feb 17, 2010 1:40 am

Re: Fast PWM Duty Cycle

Postby FazJaxton » Thu Jun 17, 2010 1:48 pm

The wiki page is calculating the duty cycle assuming that high closes the switch. However, as you mentioned, this is a PNP transistor, so it is conducting when the gate is low. This inverts the meaning of the PWM signal, so a lower duty cycle is producing a higher voltage. (Alternatively, if you correct your meaning of "duty cycle" to match the transistor so that 0 is "high" or "on", then with higher brightess, we are creating a higher duty cycle, aka more time low or "on").

If you're wondering why more conducting time gives a higher output voltage, I think it's because it allows more time for the current to build up in the inductor, leading to a higher voltage when the current flow is cut off.
FazJaxton
 
Posts: 56
Joined: Mon Sep 28, 2009 1:18 pm
Location: Kansas, USA

Re: Fast PWM Duty Cycle

Postby madworm_de » Thu Jun 17, 2010 2:17 pm

Where is the problem?

According to its datasheet the IRFD110 is an N-channel mosfet. Therefore it conducts if V(GS) is positive and above the threshold.
NO LARDO CHIPS
User avatar
madworm_de
 
Posts: 99
Joined: Mon Jun 09, 2008 5:56 am

Re: Fast PWM Duty Cycle

Postby stinkbutt » Thu Jun 17, 2010 6:45 pm

madworm_de wrote:Where is the problem?

According to its datasheet the IRFD110 is an N-channel mosfet. Therefore it conducts if V(GS) is positive and above the threshold.


Well, the problem was the design document suggesting the transistor needs to be pulled low to conduct. But you're absolutely right; You've solved that problem. An N-channel does, indeed, conduct when the gate is pulled high. Thank you for independently confirming this, Zener.

This makes perfect sense in the macroscopic, high-level, hand-waving behavior of the boost converter. When you increase OCR0A, you increase the duty cycle, thus the output voltage. For example at OCR0A = 20 the voltage is barely higher than the input voltage:

Code: Select all
D = 20/255

Vo = (1/1-D)Vi = ~Vi = ~9V

However, this raises a new problem: When OCR0A is at it's maximum of 90, the duty cycle is ~0.35. This implies:

Code: Select all
D = 90/255 = 0.35

Vo = (1/1-D)Vi = 1.5Vi = 13.5V


But we don't see that! Instead of an output voltage of 13-14V, we see an output voltage of 70-80V.

So the new problem is this: How can a relatively low duty cycle of 90/255 = 0.35 generate an output voltage which implies a duty cycle of 0.9? I'm pretty sure we're locked into a TOP of 255 in fast PWM, so it's not that you can change the maximum value of the counter (to, say, 100,) to get a duty cycle of 90/100.

What's the speed of the PWM for fast PWM on this clock? What's the response time of this transistor? Is it possible that the transistor is conducting for a hell of a lot longer than just 35% of the time? It seems almost necessary that the PWM is too fast for this transistor to handle.
Red M&M, Blue M&M: They all wind up the same color
stinkbutt
 
Posts: 583
Joined: Wed Feb 17, 2010 1:40 am

Re: Fast PWM Duty Cycle

Postby pstemari » Fri Jun 18, 2010 10:52 am

It also depends on the output current. See http://en.wikipedia.org/wiki/Boost_conv ... _principle, especially the section about discontinuous mode.
--Paul

A wholly owned subsidiary of:
Persephone: DL R+W+B C 7 X L W C++ I++ T+ A E H++ S+ V-- F+ Q P B PA+ PL
Aldebaran: DM Rt H 5 Y L- W+ C+ I++ T++ A+++ E H++ S+ V+ F++ Q+ P B++ PA- PL--
User avatar
pstemari
 
Posts: 309
Joined: Sun Mar 21, 2010 5:10 pm
Location: Seattle, WA

Re: Fast PWM Duty Cycle

Postby stinkbutt » Fri Jun 18, 2010 11:21 am

pstemari wrote:It also depends on the output current. See http://en.wikipedia.org/wiki/Boost_conv ... _principle, especially the section about discontinuous mode.


Yeah, I saw that, but my inclination is to believe that the transistor's too slow. Discontinuous mode yields a reduced output voltage because the inductor's being exhausted before the switch turns back on. The design document suggests they chose the size of the inductor to avoid that. And since we're seeing the opposite of that, as far as I can tell, I'm inclined to believe it.

The datasheet on the hexfet suggests a total turn-off time of 25ns - 15ns of "turn-off delay time" and 9.4ns of "fall time." That corresponds to ~40 MHz.

What's the frequency of the PWM coming out of the microcontroller? If it's within an order of magnitude of 40MHz the mystery may have been solved. If it's NOT even close to 40MHZ (I fear it may not be) then I can't explain the voltages coming out of the boost converter.
Last edited by stinkbutt on Tue Jul 13, 2010 12:53 pm, edited 2 times in total.
Red M&M, Blue M&M: They all wind up the same color
stinkbutt
 
Posts: 583
Joined: Wed Feb 17, 2010 1:40 am

Re: Fast PWM Duty Cycle

Postby pstemari » Sat Jun 19, 2010 11:59 pm

As far as I can tell, it's the other way around, it's a low-load condition resulting in a higher output voltage.

In some cases, the amount of energy required by the load is small enough to be transferred in a time smaller than the whole commutation period. In this case, the current through the inductor falls to zero during part of the period.


As I read that and think about it, the output cap is fully recharged before the inductor is switched back to the short-circuit position, meaning the charge removed from the capacitor during the period with the inductor shorted to ground could be replenished in less time.

Plugging in some numbers, Vi = 9v, D=35%, T=100usec (10kHz), L 2.2mH, and I 1mA, you get a boost factor of 26x. Increase the draw to 10 mA, and it's 3.5x.
--Paul

A wholly owned subsidiary of:
Persephone: DL R+W+B C 7 X L W C++ I++ T+ A E H++ S+ V-- F+ Q P B PA+ PL
Aldebaran: DM Rt H 5 Y L- W+ C+ I++ T++ A+++ E H++ S+ V+ F++ Q+ P B++ PA- PL--
User avatar
pstemari
 
Posts: 309
Joined: Sun Mar 21, 2010 5:10 pm
Location: Seattle, WA

Re: Fast PWM Duty Cycle

Postby pstemari » Sun Jun 20, 2010 1:39 pm

Ah, and I found a handy web calcuator that demonstrates that with some lovely graphs. Playing around with it a bit, and assuming a switching speed of 10 kHz, it seems that the tube is probably pulling 3.5 mA. As you increase the current draw, the duty cycle goes from 35% up to 88%.

That all intuitively makes sense, since the charge-up (magnet-up?) phase where the inductor is shorted out doesn't have any visibility of the load, and that energy brought in has to go somewhere. Since the energy leaving the capacitor is voltage*current, if the current isn't enough to consume the energy, it manifests as voltage.
--Paul

A wholly owned subsidiary of:
Persephone: DL R+W+B C 7 X L W C++ I++ T+ A E H++ S+ V-- F+ Q P B PA+ PL
Aldebaran: DM Rt H 5 Y L- W+ C+ I++ T++ A+++ E H++ S+ V+ F++ Q+ P B++ PA- PL--
User avatar
pstemari
 
Posts: 309
Joined: Sun Mar 21, 2010 5:10 pm
Location: Seattle, WA

Re: Fast PWM Duty Cycle

Postby stinkbutt » Sun Jun 20, 2010 7:30 pm

pstemari wrote:As far as I can tell, it's the other way around, it's a low-load condition resulting in a higher output voltage.

In some cases, the amount of energy required by the load is small enough to be transferred in a time smaller than the whole commutation period. In this case, the current through the inductor falls to zero during part of the period.


As I read that and think about it, the output cap is fully recharged before the inductor is switched back to the short-circuit position, meaning the charge removed from the capacitor during the period with the inductor shorted to ground could be replenished in less time.

Plugging in some numbers, Vi = 9v, D=35%, T=100usec (10kHz), L 2.2mH, and I 1mA, you get a boost factor of 26x. Increase the draw to 10 mA, and it's 3.5x.


Yeah, those numbers are all wrong. 10mA is about half of what we actually see, much less 1mA:

Ladyada In The Design Document wrote:The current draw for the IV-18 tubes is about 8mA per digit and 11mA for the grid. Remember, though, that we only light up one digit at a time! So we need about 20mA total (we also meaured this in-circuit to verify)


This is also consistent with the findings of Riad at jfet.org.

Moreover, the 10KHz speed is not accurate. Consider that the design document quotes a speed of 31.25KHz, 3x that number, AND I THINK THAT NUMBER'S OFF AS WELL! The 31.25KHz speed (which implies a 32 usec period) is calculated from FP_CPU / 256. But take a look at this code from the actual firmware:

Code: Select all
  // fast PWM, set OC0A (boost output pin) on match
  TCCR0A = _BV(WGM00) | _BV(WGM01);

  // Use the fastest clock
  TCCR0B = _BV(CS00);

  TCCR0A |= _BV(COM0A1);
  TIMSK0 |= _BV(TOIE0); // turn on the interrupt for muxing
  sei();


It looks like after the design document was written they altered the CPU prescaler from 256 ( TCCR0B = _BV(CS02)) to 1 (TCCR0B = _BV(CS00)). This is 256 times faster. So the 32 usec period becomes a 125 nsec period. Now, that means you're OFF, when one is at maximum brightness, for ~83nsec. It takes 25nsec to turn off the transistor. This is a non-trivial amount of the off-time. Is it enough to account for 35% duty cycle becoming 90%? I'm not certain.

There's one more thing I can do. I can recompile with a new CPU prescaler. If the prescaler goes to 8 instead of 1 and I see the voltage go DOWN, then the transistor's just slow. If the prescaler goes to 8 and the voltage goes UP, then I know the issue isn't the transistor but the boost converter's current-starved.
Red M&M, Blue M&M: They all wind up the same color
stinkbutt
 
Posts: 583
Joined: Wed Feb 17, 2010 1:40 am

Re: Fast PWM Duty Cycle

Postby oPossum » Sun Jun 20, 2010 8:28 pm

The code is correct.

The PWM resolution will be 125 ns with a 8 MHz clock.
The PWM counter is 8 bits, so 256 steps per cycle.
125 ns * 256 = 32 us = 31.25 kHz

The speed of the transistor is not important.

Are the AVR fuses set for 8 MHz or the default of 1 MHz?

You don't have a 'scope?
I am the Possum, and I approve of this message. Sent from MacBook Wheel Sorry for my bad German.
User avatar
oPossum
 
Posts: 634
Joined: Thu Oct 25, 2007 11:42 pm
Location: Michigan, USA

Re: Fast PWM Duty Cycle

Postby stinkbutt » Sun Jun 20, 2010 9:25 pm

oPossum wrote:The code is correct.

The PWM resolution will be 125 ns with a 8 MHz clock.
The PWM counter is 8 bits, so 256 steps per cycle.
125 ns * 256 = 32 us = 31.25 kHz

The speed of the transistor is not important.

Are the AVR fuses set for 8 MHz or the default of 1 MHz?

You don't have a 'scope?


If I had a scope this question would've been answered long ago. If someone wants to drive the transistor with a square wave with a frequency of 31.25 KHz and a duty cycle of 0.35 we can see what kind of current goes through the transistor.
Red M&M, Blue M&M: They all wind up the same color
stinkbutt
 
Posts: 583
Joined: Wed Feb 17, 2010 1:40 am

Re: Fast PWM Duty Cycle

Postby pstemari » Mon Jun 21, 2010 2:56 am

Ok, using 31.25 kHz and 20 mA it's definitely not in discontinuous mode. Drop that down to 5 mA and it does go into discontinuous mode, which is really what I was trying to get at--if you don't draw enough current from the supply, the 1/(1-D) formula doesn't hold, and you'll get a higher voltage than the 1/(1-D) bit would indicate.

Seems like that's not the case here, but a scope will give you a real answer. If nothing else, my kit should be here in a week or so and I can check out what's going on with it.
--Paul

A wholly owned subsidiary of:
Persephone: DL R+W+B C 7 X L W C++ I++ T+ A E H++ S+ V-- F+ Q P B PA+ PL
Aldebaran: DM Rt H 5 Y L- W+ C+ I++ T++ A+++ E H++ S+ V+ F++ Q+ P B++ PA- PL--
User avatar
pstemari
 
Posts: 309
Joined: Sun Mar 21, 2010 5:10 pm
Location: Seattle, WA

Re: Fast PWM Duty Cycle

Postby stinkbutt » Mon Jun 21, 2010 9:58 am

pstemari wrote:Ok, using 31.25 kHz and 20 mA it's definitely not in discontinuous mode. Drop that down to 5 mA and it does go into discontinuous mode, which is really what I was trying to get at--if you don't draw enough current from the supply, the 1/(1-D) formula doesn't hold, and you'll get a higher voltage than the 1/(1-D) bit would indicate.

Seems like that's not the case here, but a scope will give you a real answer. If nothing else, my kit should be here in a week or so and I can check out what's going on with it.


Yeah, it was an interesting idea, only they pretty much chose the size of the inductor to avoid discontinuous mode. However, if you've got a scope and you can take a look, reading across the power transistor, Vgs in one channel & Vds in another might shed some light on this. Can a 'scope measure current? If it can we can establish how much current is coming out of the boost.

AT this point, I don't think there's an adequate explanation. The transistor's too fast to be impacting the duty cycle, and the whole damn system's been engineered to avoid discontinuous mode :?

One last possibility occurs to me: Perhaps we're not actually drawing 20mA. We're not, strictly speaking, driving the tube. We're just supplying the MAX6921 driver chip. I guess it's possible it's duty cycle is low enough to be current-starving the boost converter.
stinkbutt
 
Posts: 583
Joined: Wed Feb 17, 2010 1:40 am

Re: Fast PWM Duty Cycle

Postby pstemari » Tue Jun 22, 2010 1:50 am

Current-starving, heh. I was thinking of it more in terms of constipation :evil:
--Paul

A wholly owned subsidiary of:
Persephone: DL R+W+B C 7 X L W C++ I++ T+ A E H++ S+ V-- F+ Q P B PA+ PL
Aldebaran: DM Rt H 5 Y L- W+ C+ I++ T++ A+++ E H++ S+ V+ F++ Q+ P B++ PA- PL--
User avatar
pstemari
 
Posts: 309
Joined: Sun Mar 21, 2010 5:10 pm
Location: Seattle, WA

Next

Return to Clocks

Who is online

Users browsing this forum: No registered users and 1 guest

Stuff to buy from the Adafruit store and links to product documentation!


New Products [108]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[31]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[34]
LCDs & Displays[48]
Components & Parts[70]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[111]
 
Wireless[14]
Cables[62]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]