Rediculist: Ports and LED's

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
yzoer
XCore Addict
Posts: 133
Joined: Tue Dec 15, 2009 10:23 pm

Rediculist: Ports and LED's

Post by yzoer »

I can't really believe I'm asking this, but can anyone shed some light as to why this doesn't work on an XC-2? The button's port is not clocked (should it be?) and, since it's pulled high, returns 15 when it's not pressed and (sporadically) returns 14 when it is..

So all this example should do is turn on the led when the button is pressed, but it doesn't...

Suggestions?

Yvo

Code: Select all

#include <platform.h>
#include <xs1.h>

out port led = PORT_BUTTON_LED_0;
in port  button = PORT_BUTTON_A;

int main ()
{
	int c;

	while ( 1 )
	{
		button :> c;

		if ( (c&15)==15 )
			led <: 0;
		else
			led <: 1;
	}
}
Edit by Bianco: added code tags


User avatar
Gravis
Experienced Member
Posts: 75
Joined: Thu Feb 02, 2012 3:32 pm

Post by Gravis »

if you check the hardware manual then you will see that the buttons are not hooked to 1-bit ports. you can use them together as a 8 bit port (as you seem to be) or separated as 4-bit ports. page 11 of the XS1-G04B-FB512 datasheet has a good illustration about how all the ports are connected and how they can be used.

so... RTFM. :P
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am
Contact:

Post by segher »

yzoer wrote:The button's port is not clocked (should it be?)
Nope, no reason to, it's a very slow signal after all.
and, since it's pulled high, returns 15 when it's not pressed
It is not pulled high (well, not externally anyway): only bit 0 is, and
that is the only bit you care about. Incidentally, when you read from
a 4-bit port all but the low 4 bits will be returned as 0, so there is no
need to mask with &15. But you should use &1 here, for cleanliness
if nothing else.
and (sporadically) returns 14 when it is..
What does it return non-sporadically? That will (hopefully) point
to the real problem. Or we can guess of course :-)
yzoer
XCore Addict
Posts: 133
Joined: Tue Dec 15, 2009 10:23 pm

Post by yzoer »

Yup, I know it's a 4-bit port. Read plenty of manuals and schematics

Segher, the debugger actually returns 4-bits when you debug, as it should. The 'unused bits' are all pulled high internally with weak pull-ups.

It should be straight-forward and SHOULD work, but it doesn't. I've got an XK-1 laying around here somewhere too and will try that tonight to see if that gives similar results.

Either way, thanks for the replies!
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am
Contact:

Post by segher »

So you are saying most of the time when you read the port while
you hold the button depressed, you get back 15?

Sounds like you have broken the button... Try the other one?
yzoer
XCore Addict
Posts: 133
Joined: Tue Dec 15, 2009 10:23 pm

Post by yzoer »

Most of the time it'll just read high but I've managed (in the debugger, on real hardware) to read it correctly... for one or two iterations.

Thing is, BOTH buttons behave this way so I'm somewhat sceptical about it being the board. OTOH, they're both on the same port so it could be that the port's borked.. Like I said earlier, I'll see what I can coax out of my XK-1 tonight :-)
yzoer
XCore Addict
Posts: 133
Joined: Tue Dec 15, 2009 10:23 pm

Post by yzoer »

Just checked the same code on my XK-1 and it works as it should, so at least I'm not going crazy..

Bit of a shame about that port though...
User avatar
Ross
XCore Expert
Posts: 966
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

We did see some issues with the buttons and PCB washing process on early boards, this prompted us to change button model.
User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

I know this might sound silly to you, but can you try to assign the ports directly instead of using them in XN file and see if it works.

Say, Instead of using this,
out port led = PORT_BUTTON_LED_0;
in port button = PORT_BUTTON_A;
use
out port led = XS1_PORT_ 1E;
in port button = XS1_PORT_4C;
yzoer
XCore Addict
Posts: 133
Joined: Tue Dec 15, 2009 10:23 pm

Post by yzoer »

Thanks for the tip but I already confirmed it's the board, as the same test on another board worked as it should :-)

-Yvo
Post Reply