Heater PWM
TC
Posts: 1,019
Hello All,
I am need of some help with the code and circuit JonnyMac posted about 2 weeks ago.
I have the circuit he posted built, when I hook my meter up to the "zc" line and 3.3V I am getting 120Hz.
I have my triac circuit built, when I provide a "LOW" to it, it will turn on the heater.
Right now I am just trying to be able to control the heater from a set value. Here is what I have:
But when I run the code the heater does not turn off, even if I use a value of 100 or 1. I tried inverting all the "outa", since my triac needs to LOW to turn on the heater.
I dont fully understand what is going on with the code yet. That is why I want to get it working, so I can dissect it and understand whats going on.
Any help would be great.
Thanks
TC
I am need of some help with the code and circuit JonnyMac posted about 2 weeks ago.
I have the circuit he posted built, when I hook my meter up to the "zc" line and 3.3V I am getting 120Hz.
I have my triac circuit built, when I provide a "LOW" to it, it will turn on the heater.
Right now I am just trying to be able to control the heater from a set value. Here is what I have:
CON _clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz _xinfreq = 5_000_000 CON 'PINS lower_heater = 0 upper_heater = 1 zero_cross = 2 '*** Lower thermocouple *** TH_lower_SIN = 3 TH_lower_CS = 4 TH_lower_CLK = 5 '*** Upper thermocouple *** TH_upper_SIN = 6 TH_upper_CS = 7 TH_upper_CLK = 8 '*** Door inputs *** door2 = 13 door1 = 14 '*** Servo Signel *** servo = 15 '*** Lower buttons *** lower_right = 19 lower_center = 20 lower_left = 21 '*** Upper buttons *** upper_right = 22 upper_center = 23 upper_left = 24 '*** Display *** display_sout = 25 display_busy = 26 display_reset = 27 '*** EEPROM *** SCL = 28 SDA = 29 '*** Serial *** Tx = 30 Rx = 31 PUB main repeat triac_ctrl(zero_cross, upper_heater, 1) pri triac_ctrl(zc, triac, p_ctrl) | mask, level ' launch with congnew outa[triac] := 0 ' make triac pin output dira[triac] := 1 repeat repeat level from 100 to 1 waitpeq(1 << zc, 1 << zc, 0) ' wait for zero-cross if (byte[p_ctrl] => level) ' on now? outa[triac] := 1 waitcnt(cnt + (clkfreq / 500)) ' 2ms delay outa[triac] := 0
But when I run the code the heater does not turn off, even if I use a value of 100 or 1. I tried inverting all the "outa", since my triac needs to LOW to turn on the heater.
I dont fully understand what is going on with the code yet. That is why I want to get it working, so I can dissect it and understand whats going on.
Any help would be great.
Thanks
TC
Comments
When you make the triac pin an output you are turning it on at that point so it doesn't matter anymore if you try to turn it off as the triac has been triggered and will only turn off at zero cross when the current drops below the hold current level.
Change: to
This is just a very quick glance and I need to look over your code a bit more but you need to make sure that the trigger is released before the start of the next cycle, you don't have to leave the trigger activated, just a short pulse is all that is necessary.
EDIT: the loop doesn't look right but unless I find some more time I won't be able to tell you much yet. How come the call to triac_ctrl is in a repeat loop yet triac_ctrl is in an endless repeat loop itself??
EDIT: JM's opto fires on a high output, he kills the output with a low.
I just "copied & pasted" the triac_ctrl. I was wondering the same thing, Why is it in a endless loop? how can the value be changed? So many questions that I was going to figure out after I got it working.
What?
Yes I have, and everything works great that way. But I have no control of the temperature that way.
JM talks like this: So to turn it on he drives the pin high which implies that the anode of the opto LED is connected to the Prop pin (+resistor) and that the cathode is grounded.
You mentioned yours turns on when the output is low so you have it connected the other way around, so either change the wiring or change the code.
His code was only an example "I might do it like this" so it's up to you to grok that and make it something useful for you.
Yes, This works just fine.
I have been playing with it, I got something to work but I dont know if it is the right way do do it.
Try changing the first waitcnt to 160,000,000 so you can see if a one or a zero turns on the power.
Change one thing at a time if you don't have a clue, at least you will be able to see what it changes. The "on now? comment should correspond with the correct level, either active high or active low. Here you are still using the same code that sets it active high yet you have stated that a low turns it on. CONFIRM which it is that turns it on and make the changes accordingly.
I worry about the comments after I get something working, and I understand exactly what is going on.
Both at the same time. I have an LED(+resistor) tied to the same wire that is going to the triac circuit. When I take that wire, tie it to 3.3V, the LED is off, and the heater is off. But when I tie that wire to ground, the LED comes on, and the heater comes on.
The input of the opto;
3.3V---->1KΩ--->opto-anode
I/O pin--->opto-cathode
Hope that makes sense.
That means it's active low, you have to make the Prop pin a low output for current to flow through the opto LED. Yet the code is set for an active high. Please just acknowledge that you get this point.
That 1K resistor is a bit too much current limiting. You're only getting at most 2 mA current through the led. That is marginal so it might work with a wire connection but the voltage on the prop pin will be slightly higher than ground when it is low, and slightly lower than +3.3V when it is high. Try 220 ohms or so.
I only mentioned the comment to mark the place in the code "should correspond with the correct level" as the next line turns it on, but whether outa[triac]=1 or outa[triac]=0 depends on how you have wired it, in you case it is =0.
BTW, ditto kwinn, use a much lower value resistor as suggested but you must really learn some basic electronics first or you will still be floundering here in another 12 months. Do not skip the basics, take your time with these and understand them before trying to run and jump or else you will fall flat on your face.
I get, and understand your point. I changed all the outa statements to what they should be for my setup. I only kept the code I posted the same from when I started, to see if there was something I was missing. I am still learning programing and I was having trouble fully understanding (1 << zc, 1 << zc, 0) of the waitpeq command. I was/am having trouble understanding why "shift left" 1, zc times, for the state and mask.
I agree, and I was going to change it. Right now, just to get it working I used the values the crane machine used. The machines motherboard used a 5V logic system. I figured if I kept everything the same, I had no chance of braking anything. Then, after i get all the bugs worked out, make a forever board for the triacs.
I have a basic knowledge of electronics. I know, and understand Ohm's Law, including Ohm's Law wheel. I know some about RC circuits (DC no AC). Starting to get a better grasps on logic design(I know the basics, AND, OR, NOT, NOR, etc..) I understand how transistors work, but I have trouble understanding the math to find out the proper support resistors.
Like I told kwinn, I only used that value, because it is safer for the prop. I have lost count how many times I have been shocked, burnt, had parts explode, seen blue smoke, and destroyed projects learning about electronics. So now I take a walk on the cautious side.
For example, my triac circuit is still on the crane machine motherboard. I just cut the traces I do not need, and added wires to things I do need. The engineers that made that board accounted for the current loads, so I cant go wrong to use what they made just for testing, and proof of concept.
I have a board design made up (including a smaller value resistor), but I wanted to wait until I have things working right before I send it to OSHpark. And pot the board in potting compound for safety.