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

can input() change the output of a PIN?

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



Joined: 17 Jun 2019
Posts: 644
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

can input() change the output of a PIN?
PostPosted: Fri Nov 07, 2025 7:21 am     Reply with quote

We have a PIC24-based board that uses an output pin to toggle a synthesizer chip between internal mode (where it generates the RF signal) or external mode (where it takes a signal from an external source).

We toggle this mode like this:

Code:
void setRFInternal(void)
{
    powerUpFrequency (); // Power up the ADF device.
    output_low(RF_IN_SEL);
}

void setRFExternal(void)
{
    powerDownFrequency (); // Power down the ADF device.
    output_high(RF_IN_SEL);
}


I just enabled a new message in the firmware to show the status of this, and the code that was there (written years ago, never used) is this:

Code:
bool RFIsInternal(void)
{
    return (input(RF_IN_SEL) == 0);
}


We now have a new weird problem where the mode switches back, and I am wondering if this input() is doing it. It would change the pin to an input() to read it, and never be changed back to an output.

Am I on the right track? This should really use input_state() to read the pin without changing it?
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
temtronic



Joined: 01 Jul 2010
Posts: 9590
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Nov 07, 2025 8:06 am     Reply with quote

pretty sure you're on the right track

input() will change pin to an input
input_state() should just read whether pin is a 1 or 0

cut small test program with those two , compile and then dump the listing to see what is actually happening !!

ever since I switched ISPs my 'engineering' PC hasn't been the same....another of life's mysteries...
Ttelmah



Joined: 11 Mar 2010
Posts: 19970

View user's profile Send private message

PostPosted: Fri Nov 07, 2025 8:17 am     Reply with quote

and of course, think how the pin is biased when it is set to input.
Should you perhaps have a pull up on it, so if floating it will go high, and
the input being low will mean it is being driven?. (or a pull down depending
on what is expected and generated).
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