Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Calculating duty cycle

Status
Not open for further replies.
I originally used these equations:

Vtriplow = Vref*R2/(R1+R2) and Vtriphigh = Vref*R2/(R1+R2) + Vcc*R1/(R1+R2)
where R2 is my hysteresis resistor and R1 is the resistor after Vref.

However, I redid my calculations with nodal analysis at the noninverting input and received a hysteresis resistor of 10k and the two resistors in the divider network as 40k. This gives me a perfect 1.5 volt trigger level and 3.5 volt threshold level. But this is with an output of 4 volts at high and 1 volt at low. How are you getting an actual 0 for low output? Does the LM324 not have a limit on it's output voltage of about 1 volts, thus a 4volt high and 1volt low?.

I used 0V for Vol based on the datasheet; you can look at it here:

https://www.electro-tech-online.com/custompdfs/2011/02/LM124.pdf

They list the Vol at 5mV typical and 20mV max with Vcc @ 5V on page 4. If you look at page 2, you can see the reason for this on the schematic's output. Also, I am using a model of the LM324 in LT Spice and it places Vol in operation at ~27mV. The model you are using doesn't get down there, so with it you will not get true results in your simulations. I can send you the model I'm using if you wish.

I just went out to my bench and tested two 324; one ST and one National. The Vol ranged from 2mV to 10mV, so I'm fairly confident about using 0V for calculating the hysteresis. The fly in the ointment is the Voh was right at 3.7V with a 10k load without a pullup. With a pullup and a load, there was essentially no change. I'll be checking that out a bit further to see if anything can be done with that situation. Too bad your instructor didn't pick a rail-to-rail amp. ;)
 
I used 0V for Vol based on the datasheet; you can look at it here:

https://www.electro-tech-online.com/custompdfs/2011/02/LM124-1.pdf

They list the Vol at 5mV typical and 20mV max with Vcc @ 5V on page 4. If you look at page 2, you can see the reason for this on the schematic's output. Also, I am using a model of the LM324 in LT Spice and it places Vol in operation at ~27mV. The model you are using doesn't get down there, so with it you will not get true results in your simulations. I can send you the model I'm using if you wish.

I just went out to my bench and tested two 324; one ST and one National. The Vol ranged from 2mV to 10mV, so I'm fairly confident about using 0V for calculating the hysteresis. The fly in the ointment is the Voh was right at 3.7V with a 10k load without a pullup. With a pullup and a load, there was essentially no change. I'll be checking that out a bit further to see if anything can be done with that situation. Too bad your instructor didn't pick a rail-to-rail amp. ;)

Yea, or even let me use a 555 timer. Also, with my previous design the Output voltage swing of the breadboard circuit was 4volts high and about .8 to .9 volts low. And it is an ST. Could this be a problem with my design? Because it's definitely not going down close to 0 volts like yours.
 
Yea, or even let me use a 555 timer. Also, with my previous design the Output voltage swing of the breadboard circuit was 4volts high and about .8 to .9 volts low. And it is an ST. Could this be a problem with my design? Because it's definitely not going down close to 0 volts like yours.

I mentioned the 555 so you might see how the hysteresis was established there with the three 5k resistors between Vcc, threshold, trigger and ground; 1/3rd, 1/3rd & 1/3rd to set the value of the constant (|Ln .5|) of the timing. There are a number of hints in that App. Note that relate directly to your project that will reproduce one function of the 555; astable mode.

Regarding the issue with your Vol, I would suggest to place a 324 on a bread board, establish ground on pin 11 & Vcc (5V) on pin 4, ground the non-inverting inputs and apply 5V to the inverting inputs and look at the four outputs with nothing else added. I think you'll find the Vol will be within the range of those shown on the datasheet. If not, look at what you have configured on the breadboard for the cause of the anomilies recorded.

BTW, I found the issue with my 324 model after looking at the file. Adding a 10mA load (370 ohm) pulled it down to 3.7V vice 4V at Voh.
 
I mentioned the 555 so you might see how the hysteresis was established there with the three 5k resistors between Vcc, threshold, trigger and ground; 1/3rd, 1/3rd & 1/3rd to set the value of the constant (|Ln .5|) of the timing. There are a number of hints in that App. Note that relate directly to your project that will reproduce one function of the 555; astable mode.

Regarding the issue with your Vol, I would suggest to place a 324 on a bread board, establish ground on pin 11 & Vcc (5V) on pin 4, ground the non-inverting inputs and apply 5V to the inverting inputs and look at the four outputs with nothing else added. I think you'll find the Vol will be within the range of those shown on the datasheet. If not, look at what you have configured on the breadboard for the cause of the anomilies recorded.

BTW, I found the issue with my 324 model after looking at the file. Adding a 10mA load (370 ohm) pulled it down to 3.7V vice 4V at Voh.

Okay, I tested it without any additional components and it goes down around 0V. With this value I get my voltage divider network to be 20k with a 10k hysteresis resistor.

Also if you wouldn't mind sending me the LM324 model for LtSpice that would be great. We use it a lot; they're cheap and my professors seem to be old school. My email is tb144@evansville.edu
I also don't have access to a lab at all times so I have a dependence on simulation to get me close before I start to do lab experimenting.

Thanks, Trent
 
Last edited:
Hi Trent,

I get back to this tonight or in the AM...dinner plans.

EDIT:

OK, here is the model, but I don’t know if you have done this before so I’ll give the step-by-step procedure I use to install a .sub style without a symbol file.

1. Open Windows Explorer and open Program Files of the drive in which it is located;
2. Lclick on LCT, then Lclick on LtspiceIV, then Lclick on Lib, then Lclick on Sub;
3. Now create a sub folder “OPAMPS”, but stay in the main .SUB folder;
4. Now locate the .SUB file “opamp” & Rclick on it and open with Notepad;
5. With the file open in Notepad, delete all contents (it will be save as LM324 later);
6. Copy the LM324 file from the source and paste it in the open Notepad app;
7. Now LClick on file and “save as” with type “All Files” & Encoding “ANSI”;
8. Now select the “OPAMPS” folder in the window and type in filename LM324.SUB
9. Now click save.

To test, open your schematic, delete the opamp you are using currently, and go to the toolbar and click on the IC icon and op amps. From there select “opamp2” and place it on the schematic. Place the cursor over the amp and Rclick and a dialog window will open. In the line that says “opamp2” double Lclick it and edit the line to read LM324. Then close the window and in the toolbar on the far right Lclick on the .op icon and another dialog box will open. In the box type in the line, ‘.inc opamps/LM324.sub’ without the apostrophes and after hitting OK place that spice directive on the schematic. That line will direct LTC to look for the amp or amps .sub circuit file labeled LM324 in the folder it is located. Now in the schematic, right click on the newly placed spice directive, and a box will open up. Hit the open button and a new window with the spice model will open if everything was done correctly. You can close the window and run a simulation. If the amp was correctly labeled no error message will appear.

I know it seems like a long process but if followed precisely, it will take no more than a minute or 2 for the whole thing after a few times. Here is the LM324 model from National Semi:


*//////////////////////////////////////////////////////////////////////
* (C) National Semiconductor, Inc.
* Models developed and under copyright by:
* National Semiconductor, Inc.

*/////////////////////////////////////////////////////////////////////
* Legal Notice: This material is intended for free software support.
* The file may be copied, and distributed; however, reselling the
* material is illegal

*////////////////////////////////////////////////////////////////////
* For ordering or technical information on these models, contact:
* National Semiconductor's Customer Response Center
* 7:00 A.M.--7:00 P.M. U.S. Central Time
* (800) 272-9959
* For Applications support, contact the Internet address:
* amps-apps@galaxy.nsc.com

*//////////////////////////////////////////////////////////
*LM324 Low Power Quad OPERATIONAL AMPLIFIER MACRO-MODEL
*//////////////////////////////////////////////////////////
*
*connections:
* non-inverting input
* | inverting input
* | | positive power supply
* | | | negative power supply
* | | | | output
* | | | | |
* | | | | |
.SUBCKT LM324 1 2 99 50 28
*
*Features:
*Eliminates need for dual supplies
*Large DC voltage gain = 100dB
*High bandwidth = 1MHz
*Low input offset voltage = 2mV
*Wide supply range = +-1.5V to +-16V
*
*NOTE: Model is for single device only and simulated
* supply current is 1/4 of total device current.
* Output crossover distortion with dual supplies
* is not modeled.
*
****************INPUT STAGE**************
*
IOS 2 1 5N
*^Input offset current
R1 1 3 500K
R2 3 2 500K
I1 99 4 100U
R3 5 50 517
R4 6 50 517
Q1 5 2 4 QX
Q2 6 7 4 QX
*Fp2=1.2 MHz
C4 5 6 128.27P
*
***********COMMON MODE EFFECT***********
*
I2 99 50 75U
*^Quiescent supply current
EOS 7 1 POLY(1) 16 49 2E-3 1
*Input offset voltage.^
R8 99 49 60K
R9 49 50 60K
*
*********OUTPUT VOLTAGE LIMITING********
V2 99 8 1.63
D1 9 8 DX
D2 10 9 DX
V3 10 50 .635
*
**************SECOND STAGE**************
*
EH 99 98 99 49 1
G1 98 9 POLY(1) 5 6 0 9.8772E-4 0 .3459
*Fp1=7.86 Hz
R5 98 9 101.2433MEG
C3 98 9 200P
*
***************POLE STAGE***************
*
*Fp=2 MHz
G3 98 15 9 49 1E-6
R12 98 15 1MEG
C5 98 15 7.9577E-14
*
*********COMMON-MODE ZERO STAGE*********
*
*Fpcm=10 KHz
G4 98 16 3 49 5.6234E-8
L2 98 17 15.9M
R13 17 16 1K
*
**************OUTPUT STAGE**************
*
F6 50 99 POLY(1) V6 300U 1
E1 99 23 99 15 1
R16 24 23 17.5
D5 26 24 DX
V6 26 22 .63V
R17 23 25 17.5
D6 25 27 DX
V7 22 27 .63V
V5 22 21 0.27V
D4 21 15 DX
V4 20 22 0.27V
D3 15 20 DX
L3 22 28 500P
RL3 22 28 100K
*
***************MODELS USED**************
*
.MODEL DX D(IS=1E-15)
.MODEL QX PNP(BF=1.111E3)
*
.ENDS
*$



I have more, but it’s late and I add some other finds in the AM.
 
Last edited:
Merv,

Thanks a ton. That will be very useful in the future.

Recalculating my hysteresis and voltage divider resistors leads me to the circuit attached. So now I have the correct hysteresis and trigger/threshold values. Next I need to figure out the time constant resistors.
 

Attachments

  • LtSpiceGraph.png
    LtSpiceGraph.png
    5.6 KB · Views: 120
  • LtSpiceSchematic.png
    LtSpiceSchematic.png
    5.2 KB · Views: 173
Hi Trent,

Looks like putting the LM324 model in place went ok. I should have gotten this further bit in last night or earlier today...sorry for the delay.

To get the model to respond exactly as in the real world you will have to do the following, which will change you hysteresis network values, and as a consequence, will impact the frequency along with the duty cycle and frequency:

1. Place a 365 ohm resistor from the output to ground to pull the high output down to 3.7V (we discussed this earlier);

Because the amp is being used in differential mode and R1 is feeding back a potential to the output when low, there is a diode junction being forward biased raising the output from ~20mV to ~0.62V-0.63V (see LM324 schematic). You noticed this earlier, but I tested a 324 on the bench and could not find the issue because I failed to recognize this or your means of testing...my apologies for wasting your time. The solution to reproduce real world conditions in the simulation, because this is not considered in the model, is...

2. Add a 1N914 diode to the output; cathode to output and anode to a 1.375V source.
3. The resistor and diode in place will force your simulations to react as if in the real world for realistic results in the oxygen breathers world making the output swing from ~0.625V to ~3.7V.
4. To eliminate any additional current loading of the output, I strongly recommend using another amp of the 324 as a unity gain follower to drive your transistor base load;
5. No pullup of the output is necessary, so I'd eliminate R6 on the schematic.

You will notice with the above changes that the hysteresis is no longer within the required bounds so will have to be recalculated. Have you found the method of accomplishing this with the given configuration? From looking at your most recent plot it seems the hysteresis swings from 3.50V down to ~1.37V instead of 1.5V.

If you consider the output high at 3.7V and R1 at 10k as you have, you'll see you have ~0.2V across and 20uA thru R1 and 3.5V across R2. Now disregard R3 for the moment and think of a 3.5V source at the junction of both R1 & R2. Given that premise, the ratio of the current thru R1 and the voltage across R2 will give the current thru R2, or Ir2=Vr2*Ir1. Since the current and voltage of R2 is now known, the resistance of R2 can be determined. Then it is a simple matter of finding the resistance of R3. If you don't have a ratio of 1.0:5.0:3.0 (R1:R2:R3) in the network, something went wrong in your calculations. The ratio is obviously scaleable but R1 at 10k is just dandy, and will yield the required bounds of 1.5V to 3.5V for the hysteresis.

Let me know how this turns out for you.

Good luck,
Merv
 
Merv,

So we have to add the resistor and diode to replicate what the op-amp does in lab experiments; with that I receive the attached circuit. Notice that I have the (1:5:3) ratio as you explained. I used nodal analysis to achieve the values.

Now, to calculate the resistors for period and duty cycle. I don't understand the part of your equation where you take the natural log of t1. Any equation I've seen has the time constant in the exponential, like MrAl's equations. I understood what MrAl was doing and calculating the resistors using his method gets me very close (about .95 period with 22% duty cycle). But clearly it's not perfect and my guess is that the diode is affecting the values.

Thanks again,
Trent
 

Attachments

  • LtSpiceSchematic2.png
    LtSpiceSchematic2.png
    8.3 KB · Views: 171
  • LtSpiceGraph2.png
    LtSpiceGraph2.png
    5.8 KB · Views: 130
Last edited:
Merv,

So we have to add the resistor and diode to replicate what the op-amp does in lab experiments; with that I receive the attached circuit. Notice that I have the (1:5:3) ratio as you explained. I used nodal analysis to achieve the values.

Now, to calculate the resistors for period and duty cycle. I don't understand the part of your equation where you take the natural log of t1. Any equation I've seen has the time constant in the exponential, like MrAl's equations. I understood what MrAl was doing and calculating the resistors using his method gets me very close (about .95 period with 22% duty cycle). But clearly it's not perfect and my guess is that the diode is affecting the values.

Thanks again,
Trent

OK, you've got the hysteresis at the right points now, that was the important starting point to get the correct charge and discharge levels for the timing capacitor. Also, the correct levels at the output are now established for the charging and discharging levels of the capacitor. So let's look at the fundamental equations involving the universal time constant as MrAl started you on.

vc = V*(1-e^-t/τ) for charging and vc = V*e^-t/τ for discharging the capacitor where:

vc = the charge in volts across the capacitor
V = the applied voltage to the capacitor (state dependent trigger/threshold)
t = the period in seconds (state dependent trigger/threshold)
τ = the RC product

Since all the variables are now known except R and C and given C is common to both charge and discharge states select a convenient value for C, plug in the appropriate values at the trigger or threshold points and solve the equation in terms of R.

Please note that the equation I posted was found to be in error due to a transposition error 3 hours later and I edited my post accordingly. But also note that was an attempted solution to find R, which was the desired result.

The reason I kept referring you to the 555 was the relationship between the hysteresis and the constant used in the formula, which was 0.693. The two comparators used to establish the switching points were at 50% (0.50) between threshold and Vcc and trigger and threshold or (|Ln 0.50|), which is 0.69314718 and makes the 555 relatively immune to variations in Vcc.

That is NOT the case with the single comparator employed in your circuit using a single input to setup the hysteresis with a LM324 op amp not intended for use as a comparator. The circuit is very sensitive to all voltage parameters involved, and that is why they must be discovered before moving on to determining the values of R & C so their relatively accurate values can be found assigning an arbitrary to one and finding the other for a given period.

So by plugging in the values to the equations above you will uncover the constant of .xxxxx for that circuit, with those periods solving for R. There is no departure from what MrAl brought to your attention, and perhaps I should have let him help you rather than stepping in to confuse you.

I hope this clarifies some of the issues.

Regards,
Merv
 
Merv,

Thank you for all your help. The project is finished, and I understand how it works as well. I also see what you were getting at with the 555 timer app. After getting the circuit finished I tried it with two diodes again and you're right, it really effects the output.

Thanks again,
Trent
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top