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.

Switching Led

Status
Not open for further replies.
Trying to learn more about this before moving on.

I have been having a hard time trying to find the correct formula's or some I can figure out for RMS Voltage vs delay angle.

I have found a formula for a "single phase fully controlled bridge rectifier for Resistive Loads" giving an RMS formula vs delay angle but I am unsure if it is correct for the Triac circuits. Delay angle in Degrees.

The only other thing I can think of is to use a formula for a single phase controlled half wave rectifier & maybe multiply the result by 2 but I am unsure about this as well?

I have attached the formula for the controlled full wave bridge rectifier, could you have a look & see if it is suitable please?

Cheers
 

Attachments

  • Controlled Full Wave Bridge  Rectifier R Load.PNG
    Controlled Full Wave Bridge Rectifier R Load.PNG
    7.4 KB · Views: 168
Last edited:
I plug in π and get zero, so it doesn't make sense.

You can use Wolframalfa and binary search for the values. You just need to do it for 0 to the peak voltage.
The other half is just algebra after that.

V^2 is probably better.

You can also plug in values of delay to your program and measure the voltage with your TRMS meter.
 
Thanks Kiss,

I plug in π and get zero, so it doesn't make sense.

Sorry I don't understand what you mean? The formula is from the electrical engineering dept of Lakehead university.



You can use Wolframalfa and binary search for the values. You just need to do it for 0 to the peak voltage.
The other half is just algebra after that..

Yes, I was just attempting to do it from scratch so I get a better understanding of things.

V^2 is probably better...

Are you referring to "V^2/R" for Power measurements vs conduction angle?

You can also plug in values of delay to your program and measure the voltage with your TRMS meter.

Yes I have been looking at that also, like mentioned I am trying to have a formula, say I have a need to have X output voltage from a circuit, I would just like to be able to calculate the delay time & plug that in so to speak, it's just for future reference & learning that's all.

Cheers
 
π is 180 deg, so plug in the values and I get zero, not the RMS value of 1/2 cycle. That I think should be 120 VRMS or 1/2 of 240 V intuitively.

I did a couple in Wolframalfa. If you know the value of the entire integral over one half cycle, you can divide that number by, say 100 or 1% bins. If you did 1% of the max, then 99% of the max is 10 ms - T(1%), so you only have to do do the binary search for 1/2 of a 1/2 cycle.

Your graphs done with the TRMS meter vs power suggest that vacuum is proportional to power. Call it k*(V^2). Power is proportional to V^2 and less importantly P= V^2/R as you suggested.

So, k*sin^2(ωt) makes sense. ω=2πf. Usually, you see the general equation of voltage as v(t) = Vp*sin(ωt+θ). Who cares what k is.

Reality says, you don;t care. My ex boss would say, we want a number between 1 and 10, i.e. convenient.

I'd rater break up 500 somethings into 100 pieces than 0.00001 into 100 pieces.

The formula eludes me. If you have 100 pieces, you can always interpolate everything else.

I see it being one of those infinite series problems which I am no good at.
 
Thanks for that,
I have another sketch which I have modified to suit, it gives 0V = OFF & 255 is full ON. I noted the special cases you mentioned for these values.
I have a potentiometer connected so adjustment is 0v to 5V which will be good for the PID setup - I think.
There is a small glitch somewhere that I can't find as yet.
With the pot turned to 0V output there is 0V output from the Triac circuit, basically flat lined, then intermittently there is a very small spike, not enough to flash the Lamp but on the scope you can see one Zero Cross Pulse & it's just enough to trigger the Gate of the Triac causing a small spike.
It very intermittent but still it is an issue I guess.

See below for sketch, credit is given for the original sketch.

Cheers

/*
*****************************************************************************
Thanks to
Ryan McLaughlin <ryanjmclaughlin@gmail.com>
Mark Chester <mark@chesterfamily.org>
James Orland <ptd@caff.cx>
**broken link removed**
for the original sketch ideas.
*****************************************************************************
Modified Sketch
Willeng
22/7/2014

Pin A0 -- Potentiometer 0V to 5V Input---Potentiometer
Pin 2 -- Zero Cross Interupt (Interupt 0)
Pin 3 -- Trigger Pulse to Triac Single pulse at this stage.

0 = 0V 255 = 5V from Arduino
0V AC output from circuit -- True Zero---HEY!!!!

*/

#include <TimerOne.h>
// General
boolean debug = false;
unsigned long int ZeroXTime[4] = {0,0,0,0}; // Timestamp in micros() of the zero crossing interrupts
unsigned long int PowerStep; // How many micros() in each step of power output
unsigned long int AvgPeriod; // The average line voltage period in micros()
unsigned long int PeriodResync = 3000; // Number of milliseconds between line freq measurements
unsigned long int ResetPeriod = PeriodResync; // The timestamp in millis() when we will measure the period again
unsigned long int PowerRes = 256; // How many steps of power resolution
volatile unsigned long int PowerStepCounter; // For counting Timer1 interrupts
volatile unsigned long int FireTriac = 0; // When it's OK to fire the triacs, in counts of PowerRes
volatile boolean zero_cross = 0; // Tels us we've crossed the zero line
byte TriacPin = 3; // Which digital IO pins to use
byte PowerMap[256] = {
255,245,241,237,235,232,230,228,226,224,223,221,220,218,217,215,214,213,211,210,209,208,207,205,204,203,202,201,200,199,198,197,
196,195,194,193,192,192,191,190,189,188,187,186,185,185,184,183,182,181,181,180,179,178,177,177,176,175,174,174,173,172,171,171,
170,169,168,168,167,166,165,165,164,163,163,162,161,161,160,159,158,158,157,156,156,155,154,154,153,152,152,151,150,150,149,148,
148,147,146,146,145,144,144,143,143,142,141,141,140,139,139,138,137,137,136,135,135,134,134,133,132,132,131,130,130,129,128,128,
127,127,126,125,125,124,123,123,122,121,121,120,120,119,118,118,117,116,116,115,114,114,113,112,112,111,111,110,109,109,108,107,
107,106,105,105,104,103,103,102,101,101,100,99,99,98,97,97,96,95,94,94,93,92,92,91,90,90,89,88,87,87,86,85,84,84,83,82,81,81,80,
79,78,78,77,76,75,74,74,73,72,71,70,70,69,68,67,66,65,64,63,63,62,61,60,59,58,57,56,55,54,53,52,51,50,48,47,46,45,44,42,41,40,38,
37,35,34,32,31,29,27,25,23,20,18,14,10,0
};
void setup() { // Begin setup
Serial.begin(9600);
Timer1.initialize(PowerStep); // Start up the Timer1 timer
attachInterrupt(0, zero_cross_detect, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
pinMode(TriacPin, OUTPUT); // Set the Triac pin as output
measure_half_period(); // Initially measure the half period
} // End setup
void measure_half_period() {
zero_cross = 0; // Clearing this here increases the accuracy of the measurement
byte F = 0; // Frequency counter counter
while ( F < 4 ) { // This loop takes 4 zero cross samples
if ( zero_cross ) { // Only run if a zero cross is detected
ZeroXTime[F] = micros(); // Set the new current zero cross time in micros()
zero_cross = 0; // Reset zero_cross
F++; // Bump the counter for the next sample
}
} // Now we calc the length of each PowerStep
PowerStep = (((ZeroXTime[1]-ZeroXTime[0]) + (ZeroXTime[2]-ZeroXTime[1]) + (ZeroXTime[3]-ZeroXTime[2])) / 3) / PowerRes;
Timer1.attachInterrupt(fire_triacs, PowerStep); // (Re)Associate fire_triacs() with the Timer1 interrupt and the latest PowerStep period
ResetPeriod = ResetPeriod + PeriodResync; // Set the next time when we'll measure the half period again
}

void zero_cross_detect() { // function to be fired at the zero crossing
zero_cross = 1; // set a variable that's picked up later
PowerStepCounter = 0; // Reset the step counter for the next round of triac firings
}
void fire_triacs() { // improved version with full OFF and ON
if ( FireTriac == PowerStepCounter ) { // Is it time to fire?

if(FireTriac !=(PowerRes-1)) // When the power output is 0% never turn the triac on
digitalWrite(TriacPin, HIGH); // Fire the Triac mid-phase
if(FireTriac != (PowerRes-1) && FireTriac != 0) //Only bother to add a timing delay when both digitalWrites are active
delayMicroseconds(2);
if(FireTriac != 0) // When the power output is 100% never turn the triac off
digitalWrite(TriacPin, LOW); // Turn off the Triac gate (Triac will not turn off until next zero cross)
}
PowerStepCounter++;
}
void loop() { // Main Loop
if ( millis() >= ResetPeriod ) { // Measure the half period every PeriodResync milliseconds to prevent drift
measure_half_period();
}
FireTriac = PowerMap[(PowerRes * analogRead(0)) / 1024]; // Read input and calc the next triac fire time
if (debug) Serial.println( PowerStep );
if (debug) Serial.println(" " );
if (debug) Serial.println( FireTriac );
delay(100);
}
 
I seemed to have found the issue, the power resolution & the power map was to 256 making a very fine resolution.
I changed this to give .1mS = 100 steps from 0 to 99 in the power map & because the resolution isn't as fine it has stopped the issue with the intermittent spike.

Cheers
 
This is what you need to do:

See figure 14 in this link:

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CDAQFjAC&url=https://www.nxp.com/documents/application_note/APPCHP6.pdf&ei=-8rOU5ibIanisASl3IK4BQ&usg=AFQjCNGn8RUWkJiBb2vyOu3ycD4gvCj4DQ&sig2=T1kngvXjN3nC8zoew3UO3g&bvm=bv.71198958,d.cWc&cad=rja

The gate should be driven hard and fast to ensure
complete gate turn on and thus minimize di/dt effects.
Usually this means a gate current of at least three times
the gate turn on current with a pulse rise of less than one
microsecond and a pulse width greater than 10 microse-
conds. The gate can also be driven by a dc source as long
as the average gate power limits are met.

From ON Semi Handbook.

I can't yet find out what the repetition rate should be. What TRIAC are you using again?

FWIW, the mains frequency changes slightly and therefore, when trying to get to the infinite number of decimal places, I think, one would have to continually monitor the mains frequency and adjust according.

Roman Black who is a member here has some good info on his website: https://www.romanblack.com/onesec/High_Acc_Timing.htm

The 0.033% corrections suggested here https://en.wikipedia.org/wiki/Utility_frequency may be insignificant.
It's about +-3.3 us.

I think you did better than you expected?
 
Thanks for the reply,

There is very good information in the posts you have given & again in your last post, I appreciate the help & time your taking to teach an old dog new tricks so to speak.
I am slow to catch on now after my incident though?

The Triac I am using for the Lamp testing is BTA16 600B, The Triac I was thinking of using for the Vacuum motors control is NTE56033, for no other reason besides I have some here. Datasheets attached.

I was also thinking about the gate turn on current after looking at the signal, I think your right on the money with your mention of it.

Just getting back to the Lamp setup, power like you mention is proportional to the square of the voltage, so if we have half the voltage the power is one quarter of the of the peak power output.

Is this assuming a constant resistance?
A lamp is not constant resistance is it?

This is where I have been somewhat confused by things but in saying that it doesn't take much to get me confused these days?


Cheers
 

Attachments

  • BTA16-600B - STMicroelectronics.pdf
    69.9 KB · Views: 289
  • NTE56033.pdf
    23.3 KB · Views: 220
Is this assuming a constant resistance?

Yes.

A lamp is not constant resistance is it?

It can best be described as a current dependent resistor. The resistance is about 11-12x lower than the full brightness R.

However,

In the limit as ΔT approaches zero, R(lamp) is a constant.

The proportional gain might only work for a small value of ΔT. e.g. 10 degrees might cause the controller to output 100%. 1/kp is the proportional band.

The PID algorithm should be modified for Tungsten and you can buy "triac circuits" designed for Tungsten loads.
What happens, I don't really know, but limiting the rate of change of the output per unit time would really help.
When you combine it with V^2 limits, rate of rise on V^2 and current limits you have a stronger solution.

One way to implement current limit would be to feedback the current and cause the output of PID to reduce. Usually 25 to 100% of the TRIAC/SCR unit is the range of current limit operation.
 
Thanks for that,

I have been attempting the Pulse Train to the Triac gate as suggested & am having issues with it due to not doing it correctly I would say.

Every time I get it close to the correct timing it becomes unstable, you can see the instability on the scope.

I have a picture of the Zero Cross Detector output & the Pulse to the MOC3021, is this what I am chasing although the timing is out which I am aware of.

Cheers
 

Attachments

  • SCOPE TRACE.jpg
    SCOPE TRACE.jpg
    353.9 KB · Views: 176
I can't tell much in terms of pulse width or instability.

With short pulse widths, you may have to increase the gate current. The average current will still be low.
 
Sorry about that I didn't word things correctly,

The picture was taken where things were stable just to see if I have the right idea.

I have taken some other pictures to show the instability, basically when there is a single pulse to the Triac the circuit is stable because the Zero Cross signal is stable & the circuit will adjust to 0V.
When I have a Pulse Train the Zero Cross signal jumps or jitters from left to right so much so that you can't set the circuit near 0V because of this instability & the Zero Cross signal jumps in & out of the trigger point intermittently triggering the Triac.
You will see this in the pictures.

The pulse widths are 10uS, I have tried increasing & decreasing the pulse widths but there is instability whenever there is a pulse train?

At this stage I am only writing digitalWrite high & low with a delay to create the pulse train & maybe this is the issue that I can't work out yet how to do this better?

Cheers
 

Attachments

  • 1.JPG
    1.JPG
    480 KB · Views: 166
  • 2.JPG
    2.JPG
    482.7 KB · Views: 175
  • 3.JPG
    3.JPG
    485.8 KB · Views: 164
  • 4.JPG
    4.JPG
    498.5 KB · Views: 157
Last edited:
After a long day looking at this with novice eye balls I have found some solutions to the problem.
Like everything there has to be compromise, you fix one thing & it takes away from another & visa versa.

I boosted the gate current as suggested to the Triac & fitted a Diac in the circuit, maybe not needed but it did seem to help.

I now have 10 gate pulses, 5uS on 5uS off & it is stable, I have 0 = 0V but now 4V from the Potentiometer = 240V output.
If I adjust the Pulse width to say 10uS on & 10uS off then around 3V will be 240V output.

Is this acceptable ?

The Triac is firing nicely & it is stable, although the way I created the pulse train is very crude, but it works.
I tried a few different ways which would appear to be more professional but the instability was still there because basically I wouldn't have a damn clue at this stage?.

If all is well with this I will move onto the PID for the lamp but if not I will try again until it is right.

Long day & again I learnt how much I don't know!

Cheers
 
Last edited:
Go for it.

As for creating the pulse train, you could have used something like an "on timer" kind of construct at some rate, say 1 uS.

Then you do everything by counts.

Somewhere, you tell the "program to switch on triac or pulse.
So, the traic turns on and 10 interrupts later, the triac turns off, because your counting them.
 
As for creating the pulse train, you could have used something like an "on timer" kind of construct at some rate, say 1 uS.

Then you do everything by counts.

Somewhere, you tell the "program to switch on triac or pulse.
So, the traic turns on and 10 interrupts later, the triac turns off, because your counting them.

Thanks for the reply & the hint on how to go about the pulse train,

I see what your saying, not sure how to do that yet but I will attempt to sort it out today.

I apologise for taking so long to do things, I seem to be reading up on things more than doing things at this stage due to a lack of knowledge & understanding.

Thanks again, I will try to improve on the pulse train section of the sketch before moving on.

I revisited the Triac Power Control sketch from the site you advised to use & had a go at removing the Bluetooth section etc in the sketch but there are a lot of things in the sketch I don't understand at this stage so I had trouble getting it to run correctly?

Cheers
 
Kiss,
Just a quick update & to let you know I haven't given up.

From your last post I found myself looking onto Timer Registers etc & playing around with various things in the sketch, the trouble is without an understanding of how things work inside these registers when you write these commands, it still leaves you somewhat blind as to what's going on & how they actually work.
It's sort of like if you play around with an engines ignition timing or mapping & fuel mixtures or mapping, larger or smaller primary pipes, porting etc etc, without an understanding of what really happens when you make these changes you may as well not touch the bloody thing in the first place.

So I am taking the time out to read up on the inner workings of the microcontrollers & the registers etc before proceeding any further, after reading a lot so far I can now see why I was having trouble with various things I was attempting in the sketch before.

Understanding is the key to everything so I will give it a go & then proceed with things.

I'll Be Back!

Cheers
 
Yup, I remember trying to set up a Holley Economaster Carb. I had to resort to using the propane enrichment method which works flawlessly.

Back in high school and before I could legally drive, my father bought me a 6 cyl 1965 wreck for next to nothing. Lot's of work porting heads, rebuilding the carb, retrofitting electronic ignition and having the head rebuilt. A neighbor was in the biz, so I just dropped it off. Bodywork, body panel replacement, upholstery and various mechanical problems. One problem was a little difficult to find. A slit in the rubber fuel hose at the tank. Prior to that I had a 1968 carb under by belt and a rebuilt lawnmower that I threw a rod in and minor car repairs under the supervision of dad. A 1982 Toyota carb had like 130 parts when I rebuilt it. It's nice to start simple and work up.
 
Gday Kiss,

After countless hours studying timers & how the work I have failed miserably in my attempt to create the required pulse train using timers, I tried just about everything I could think of but I just don't seem to think the way I should with programming.
Like I mentioned before it's all new to me, I even tried creating the pulse train using Tones & many many other ways that don't require timers but all are unsuitable to get the required on time of the pulses to cover the worst case scenario as far as the current lag is concerned. I can get the required on time for the pulses but they all affect how the program & circuit works?

At least I can setup the timers now for other purposes, I figured out one way to create the pulse train was to Loop the timer ISR n times but I still can't work the damn thing out, even the basic way I started with was writing digitalWrite HIGH & LOW with delay but the delay causes issues.

So at the end of the day I'm frustrated beyond belief that I can't work this out & embarrassed also but that's life I guess.

I could really use some help with this part of things & many others to be honest.

Today instead of throwing in the towel like I felt like doing I decided to just try the PID using just a single pulse to the Triac gate & have come up with at least something, this may not be suitable either but it's a start.

Like I mentioned I just don't think the right way with all this & especially now.

I have attached a couple of screen shots of the Serial readout which shows the Setpoint Vs Thermocouple Input to see what you think?

I am not sure I have any of this correct even though I get some sort of results, to explain:

If I have the Setpoint at say "100" & the Input from the Thermocouple goes fractionally above this say 101, 102, the Lamp does not DIM smoothly to correct to the 100 Setpoint mark but instead it drops the power to the lamp very quickly & then back on very quickly making the lamp FLICKER to hold the Setpoint number.
I thought it should Dim the power smoothly up & down to hold the Setpoint figure.

It's more than likely my total misunderstanding of how to go about programming these damn things that is causing the issues?

Could you have a look at the sketch & tell me where I have gone wrong with things, If I have totally buggered up just say so, I can handle it!

I just wasn't born to be a programmer!

EDIT: I forgot to mention that the timing for the serial readout is every 500mS when you look at the pictures attached, you will see that in the sketch anyway.

Cheers
 

Attachments

  • Setpoint Vs Input.PNG
    Setpoint Vs Input.PNG
    24.2 KB · Views: 144
  • Setpoint Vs Input-2.PNG
    Setpoint Vs Input-2.PNG
    23.1 KB · Views: 140
  • Setpoint Vs Input-3.PNG
    Setpoint Vs Input-3.PNG
    22.2 KB · Views: 143
  • PID_Lamp_Temp_Control_Trial.ino
    9.2 KB · Views: 112
Last edited:
Hopefully, I can look at this later, but I have a few things for you to look at:

The graphs here https://en.wikipedia.org/wiki/PID_controller of the effects of P I and D.
and here: https://www.futuredesigncontrols.com/AutoTune Page.htm

You MAY have what you see in the red line or a non-optimally tuned PID, but I don;t think so. Unfortunately, your data doesn't include t=0. I do see it oscillating +-1 or 2 degrees, but then I don't see any fractional temperatures, so I don't initially think it could do much better. If your reading to 1 degree, how can you expect any better control? In reality, I think you did good. Does this make any sense? Both how fine, you can read the temperature, even if it isn't correct and the output % on resolution has an effect.

PID does have a habit of turning off the control if you overshoot.

The total picture requires: time, setpoint, measured value and Pout(%) including both a step change and steady state. So, these are my initial thoughts.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top