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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
chip12F675,4'mhz'Is this needed for Great Cow Basic?'config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off#definerelay1gpio.2#definerelay2gpio.4dirgpio.0in'an0 bat1dirgpio.1in'an1 bat2dirrelay1Outdirrelay2Outdirgpio.5out'buck ondimbat1asworddimbat2aswordmain:bat1=(ReadAD10(AN0))bat2=(ReadAD10(AN1))Ifbat1>=409Andbat2<409Thencharge2EndIfIfbat1<409Andbat2>=409Thencharge1EndIfIfbat1>=409Andbat2>=409ThenchargeoffEndIfgotomainsubcharge1setrelay1onwait10mssetgpio.5onwait2ssetgpio.5off'buck offendsubsubcharge2setrelay2onwait10mssetgpio.5onwait2ssetgpio.5off'buck offendsubsubchargeoffsetgpio.5off'buck offsetRelay1off'relay1setRelay2off'relay2'Is this goto superfluous?'goto mainendsub
Or this:
chip12F675,4'mhz'Is this needed for Great Cow Basic?'config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off#definerelay1gpio.2#definerelay2gpio.4dirgpio.0in'an0 bat1dirgpio.1in'an1 bat2dirrelay1Outdirrelay2Outdirgpio.5out'buck ondimbat1asworddimbat2aswordmain:bat1=(ReadAD10(AN0))bat2=(ReadAD10(AN1))Ifbat1>=409ThenIfbat2<409Thencharge2EndIfEndIfIfbat1<409ThenIfbat2>=409Thencharge1EndIfEndIfIfbat1>=409ThenIfbat2>=409ThenchargeoffEndIfEndIfgotomainsubcharge1setrelay1onwait10mssetgpio.5onwait2ssetgpio.5off'buck offendsubsubcharge2setrelay2onwait10mssetgpio.5onwait2ssetgpio.5off'buck offendsubsubchargeoffsetgpio.5off'buck offsetRelay1off'relay1setRelay2off'relay2'Is this goto superfluous?'goto mainendsub
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:
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
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:
chip12F675,4'mhzDirGPIO.0OutDirGPIO.1OutDirGPIO.2OutDirGPIO.3OutDirGPIO.4OutDirGPIO.5OutWait100mS'I have had trouble sometimes reprogramming these devices, having a small delay sometimes helps?DoLetGPIO.0=1Wait5SLetGPIO.0=0LetGPIO.1=1Wait5SLetGPIO.1=0LetGPIO.2=1Wait5SLetGPIO.2=0LetGPIO.3=1Wait5SLetGPIO.3=0LetGPIO.4=1Wait5SLetGPIO.4=0LetGPIO.5=1Wait5SLetGPIO.5=0Loop
Check that that cycles through the outputs and then build the rest of the program step by step, one command at a time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
LetGPIO.2=1Wait2S'THIS IS WHERE IT WAITS THEN TURNS OFF THE GPIO.2 ? Let GPIO.5 = 1Wait 2 SLet GPIO.5 = 0let GPIO.2 = 0Wait 2 s
Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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:
Or this:
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:
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
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:
Check that that cycles through the outputs and then build the rest of the program step by step, one command at a time.
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.
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..
I am just turning on a led with a 220ohm resistor on both right now
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
Loop
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
here they are for the most basic version
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.
That did not change the result
Nothing obvious in the ASM. The ports are set to digital automatically.
Tell me how you are programming?
Last edit: 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
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
No problem.
Enjoy the project.
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