Menu

Outputs are not staying on?

Ryan
2023-09-27
2023-09-29
  • Ryan

    Ryan - 2023-09-27

    When I run this the gpio.2 and gpio.4 only flicker and turn off right away but the gpio.5 stays on like it should amd I missing something?

    chip 12F675, 4 'mhz

    config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off

    define relay1 gpio.2

    define relay2 gpio.4

    dir gpio.0 in 'an0 bat1
    dir gpio.1 in 'an1 bat2
    dir relay1 Out
    dir relay2 Out
    dir gpio.5 out 'buck on
    dim bat1 as word
    dim bat2 as word

    main:
    bat1 = (ReadAD10(AN0))
    bat2 = (ReadAD10(AN1))
    if bat1 >= 409 then
    if bat2 < 409 then charge2
    end if
    if bat1 < 409 then
    if bat2 >= 409 then charge1
    end if
    if bat1 >= 409 then
    if bat2 >= 409 then chargeoff
    end if
    goto main

    sub charge1
    set relay1 on
    wait 10 ms
    set gpio.5 on
    wait 2 s
    set gpio.5 off 'buck off
    end sub

    sub charge2
    set relay2 on
    wait 10 ms
    set gpio.5 on
    wait 2 s
    set gpio.5 off 'buck off
    end sub

    sub chargeoff
    set gpio.5 off 'buck off
    set gpio.2 off 'relay1
    set gpio.4 off 'relay2
    goto main
    end sub

     
  • Ccin E Crout

    Ccin E Crout - 2023-09-28

    Hello Ryan.

    I might be tempted to alter your 'If...Then' statements slightly. It probably isn't the reason for your troubles, but it would make it perhaps a little clearer.

    Something along the lines of this:

    chip 12F675, 4 'mhz
    'Is this needed for Great Cow Basic?
    'config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
    
    #define relay1 gpio.2
    #define relay2 gpio.4
    dir gpio.0 in 'an0 bat1
    dir gpio.1 in 'an1 bat2
    dir relay1 Out
    dir relay2 Out
    dir gpio.5 out 'buck on
    dim bat1 as word
    dim bat2 as word
    
    main:
    bat1 = (ReadAD10(AN0))
    bat2 = (ReadAD10(AN1))
    
    If bat1 >= 409 And bat2 < 409 Then 
        charge2
    End If
    
    If bat1 < 409 And bat2 >= 409 Then
        charge1
    End If
    
    If bat1 >= 409 And bat2 >= 409 Then 
        chargeoff
    End If
    
    goto main
    
    sub charge1
    set relay1 on
    wait 10 ms
    set gpio.5 on
    wait 2 s
    set gpio.5 off 'buck off
    end sub
    
    sub charge2
    set relay2 on
    wait 10 ms
    set gpio.5 on
    wait 2 s
    set gpio.5 off 'buck off
    end sub
    
    sub chargeoff
    set gpio.5 off 'buck off
    set Relay1 off 'relay1
    set Relay2 off 'relay2
    'Is this goto superfluous?
    'goto main
    end sub
    

    Or this:

    chip 12F675, 4 'mhz
    'Is this needed for Great Cow Basic?
    'config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
    
    #define relay1 gpio.2
    #define relay2 gpio.4
    dir gpio.0 in 'an0 bat1
    dir gpio.1 in 'an1 bat2
    dir relay1 Out
    dir relay2 Out
    dir gpio.5 out 'buck on
    dim bat1 as word
    dim bat2 as word
    
    main:
    bat1 = (ReadAD10(AN0))
    bat2 = (ReadAD10(AN1))
    
    If bat1 >= 409 Then
        If bat2 < 409 Then 
            charge2
         End If
    End If
    
    If bat1 < 409 Then
        If bat2 >= 409 Then 
            charge1
         End If
    End If
    
    If bat1 >= 409 Then
        If bat2 >= 409 Then 
            chargeoff
         End If
    End If
    
    goto main
    
    sub charge1
    set relay1 on
    wait 10 ms
    set gpio.5 on
    wait 2 s
    set gpio.5 off 'buck off
    end sub
    
    sub charge2
    set relay2 on
    wait 10 ms
    set gpio.5 on
    wait 2 s
    set gpio.5 off 'buck off
    end sub
    
    sub chargeoff
    set gpio.5 off 'buck off
    set Relay1 off 'relay1
    set Relay2 off 'relay2
    'Is this goto superfluous?
    'goto main
    end sub
    

    I'm sure the compiler is clever enough to understand your original version as you wrote it, it did leave me scratching my head though for a while.

    I do use a few 12F675 and I've not had any problems with the outputs not staying on. I personally assign my outputs a value of '1' (for on) or '0' (for off) rather than using 'Set' though again, I see no reason at all why your original shouldn't work, it's just my personal coding style:

    Sub ChargeOff
        Let GPIO.5 = 0 'Turn Buck Off
        Let Relay1 = 0
        Let Relay2 = 0
    End Sub
    
     
  • Ryan

    Ryan - 2023-09-28

    I tried your ideas, and still same results, it will just pulse the output for whatever wait time I have after the on command then it goes off, and if i have no "wait" then it is just a instant on and off of the output?

    chip 12F675, 4 'mhz
    'Is this needed for Great Cow Basic?
    config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off

    dir gpio.0 in 'an0 bat1
    dir gpio.1 in 'an1 bat2
    dir relay1 Out
    dir relay2 Out
    dir gpio.5 out 'buck on
    dim bat1 as word
    dim bat2 as word

    main:
    bat1 = (ReadAD10(AN0))
    bat2 = (ReadAD10(AN1))

    If bat1 >= 409 Then
    If bat2 < 409 Then
    charge2
    End If
    End If

    If bat1 < 409 Then
    If bat2 >= 409 Then
    charge1
    End If
    End If

    If bat1 >= 409 Then
    If bat2 >= 409 Then
    chargeoff
    End If
    End If

    goto main

    sub charge1
    Set relay1 = 1
    wait 10 ms
    set gpio.5 = 1
    wait 2 s
    set gpio.5 = 0 'buck off
    end sub

    sub charge2
    set relay2 = 1
    wait 10 ms
    set gpio.5 = 1
    wait 2 s
    set gpio.5 = 0 'buck off
    end sub

    sub chargeoff
    set gpio.5 = 0 'buck off
    set Relay1 = 0 'relay1
    set Relay2 = 0 'relay2
    end sub

     
  • Ccin E Crout

    Ccin E Crout - 2023-09-28

    Well, I'm at a bit of a loss then as I can't see anything obvious.
    My next steps would be:
    Take out the line 'config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off'

    I don't think it's needed for GCB. I've never used it.

    Start with the real basics to check that there isn't something wrong with the wiring or PSU, something like:

    chip 12F675, 4 'mhz
    
    Dir GPIO.0 Out
    Dir GPIO.1 Out
    Dir GPIO.2 Out
    Dir GPIO.3 Out
    Dir GPIO.4 Out
    Dir GPIO.5 Out
    
    Wait 100 mS 
    'I have had trouble sometimes reprogramming these devices, having a small delay sometimes helps?
    
    Do
        Let GPIO.0 = 1
        Wait 5 S
        Let GPIO.0 = 0
        Let GPIO.1 = 1
        Wait 5 S
        Let GPIO.1 = 0
        Let GPIO.2 = 1
        Wait 5 S
        Let GPIO.2 = 0
        Let GPIO.3 = 1
        Wait 5 S
        Let GPIO.3 = 0
        Let GPIO.4 = 1
        Wait 5 S
        Let GPIO.4 = 0
        Let GPIO.5 = 1
        Wait 5 S
        Let GPIO.5 = 0
    Loop
    

    Check that that cycles through the outputs and then build the rest of the program step by step, one command at a time.

     
  • Anobium

    Anobium - 2023-09-28

    Ryan, thise changes really helped clarifying the code.

    There are two ways to resolve. A state engine: where you check the state before settings. Or, use #option volatile port.pin: this changes the default compile behaviour in the way a specific port.pin is set.

    Do try these methods.

     
  • Jerry Messina

    Jerry Messina - 2023-09-28

    what sort of load do you have connected to RELAY1 and RELAY2 outputs?
    individual bit set and clear instructions on ports can be subject to read-modify-write (RMW) issues, which sounds suspiciously like what you're seeing..

     
    • Ryan

      Ryan - 2023-09-28

      I am just turning on a led with a 220ohm resistor on both right now

       
  • Ryan

    Ryan - 2023-09-28

    I really am at a loss here....With just this code it turns on one output then after the wait turns it off before turning on the next output, I can switch the order and it will do the same thing with whatever output turns on first.

    chip 12F675, 4 'mhz

    'config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off

    Dir GPIO.0 Out
    Dir GPIO.1 Out
    Dir GPIO.2 Out
    Dir GPIO.3 In
    Dir GPIO.4 Out
    Dir GPIO.5 Out

    Wait 100 mS
    'I have had trouble sometimes reprogramming these devices, having a small delay sometimes helps?

    Do

    Let GPIO.2 = 1
    Wait 2 S    'THIS IS WHERE IT WAITS THEN TURNS OFF THE GPIO.2 ?    
    Let GPIO.5 = 1
    Wait 2 S
    Let GPIO.5 = 0
    let GPIO.2 = 0
    Wait 2 s
    

    Loop

     
    • Anobium

      Anobium - 2023-09-29

      Please attached the GCB, HEX and the ASM file produced from the compiler. I will inspect the ASM, but, this will tell us what version you are using ( OS, GCBASICversion, FreeBASIC version etc).

      We can load the Hex into simulators to see what happens.

       

      Last edit: Anobium 2023-09-29
      • Ryan

        Ryan - 2023-09-29

        here they are for the most basic version

         
  • Jerry Messina

    Jerry Messina - 2023-09-29

    Check to see if the pins are set for digital mode, otherwise if they're still in analog mode they'll always read as 0 and you'll see what you're describing.

    ANSEL = 0, CMCON = 7 will set them all to digital mode for that chip.

     
  • Ryan

    Ryan - 2023-09-29

    That did not change the result

     
  • Anobium

    Anobium - 2023-09-29

    Nothing obvious in the ASM. The ports are set to digital automatically.


    Tell me how you are programming?

     

    Last edit: Anobium 2023-09-29
  • Anobium

    Anobium - 2023-09-29

    The simulator operates correctly with your hex.

    Also, check the voltages. This could be a brown out.

    Share the programming methods to start with. ... is the calibration bit set?

     

    Last edit: Anobium 2023-09-29
  • Ryan

    Ryan - 2023-09-29

    I figured it out....Duh....too low of base resistor on the tranistors I had on the outputs and apparently that was making the pic do weird things

     
    • Anobium

      Anobium - 2023-09-29

      No problem.

      Enjoy the project.

       
  • Jerry Messina

    Jerry Messina - 2023-09-29

    That's why I asked what sort of load you had on the relay1 and relay2 outputs, which you defined as the GPIO pins.

    I guess i should have been more specific.

     

    Last edit: Jerry Messina 2023-09-29

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.