Would be much simpler to post your WHOLE code here than let us GUESS what could be wrong ...
Don't you think ???
Alain
Would be much simpler to post your WHOLE code here than let us GUESS what could be wrong ...
Don't you think ???
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Sorry, I didnt know how to use the Code: boxes but here is the "non-working" code:
Code:DEFINE OSC 4 'Define for 4MHz crystal DEFINE LOADER_USED 1 ' Boot loader for ICSP ' ' ***** Configure I/O ************************************************ PORTC = %00000000 TRISC = %00000000 Rel1 var PORTC.0 ' Relay1 Transistor input Rel2 var PORTC.1 ' Relay2 Transistor input Rel3 var PORTC.2 ' Relay3 Transistor input Rel4 var PORTC.3 ' Relay4 Transistor input ' Startup: Gosub TestRelay1 END ' TestRelay1: High Rel1 Pause 1000 High Rel2 Pause 1000 High Rel3 Pause 1000 High Rel4 Pause 1000 Low Rel1 Pause 1000 Low Rel2 Pause 1000 Low Rel3 Pause 1000 Low Rel4 Pause 1000 End
Last edited by Acetronics2; - 27th January 2011 at 13:09.
It definitely sounds like a read-modify-write problem. What happens is the HIGH & LOW commands create BSF PORT,PIN for HIGH, and BCF PORT,PIN for LOW.
This reads the value of the port, flips the bit in question, then writes the whole 8-bit value back to the port. The problem is after you set C0 then set C1. If C0 hasn't transitioned to logic 1 before it sets C1, then it reads-in a logic 0 on C0, then places a logic 0 on C0 when it sets C1.
With PORTC = xx it doesn't read the port first, flip a single bit, then write back, so you don't see this problem.
Normally R-M-W is caused by external capacitance on the pin, which doesn't allow time for the previous pin to transition to the expected logic state before changing the next port pin. But the long delays in between flipping each bit is usually sufficient time for the previous pin to make the transition to the expected logic state.
With 500mS or 1 second in between it should be more than enough time so I would have to suspect a problem in your circuit causing the previous pin you set being read back as 0 on the next BSF op.
This same problem is seen when you don't disable analog features on a port, but there aren't any A/D pins on portc. Pins configured as analog are always read in as zero when the port is read as digital inputs.
It might help if you could post your schematic.
Last edited by Bruce; - 27th January 2011 at 13:42.
I would add ...
What if you replace the Relays by LEDs + 220 ohms resistors ???
I do hope relays are equipped with their freewheel diode ... and NOT powered from the Pic 5v supply ...
Alain
PS : as the program runs fine aboard my EasyPic5 with leds as outputs ... we could reasonnably suppose it's a HARDWARE issue ...
Last edited by Acetronics2; - 27th January 2011 at 14:19.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Thanks Guys -
I am scouring through the hardware. Attached is the schematic ...
Can really mess up a few days...
Thanks to all for the support. I guess the fact that when written with binary logic the program worked fine - it threw me for a loop and took focus off the hardware. My apologies ...
Bookmarks