Hi all,
I have received the USB audio 2.0 reference kit earlier and have started to do some experiment on it.
I have read through the XC language tutorials, etc. Now looking at the reference USB audio 2.0 software.
The first thing I would like to try is to program the 2 hardware buttons to do something like turning on/off leds that were on the reference board.
I have search through the USB audio 2.0 reference software and couldn't see anything that access the 2 buttons.
Can anyone give some sample codes or point me to a direction on how to achieve this ... Thanks...
Michael :D
Help needed for newbie to USB Audio 2.0 Reference Kit
-
- New User
- Posts: 3
- Joined: Fri Nov 25, 2011 3:03 am
- Location: HK
-
Verified
- XCore Legend
- Posts: 1163
- Joined: Thu Dec 10, 2009 9:20 pm
- Location: Bristol, UK
Have a look at the "port map" in the hardware manual (https://www.xmos.com/download/public/US ... 1.0%29.pdf, page 13). This will show you what port the buttons (and LEDs) are connected to.
Perhaps have a look at some of the simpler tutorials on xmos.com? Tutorials for the XC-1A or XK-1 board should be useful for lighting LEDs etc.
Perhaps have a look at some of the simpler tutorials on xmos.com? Tutorials for the XC-1A or XK-1 board should be useful for lighting LEDs etc.
Technical Director @ XMOS. Opinions expressed are my own
-
- New User
- Posts: 3
- Joined: Fri Nov 25, 2011 3:03 am
- Location: HK
Thanks Ross,
I managed to look up the documents and wrote some code to print a character on the console.
Here is the sample:
When I press the switch on the board, the console should print out "A B A B A B" ......
But what I found is it sometimes printed out two As in a row.
I think I might need to debounce the key pressed.
Could you show me how to properly do debouncing with the ports in XC ?
Thanks very much.
Michael
I managed to look up the documents and wrote some code to print a character on the console.
Here is the sample:
Code: Select all
on stdcore[0] : in buffered port:1 switchA = XS1_PORT_1J;
void buttons() {
int sA;
switchA :> sA;
while( 1 ){
select {
case switchA when pinsneq( sA ) :> sA:
{
if( sA == 0 )
printstr( "A " );
else
printstr( "B " );
break;
}
}
}
}
But what I found is it sometimes printed out two As in a row.
I think I might need to debounce the key pressed.
Could you show me how to properly do debouncing with the ports in XC ?
Thanks very much.
Michael
-
- Respected Member
- Posts: 298
- Joined: Thu May 12, 2011 11:14 am
Please use the code tags :P
It's makes it easy to distinguish code from text!
It's makes it easy to distinguish code from text!
-
- New User
- Posts: 3
- Joined: Fri Nov 25, 2011 3:03 am
- Location: HK
Thanks for adding the code tag for me.
Here is an updated version of my code:
This seems to fix the problem of getting 2 As in a row if repeatly press the switch.
Can someone suggest a better ways to do this ?
Here is an updated version of my code:
Code: Select all
on stdcore[0] : in buffered port:1 switchA = XS1_PORT_1J;
void buttons()
{
int sA;
int pressed;
switchA :> sA;
pressed = -1;
while( 1 ) {
select {
case switchA when pinsneq( sA ) :> sA:
if( sA == 0 && pressed != 1 )
{
printstr( "A " );
pressed = 1;
}
else if( pressed != 0 )
{
printstr( "B " );
pressed = 0;
}
break;
}
}
}
Can someone suggest a better ways to do this ?
-
Verified
- XCore Legend
- Posts: 1163
- Joined: Thu Dec 10, 2009 9:20 pm
- Location: Bristol, UK
What about using a timer to ignore glitches? Something like the following pseudo code:
p.s. perhaps someone can split off this button stuff to a new thread "button de-bounce" or similar?
Code: Select all
if(buttonDown)
{
// Get time from timer
t :> time;
if(!buttonDown)
{
// Button state changed, ignore as glitch
}
else if(currentTime is greater than time + antiglitch)
{
// Register button press
}
}
Technical Director @ XMOS. Opinions expressed are my own