Limit on # of 2 port sensors on VEX Cortex

We are having an issue with using 3 sensors (two sonars and 1 encoder or three sonars).
Once we have 3 sensors (digital) the debug window in RobotC will not show all 3 and other issue begin to arise.
I’m a teacher that has two different groups having this issue this year and I’ve never experienced this before. We’ve tried multiple cortexes and sensors to rule those out, updated firmware etc.

Any suggestions or thoughts?

So the one important thing you are probably running in to is don’t use both ports 4 and 10 at the same time.
Those ports share some internal structure and can both be used at the same time for buttons etc but only one can be used as encoder or ultrasonic sensor at a time.


While I have another minute I can go into more detail. Ports 4 and 10 share an interrupt which is a piece of embedded processor wizardry that detects changes on a pin and “interrupts” the program to acknowledge the change immediately.

On a button you just need to read the sensor when a user requests it, but on an encoder you want the program to count how many times the encoder value changed, this requires using an interrupt to detect up to a few thousand changes a second. On an ultrasonic sensor you send out a pulse of ultrasonic waves and when the sensor receives the return pulse it pings in response, we calculate the distance by subtracting time received - time sent and dividing by speed of light. What this means is we want to save the exact time the sensor receives the pulse and thus need an interupt.



Thank you so much for the reply. We will give it a try tomorrow to see if that is the cause with both groups. I don’t think I had ever heard that before.
Are there any other ports that I need to watch out for in the future like this, or is it just 4 and 10 on the digital side?

I will be sure to make a note of this for future years!

1 Like

From experience, more than 3 sonars being checked in a tight loop start having some lag issues, so don’t go fast heading into a wall. Spreading the checks out helps with the problem.

Griffin is spot on the 4/10 split.

1 Like

No other “traps” I can think of off the top of my head. It is sorta standard practice to do stuff like this in embedded processors, have tons of features that share the same under the hood pins and restrict users to 1 of them. The confusing part is that the Cortex only has that happen exactly once, ports 4/10 on digital, so its something you never think about.

There are a bit deeper explanations around as for whats going on with 4/10 under the hood if anyone is curious.


8-9 years ago there was a lot of discussion about these sorts of issues, but as no one is using cortex for competition anymore, mostly it will only be the “old timers” like @tabor473 who will remember such details.
(the posts Griffin linked were posted by me while I was still a VEX customer not an employee).