View previous topic :: View next topic |
Author |
Message |
Chris
Joined: 11 Nov 2004 Posts: 8
|
use of input(PIN_A0); |
Posted: Sun Oct 18, 2009 6:37 am |
|
|
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
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Oct 18, 2009 7:07 am |
|
|
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
|
Input(PIN_A0) use |
Posted: Sun Oct 18, 2009 10:09 am |
|
|
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
|
|
Posted: Sun Oct 18, 2009 12:38 pm |
|
|
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
|
Input(PIN_A0) use |
Posted: Mon Oct 19, 2009 2:04 am |
|
|
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
|
|
Posted: Mon Oct 19, 2009 3:20 pm |
|
|
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. |
|
|
|