|
|
View previous topic :: View next topic |
Author |
Message |
_olaf_
Joined: 24 Feb 2005 Posts: 32
|
Problem with Output_low/high() |
Posted: Sun Feb 11, 2007 4:47 am |
|
|
Hi,
I have a question about setting the output of portpins on a 16F873. If I use the following Code, everything is o.k.
Code: | switch (x)
{
case 0: OUTPUT_A(0x00);
break;
case 1: OUTPUT_A(0x03);
break;
case 2: OUTPUT_A(0x05);
break;
case 3: OUTPUT_A(0x01);
break;
}
|
But if I use the output_low or *_high statement like I use it in the following code the pins don't have the behaviour what they should have.
Code: |
switch (l_n)
{
case 0: output_low(Q_A2);
output_low(Q_B2);
output_low(Q_C2);
break;
case 1: output_high(Q_B2);
output_low(Q_C2);
break;
case 2: output_high(Q_A2);
output_low(Q_B2);
output_high(Q_C2);
break;
case 3: output_high(Q_A2);
output_low(Q_B2);
output_low(Q_C2);
break;
}
|
The two examplecode should not do the same, ist is only an example of the code which is working (OUTPUT_A() ) and the one (output_low/high() ) which does not work
Does anyone have an idea what the Problem is. Interrupts are all disabled. I have tried to bring an delay between the instruction but without succes. It is the same behaviour on PortA or PortB.
Regards Olaf |
|
|
Ttelmah Guest
|
|
Posted: Sun Feb 11, 2007 5:06 am |
|
|
What are the pin definitions being used in the output high/low instructions. Difficult for us to know what is happening without these...
However, the 'odds' are that this is the RMW problem.
On the PIC, when you set /clear an individual pin, the current status of the pins is read from the port, modified, and writen back to the port (hence read, modify, write - RMW). Now two things cause problems here. The first is if there is significant capacitance present, where if a pin is changed, it takes _time_ to reach the required voltage. However a delay added between each instruction nd the next, should solve this. The second though is loading. For instance, if a pin drives an LED directly, without a suitable current limit resistor, it may never reach the required output voltage, and will therefor always read incorrectly. The answer to this, is to design the circuit properly...
Best Wishes |
|
|
vsmguy
Joined: 13 Jan 2007 Posts: 91
|
|
Posted: Sun Feb 11, 2007 7:44 am |
|
|
It would be great if the OP provided the schematic and the pin definition.
Would help us answer straight away. I have written almost the same code a while ago, and faced no problem.
Perhaps a simple voltage follower on the output pins might do the trick ? |
|
|
_olaf_
Joined: 24 Feb 2005 Posts: 32
|
|
Posted: Sun Feb 11, 2007 8:23 am |
|
|
Hi,
I think it is not a hardwareproblem. At the pin there is only a Low-Current LED (1,5mA with resistor), no capacitance is connected (I know the problem of this since my first controller PCB ). This should be low enough for the port. As I mentiond above, I tried to insert a delay with up to 200ms. This was the first thing I tried, because I had some timingproblems on another project before. But it is the same behaviour, the pins are not set.
The Pin definition is like
#define Q_A2 40 // PortA0
#define Q_B2 41 // PORTA1
#define Q_C2 42 // PORTA2
The Problem is, that there is a different behaviour on the same pins. If I make a short test with toggling the portpins it is different when using the OUTPUT_X or the output_low/high. This is what I don't understand. It should be the same. The pins should go high and low.
EDIT:
I have forgotten the Compilerversion
MPLAB V7.43
Compiler PCM 3.223 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|