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 support@ccsinfo.com

use of input(PIN_A0);

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



Joined: 11 Nov 2004
Posts: 8

View user's profile Send private message

use of input(PIN_A0);
PostPosted: Sun Oct 18, 2009 6:37 am     Reply with quote

Hello CCS Users,
I am writing code for a PIC16F777, my compiler is PCB,PCM,PCH 3.185
I have a 14 chan board and need to test pin states for each channel. Typically input(PIN_A0) or input(PIN_A1) etc.

I want to replace the PIN_A0 with a variable containing the string equivalent, eg. input(pin_str), but compiling causes this error:
'Expression must evaluate to a constant'

I suspect trying to replace the PIN_A0 (constant) with pin_str (var) is not allowed, but I dont understand why. Is there an alternative or am I doing somthing wrong. Do I need a later version of the compiler. Is it a compiler issue?

I wondered about creating an if elseif with all variations of the input(PIN_xx) command but this seems odd.

Help greatly appreciated.

Regards Chris
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 18, 2009 6:53 am     Reply with quote

Quote:
I want to replace the PIN_A0 with a variable containing the string
equivalent, eg. input(pin_str), but compiling causes this error:
'Expression must evaluate to a constant'

This feature is built-in to vs. 4, but for vs. 3 you need to use routines.

For 16F:
http://www.ccsinfo.com/forum/viewtopic.php?t=25280&start=4

For 18F:
http://www.ccsinfo.com/forum/viewtopic.php?t=27723&start=3
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Oct 18, 2009 7:07 am     Reply with quote

PIN_A0 actually is a constant, representing a port address and a bit number. For a variable IO pin addressing, you have to decode the respective string at runtime in your code, e.g. using a table.
Chris



Joined: 11 Nov 2004
Posts: 8

View user's profile Send private message

Input(PIN_A0) use
PostPosted: Sun Oct 18, 2009 10:09 am     Reply with quote

Hello PCM & FvM,
Both good answers, thanks, I will upgrade when I have some cash, in the meantime FvM answer looks like a possible solution. Could you explain how to 'decode the string at runtime'. I started to build a clunky if-else:
Code:

if(pin == 1){
   if(true_param){
       while(input(PIN_A0));          // if it's high, wait for a low
   }
   else{
       while(!input(PIN_A0));
   }
}

else if(pin == 2){
   if(true_param){
       while(input(PIN_A1));
   }
   else{
   while(!input(PIN_A1));
   }
}

etc.

I have just extracted the input() lines that need running alongside a while and created if, else for each pin. Is this what you meant or is there a more elegant method, please?
Regards Chris
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 18, 2009 12:38 pm     Reply with quote

1. Tell us what your project is basically about.

2. What external circuits or devices are connected to the pins on each
channel ?

3. Post a list of the pins that are used for the channels.
Chris



Joined: 11 Nov 2004
Posts: 8

View user's profile Send private message

Input(PIN_A0) use
PostPosted: Mon Oct 19, 2009 2:04 am     Reply with quote

Hello PCM Programmer,

http://www.robotic-systems.co.uk/products/14-channel-logger.htm

I have a simple pic16F777 circuit (url above) I am using as a 14 chan pulse width measuring device, like a multi chan scope except it can only take a snapshot of pulse widths 1 chan at a time via RS232, the PC user types keys (1 - 14 return) which the pic gets via RS232. However these measurements a very accurate when compared to a scope. The pic then carries a pulse width measurement on that channel and passes a string with the answer back to the PC via RS232. This may be useful for testing car ECUs etc where lots of pulses are running on the same device.

Keyboard Commands could be automated using test equipment to carry out lots of automated pulse width measuring.

I have had this code working fine but the code was all long hand not much looping and I ran out of RAM after 10 channels so I am trying to rewrite and refine. You can see that as I need to use a good number of the input(PIN_xx) commands my code size is a problem. Finally my lack of experience writing C and with pics isn't helping.

Thanks
Chris
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 19, 2009 3:20 pm     Reply with quote

If you use the code in the links that I posted, it probably takes 50
instruction cycles or more to read one i/o pin. This is compared to
just a few cycles if you use the CCS input() function.

You apparently want to sample at a fast rate, so I don't think the code
in the links will be useful.
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