Shop OBEX P1 Docs P2 Docs Learn Events
Heater PWM — Parallax Forums

Heater PWM

TCTC Posts: 1,019
edited 2014-02-17 03:56 in Propeller 1
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:
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

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-02-16 15:55
    TC wrote: »
    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:
    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.
    TC

    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:
    outa[triac] := 0                                              ' make triac pin output
    
    to
    outa[triac] := 1                                              ' make triac pin inactive
    

    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.
  • kwinnkwinn Posts: 8,697
    edited 2014-02-16 16:03
    Have you tried toggling the heater control pin every second or so to make sure all the hardware is working and connected properly?
  • TCTC Posts: 1,019
    edited 2014-02-16 16:29
    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??

    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.
    EDIT: JM's opto fires on a high output, he kills the output with a low.

    What?
  • TCTC Posts: 1,019
    edited 2014-02-16 16:31
    kwinn wrote: »
    Have you tried toggling the heater control pin every second or so to make sure all the hardware is working and connected properly?

    Yes I have, and everything works great that way. But I have no control of the temperature that way.
  • kwinnkwinn Posts: 8,697
    edited 2014-02-16 16:42
    Try this to verify the hardware is working. The triac control pin on the prop is toggling once per second so you can see it with a led or a meter.
    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
    
      dira[triac] := 1                                      ' make triac pin output
    
      repeat
        outa[triac] := 0                                    ' turn triac on       
        waitcnt(cnt + (clkfreq ))                      ' 1sec delay
        outa[triac] := 1                                    ' turn triac on       
        waitcnt(cnt + (clkfreq ))                      ' 1sec delay
      
    
    
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-02-16 16:45
    TC wrote: »
    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?
    Whatchu talkin' bout Willis?
    JM talks like this:
          if (byte[p_ctrl] => level)                                ' on now?        
              outa[triac] := 1 
    
    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.
  • TCTC Posts: 1,019
    edited 2014-02-16 16:55
    kwinn wrote: »
    Try this to verify the hardware is working. The triac control pin on the prop is toggling once per second so you can see it with a led or a meter.
    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
    
      dira[triac] := 1                                      ' make triac pin output
    
      repeat
        outa[triac] := 0                                    ' turn triac on       
        waitcnt(cnt + (clkfreq ))                      ' 1sec delay
        outa[triac] := 1                                    ' turn triac on       
        waitcnt(cnt + (clkfreq ))                      ' 1sec delay
      
    
    

    Yes, This works just fine.
  • TCTC Posts: 1,019
    edited 2014-02-16 16:59
    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.

    I have been playing with it, I got something to work but I dont know if it is the right way do do it.
    pri triac_ctrl(zc, triac, p_ctrl) | mask, level                 ' launch with congnew
    
      dira[triac] := 1
    
    
        repeat level from 100 to 0
          waitpeq(|< zc, |< zc, 0)                                  ' wait for zero-cross
          if  level => p_ctrl                                       ' on now?
            outa[triac] := 1
    
          else
            outa[triac] := 0                                        ' kill triac output
          waitcnt(cnt + (clkfreq / 500))                            ' 2ms delay 
    
  • kwinnkwinn Posts: 8,697
    edited 2014-02-16 17:15
    Are you testing it with the heating element or a light bulb so you can see what is going on?

    Try changing the first waitcnt to 160,000,000 so you can see if a one or a zero turns on the power.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-02-16 17:35
    TC wrote: »
    I have been playing with it, I got something to work but I dont know if it is the right way do do it.
    pri triac_ctrl(zc, triac, p_ctrl) | mask, level                 ' launch with congnew
    
      dira[triac] := 1
    
    
        repeat level from 100 to 0
          waitpeq(|< zc, |< zc, 0)                                  ' wait for zero-cross
          if  level => p_ctrl                                       ' on now?
            outa[triac] := 1
    
          else
            outa[triac] := 0                                        ' kill triac output
          waitcnt(cnt + (clkfreq / 500))                            ' 2ms delay 
    

    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.
  • TCTC Posts: 1,019
    edited 2014-02-16 18:02
    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.
  • TCTC Posts: 1,019
    edited 2014-02-16 18:09
    kwinn wrote: »
    Are you testing it with the heating element or a light bulb so you can see what is going on?

    Try changing the first waitcnt to 160,000,000 so you can see if a one or a zero turns on the power.

    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.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-02-16 18:14
    TC wrote: »
    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.
  • kwinnkwinn Posts: 8,697
    edited 2014-02-16 23:52
    TC wrote: »
    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 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.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-02-17 01:59
    TC wrote: »
    I worry about the comments after I get something working, and I understand exactly what is going on.

    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.
  • TCTC Posts: 1,019
    edited 2014-02-17 03:56
    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.

    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.
    kwinn wrote: »
    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 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 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 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.
Sign In or Register to comment.