CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Output_High()

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
The Rookie
Guest







Output_High()
PostPosted: Mon Jun 21, 2004 11:31 am     Reply with quote

When I use the following code:

output_high(PIN_A0);
output_high(PIN_A1);


the A0 goes high and as soon as A1 goes high A0 goes low.

Basically the output_high for A0 does not stick.

Any suggestion on how I can keep A0 high
alexbilo



Joined: 01 Jun 2004
Posts: 39
Location: Trois-Rivières

View user's profile Send private message

PostPosted: Mon Jun 21, 2004 11:38 am     Reply with quote

If you use a PIC with an ADC module, did you disable the analog inputs for the pins A0 and A1?

Code:
setup_adc_ports(NO_ANALOG)


Just an idea...
_________________
Alex
The Rookie
Guest







Output_High
PostPosted: Mon Jun 21, 2004 11:41 am     Reply with quote

I am not using ADC

But I think it might be caused by the INT being enabled.
The Rookie
Guest







Output_High()
PostPosted: Mon Jun 21, 2004 12:28 pm     Reply with quote

The INT did not help. I still can not keep the A0 high once I use output_high() again.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 21, 2004 12:33 pm     Reply with quote

You need to tell us the PIC that you're using, and
the version of the CCS compiler, and what external
circuits (if any) you have connected to pins A0 and A1.
The Rookie
Guest







Output_High()
PostPosted: Mon Jun 21, 2004 12:48 pm     Reply with quote

I am using 12F629. And I do not have any circuits connected to it. I am looking at the pins via Logic Analyzer.

It almost seems like once Output_High() is called again it releases the state of the previous pin
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 21, 2004 1:10 pm     Reply with quote

What is your version of the compiler ?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Jun 21, 2004 1:57 pm     Reply with quote

Could it be a read-modify-write problem? Try putting a delay-us(1) between the output statements.
The problem occurs because of the way the PIC bit setting operation occurs and the way instructions are pipelined. Basically the pin-a1 command starts before the pin-a0 command is done so the second command overwrites the output of the first.
It is a long standing quirk of PIC processors.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Mon Jun 21, 2004 5:02 pm     Reply with quote

version 3.185
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 21, 2004 5:49 pm     Reply with quote

You need to turn off the comparators, as shown below.
I looked at the LST file, and that function should work OK
on your version of the compiler.

Code:
void main()
{
setup_comparator(NC_NC_NC_NC);  // Turn off comparators

output_high(PIN_A0);
output_high(PIN_A1);

while(1);  // Prevent PIC from going to Sleep
}
Ttelmah
Guest







Re: Output_High()
PostPosted: Tue Jun 22, 2004 2:05 am     Reply with quote

The Rookie wrote:
When I use the following code:

output_high(PIN_A0);
output_high(PIN_A1);


the A0 goes high and as soon as A1 goes high A0 goes low.

Basically the output_high for A0 does not stick.

Any suggestion on how I can keep A0 high

Others have mentioned the ADC, and comparator, but the other possibility is that you are suffering from the 'read_modify_write' problem.
Basically, whenever you do I/O on a bit of the port, the whole port is read, the bit is modified, and the result written back. Now the first instruction sets pin A0 'high', but the pin itself does not respond immediately. It starts to drive high at the end of the instruction, and the tme taken for the signal level to actually get to the 'high' detection point, will depend on the nature of the pin (whether it has Schmidt inputs), the capacitance and resistive load attached. Now the next instruction, reads the port as the first clock cycle of the instruction, then modifies the bit from what it has read, and outputs the whole byte at the end of th instruction. The problem is that it is common for pins with 'normal' loads, to take quite a significant time to actually 'read' as high, and when the two instructions are 'nose to tail', this may not yet have happened. This is mentioned both in the Microchip data sheets in various places, and in the CCS manual, but they don't really make it clear, just how long the timescales may be.
If this is the problem, there are three possible solutions:
1) If the chip involved is one of the latter '18' family chips, then instead of using output_high, consider writing directly to the LATB register. This is available on the latter chips to avoid this problem.
2) Try simply adding a delay between the first and second write.
3) Alternatively, keep a global variable containing the value you want to appear on port B, and set the bits on this, then output this as a whole byte using 'output_b'.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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