Main Site Documentation

How can I read/write multiple GPIO pins at a time?


#1

I have an array of 8 sensors attached to my device ( a Fez PANDA II)

The information is returned as the amount of time the pin is high, and my sensors are connected to [P1.22…P1.29]

What I’d like to do is read the value of all of the pins in one go to process them.

Am I right in assuming that if I do this, it will work?

#define FIO1DIR (*(volatile unsigned long )(FIO_BASE_ADDR + 0x20))
#define FIO1MASK (
(volatile unsigned long )(FIO_BASE_ADDR + 0x30))
#define FIO1PIN (
(volatile unsigned long )(FIO_BASE_ADDR + 0x34))
#define FIO1SET (
(volatile unsigned long )(FIO_BASE_ADDR + 0x38))
#define FIO1CLR (
(volatile unsigned long *)(FIO_BASE_ADDR + 0x3C))

unsigned int Port1CurrentValues = FIO1PIN;

after which I can mask out the bits I’m looking for?

I also have another set of sensors attached to four different pins on the same port.
{ P1.1, P1.10, P1.8, P1.4}

In order to set up the sensor to deliver it’s values, I must set the pin high, wait 10 microseconds, and then set the pin low. I can then poll for the pulse train from the device.

is this pseudo code about right?

#define P0MASK = 1<<0;
#define P1MASK = 1<<1;
#define P2MASK = 1 << 2;

#define P31Mask = 1 << 31;

unsigned int pinMask = (P1MASK | P10MASK | P4MASK | P8MASK);

// ideally i’d like to disable interrupts here
FIO1DIR = FIO1DIR | pinMask;
// ideally i’d like reenable interrupts

FIO1SET= pinMask; // set my pins to output high.

// do additional work, and then wait for 10us timeout to expire as well.

FIO1CLR = pinMask; // set my pins output to low.

// ideally, I’d like to disable interrupts before the next line.
FIO1DIR = FIO1DIR & ~(pinMask); // set the port back to it’s previous io state.
// again, reenable interrupts

// now do work to process the response


#2

Start by using register class first as it is much easier to use


#3

Can I do that from RLP?


#4

Yes sure but using registers is easier. I usually start using register class to get as far as I can. If I was able to do without RLP then I do not use RLP but if I couldn’t then I move only the absolute necessary code to RLP.

This is just a suggestion but yes you can do it all in RLP.


#5

We’ve worked out that we’re not going to have enough time or resolution to be able to detect the edges on 20 inputs with microsecond accuracy, unfortunately, so we’re definitely headed down he RLP route.

If I configure all the ports in C#, can I just access them later in C with no setup, as long as I keep off them once I kick off my routine?


#6

Yes, in some cases this is a very good approach. Actually, when a customer needs a specific non-standard baud rate on UART, we ask them to open the port in C# so everything is initialized properly then RLP or register access is used to change the baudrate registers.

In your case, you seem to know more than I had anticipated so you should be fine with RLP.


#7

Got it all working! 16 infrared sensors, and 4 ultrasonic sensors read in at most 39msec while giving the sensors 38 msec to respond! And average response time for the acquisition now around 10msec for all the inputs.

Had a gotcha on the way though: Got bitten by the fact that there’s a copy of the elf file in the resources folder, that isn’t the one that’s built by make. I had hoped it would add the file as a link, but that breaks in the compiler.

Can’t wait to see how the Robot performs in Turkey for the world finals of Robocup Soccer Junior next week.


#8

Do we get some pictures/videos of all the fun?


#9

There will be ongoing coverage of the team and the event at:
http://technobotts.info/blog/
and
http://technobotts.info


#10

Interesting approach for the wheels. Never seen that before.


#11

The discontinuity between the ELF file and the managed project is kind of a bummer. However, what I did was add a step to the makefile to copy the elf file to the resources directory of the VS project. Then I just need to build and deploy the managed file. It still requires that extra step, but otherwise it works like a charm.


#12

Alternatively, you could probably run make as a pre-build step or add the link file to the project with a custom build step.

I was just flagging that when your code doesn’t work and you get exceptions when you call
RLP.GetProcedure
the reason will be you have an out of date .elf file.


#13

What if your RLP has the compile time/date in some function and then you do something like

Debug.Print(RLP.GetBuildTime());

This will assure you that the elf file you are suing is built at specific time.


#14

My problem was I added my function (and when that didn’t work) tried to edit yours to return a different value. After about 2 hours, I discovered that editing and making the samples provided wasn’t sufficient to get it onto the device.

Just hoping to spare others the same pain.


#15

Video of the working robot

and the blog has been updated at
http://technobotts.info/blog/


#16

[quote]Interesting approach for the wheels. Never seen that before.
[/quote]
They sort of remind me of mechanum/mecanum wheels (random vid: http://www.youtube.com/watch?v=8XkgUBZqWdA) but I’ve never seen one with only 3 wheels before.

Very cool!


#17

Hi i want to write to multiple gpio’s from RLP.
But I have some problems with configurations.

I want to set the following pins on EMX
//P1.20 IO51 T6
//P1.21 IO52 T7
//P1.22 IO53 T8
//P1.23 IO54 T9
//P1.24 IO55 T10
//P1.25 IO56 T11
//P1.26 IO57 T13
//P1.27 IO58 T14

I don’t know if this pins are reserved or something.

I have tried to set PINSEL3 = 0; but it seems not to work;

//Set the direction to output
FIO1DIR = 0xff00000;

//Sets pins to one
FIO1SET = 0xff00000;

//sets pins to zero
FIO1CLR = 0xff00000;

I have managed to write to other pins on port P0 with the same setup
but this pins are given me problems.
Regards


#18

Hi,

I saw from your messages that you “Got it all working! 16 infrared sensors, and 4 ultrasonic sensors read in at most 39msec while giving the sensors 38 msec to respond! And average response time for the acquisition now around 10msec for all the inputs” on an Panda II.
I would like to do something similar on a smaller scale: need about 5 infrared and up to 4 ultrasonic sensors for a robot. I’m using only C# and I can manage to get 4 infrared Sharp GP2D120 but I’m having trouble with the ultrasonic sensors: I tried Ping and HC-sr04 but the result is very inconsistent.

  • did your IR sensors were analog? Panda 2 has only 6 analog ports and I was curious how you did manage to read 16 sensors.
  • also, can you share your code that allowed you to reliably use the ultrasonic sensors with Panda 2?

Thank you,
Sorin


#19

Sorin, welcome to the forums. I would suggest that you move your questions to a separate question since the original intent of this post was RLP related, not sensor related. You’ll likely see more input if you ask separately.


#20

We decided that we couldn’t possibly run our code fast enough in C#, so had to fall back to C, hence the RLP thread.

I posted our C code here:

The ultra sound was pulse width modulated, but it is effectively a ping sensor: We set a pulse as an output, changed it to an input, and measured the width of the returned pulse, or timed out.

Are you competing in Robocup Sorin?