View previous topic :: View next topic |
Author |
Message |
PeWa
Joined: 15 Jan 2019 Posts: 22 Location: Sweden
|
Change PIN at Runtime |
Posted: Sat Nov 27, 2021 5:02 am |
|
|
In many examples we can use for example a #Define Pin_to_Use PIN_D1.
This is used when compiler generate the code.
However I have seen an example of change the PIN in runtime like this:
Code: |
int16 pin_to_use;
pin_to_use=PIN_B0;
output_low(pin_to_use);
pin_to_use=PIN_B1;
output_low(pin_to_use);
|
But this does not work in my case so I wonder what can go wrong with this type of code in CCS ? It compiles OK but the I/O address is wrong not point to the address defined in header file for the MCU.
Are there other ways to alter the PIN in an output_high(PIN_xx) at runtime maybe ?
I use compiler 5.076 and MCU is a 30F5011. |
|
 |
PeWa
Joined: 15 Jan 2019 Posts: 22 Location: Sweden
|
Re: Change PIN at Runtime |
Posted: Sat Nov 27, 2021 8:43 am |
|
|
PeWa wrote: | In many examples we can use for example a #Define Pin_to_Use PIN_D1.
This is used when compiler generate the code.
However I have seen an example of change the PIN in runtime like this:
Code: |
int16 pin_to_use;
pin_to_use=PIN_B0;
output_low(pin_to_use);
pin_to_use=PIN_B1;
output_low(pin_to_use);
|
But this does not work in my case so I wonder what can go wrong with this type of code in CCS ? It compiles OK but the I/O address is wrong not point to the address defined in header file for the MCU.
Are there other ways to alter the PIN in an output_high(PIN_xx) at runtime maybe ?
I use compiler 5.076 and MCU is a 30F5011. |
Edited, the variable address is OK. I can change a static LED but it seems that when I change to variable the output / input functions take some more time to compute. Is that the case ?? |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9427 Location: Greensville,Ontario
|
|
Posted: Sat Nov 27, 2021 8:55 am |
|
|
doing it as shown ,will require time to get the desired pin and insert into the output function
why not just ...
#DEFINE this_pin PIN_B2;
#DEFINE that_pin PIN_B4;
...
...
output_low(this_pin);
output_low(that_pin);
...
...
it 'should be faster'..... |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Change PIN at Runtime |
Posted: Sat Nov 27, 2021 9:23 am |
|
|
PeWa wrote: |
It seems that when I change to variable the output / input functions take some more time to compute. Is that the case ?? |
See this post. It shows how much ASM code is required if you use
a variable to pass the CCS pin number.
http://www.ccsinfo.com/forum/viewtopic.php?t=36953&start=3 |
|
 |
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Dec 03, 2021 2:29 am |
|
|
You can also use the get_env for the PORT and LAT register addresses.
Then build a struct as you like with a default set of values.
Then just write those values to PORT/LAT registers on start up.
You end up configuring an entire register with a single write.
I'd have to go look at an old example to see how much ASM results.... but it should be pretty thin. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
|