Sequence of statements makes code work differently. (PIC16F628A)
Hello,
below is the super simple code
Code:
SIKO:
HIGH PORTA.0
HIGH PORTA.1
PAUSE 500
LOW PORTA.0
LOW PORTA.1
PAUSE 500
GOTO SIKO
There are leds connected to porta.1 and porta.0
The above code works, but only first line
If I place at first line code for PORTA.0 it works, but next line, for PORTA.1 does not works. If I swap them, then PORTA.1 will work, but PORTA.0 - not. But if I modify code a bit, to look like this, then it works properly.
SIKO:
HIGH PORTA.0
PAUSE 500
LOW PORTA.0
HIGH PORTA.1
PAUSE 500
LOW PORTA.1
GOTO SIKO
[/code]
Why this happens?
I have no TRISA, etc defined, as manual told us, HIGH/LOW statement in PBP does all necessary, so this is why it is so slow, but it appears not to work?
Re: Sequence of statements makes code work differently. (PIC16F628A)
Without seeing your schematic, my guess would be the Read-Modify-Write issue documented in the data sheet. Try to write to PORTA as a whole rather than in bits to confirm this is the issue.
Re: Sequence of statements makes code work differently. (PIC16F628A)
Resistor-led-pin, that's all :)
Re: Sequence of statements makes code work differently. (PIC16F628A)
Strange, and how to write PORTA in whole? like this?
PORTA=%00000001
?
Re: Sequence of statements makes code work differently. (PIC16F628A)
It does not work, even setting PORTA.1=1 does nothing
Re: Sequence of statements makes code work differently. (PIC16F628A)
Try
Code:
SIKO:
PORTA=%00000011
PAUSE 500
PORTA=%00000000
PAUSE 500
GOTO SIKO
Re: Sequence of statements makes code work differently. (PIC16F628A)
Everybody together now:
Remember to disable analog functions...
Remember to disable analog functions...
Remember to disable analog functions...
/Henrik.
Re: Sequence of statements makes code work differently. (PIC16F628A)
628A has analog functions?
P.S. I do have CMCON disabled...
Re: Sequence of statements makes code work differently. (PIC16F628A)
Quote:
Originally Posted by
CuriousOne
628A has analog functions?
Page 1 of the data sheet !
2 analogue comparitors - Pins PORTA.0 to PORTA.3
Re: Sequence of statements makes code work differently. (PIC16F628A)
Quote:
628A has analog functions?
Yes it does, the comparators are analog and enabled by default.
Quote:
P.S. I do have CMCON disabled...
Your code doesn't show that. What does having CMCON disabled mean? What are you writing to it?
From the datasheet
Quote:
The PORTA pins are multiplexed with comparator and
voltage reference functions. The operation of these
pins are selected by control bits in the CMCON
(Comparator Control register) register and the VRCON
(Voltage Reference Control register) register. When
selected as a comparator input, these pins will read
as ‘0’s.
When you do stuff like
Code:
PortA.0 = 1
PortA.1 = 1
All bit operations on a register is performed as a read-modify-write operation. The port is read, modified and written back - it's the way it works inside the PIC itself. If the read operation returns a state of a pin that is different to what you set then that erroneous state will be written back to the port and you get "weird" and "unexpected" results. Having analog functions enabled is THE most (un)popular cause of this happening.
Having too much load, or a capacartive load on the actual output is another cause. In this case the voltage level at the pin isn't allowed to rise to a level where the read operation of the second command actually "gets" a logic 1.
/Henrik.
If you Google read modify write you'll find loads and loads of explainations.
Re: Sequence of statements makes code work differently. (PIC16F628A)
Simple trick to shadow the port with a latch byte and send that to the port at the expense of some speed.
Code:
portalatch var byte
portalatch = 0’
portalatch.bit0 = 1
PORTA = portalatch'
Even though it would have been pins left analogue this time, it will still cause hard to debug problems.