Button Control

If you have a simple question and just want an answer.
User avatar
xaerox
Active Member
Posts: 43
Joined: Thu Apr 30, 2015 6:12 pm

Button Control

Post by xaerox »

Hello everybody,
in my workspace I want to include a button to control audio.
On my board the button is connected to an 4-Bit port (port 0), which means, that I use the value 0x8 to check, if the button was pressed.
I also checked out the button-handle example where I use the following code to try (code is already modified):

Code: Select all

[[combinable]]
void task1a(port p_button, streaming chanend c_ButtonVal)
{
  int current_val = 0;
  int is_stable = 1;
  timer tmr;
  const unsigned debounce_delay_ms = 50;
  unsigned debounce_timeout;
  while (1) {
   select {
   // If the button is "stable", react when the I/O pin changes value
   case is_stable => p_button when pinsneq(current_val) :> current_val:
     if (current_val == 0x8) {
       c_ButtonVal<:0;
     } else {
       c_ButtonVal<:1;
     }
     is_stable = 0;
     int current_time;
     tmr :> current_time;
     // Calculate time to event after debounce period
     // note that XS1_TIMER_HZ is defined in timer.h
     debounce_timeout = current_time + (debounce_delay_ms * XS1_TIMER_HZ);
     break;

   // If the button is not stable (i.e. bouncing around) then select
   // when we the timer reaches the timeout to renter a stable period
   case !is_stable => tmr when timerafter(debounce_timeout) :> void:
     is_stable = 1;
     break;
   }
  }
}
if the Button is down, then send value 1 over streaming chanend c_ButtonVal else 0...
I use the following port:

Code: Select all

on tile[1]  :  port p_button = XS1_PORT_4B;
on XE216-512-TQ128-C20

Could you help me, why it doesn't change my audio-signal? I just want to mute the audio signal while pressing/hitting the button.

Thank you.


User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

Believe you are using the XMOS xCORE-200 Multichannel Audio Platform ? Hope so..

In reviewing the schematics of the xCORE-200 Multichannel Audio Platform hardware manual,

tile[1] is bonded to SWITCH_1 as 4B3 but so are

BUTTON_1 on 4B0
BUTTON_2 on 4B1
BUTTON_3 on 4B2.

Respectively, each of these buttons contain a pull-up resistor as shown in the hardware manual schematics. That is, if the push buttons are open, then the logic value of 1 is read for that bit weight else 0 if the respective button is pressed.

So you are dealing with:

(if no other button is pressed & SWITCH_1 is to ground position), a value of 0x07 should be read.

(if no other button is pressed & SWITCH_1 is to high position), a value of 0x0f should be read.

To check on only the position of SWITCH_1, please try with:

Code: Select all

if ((current_val&0x08) == 0x8) // to mask off the 4B3 bit only
User avatar
xaerox
Active Member
Posts: 43
Joined: Thu Apr 30, 2015 6:12 pm

Post by xaerox »

thank you mon2,
I currently use an own board with only on button connected. So we have an pull up resistor connected to the button. If we hit the button, the current will go to ground, which means we will recognize the value 0x0 on the button port. Otherwise w have a value larger 0x0.
The Button is connected to tile 1 to 4B0. All other 4B-pins are open, not connected (is it false?).
Does a logic 1 on 4B0 means the first binary "one" or the last one? I think, it`s this scheme:
Example: logic one on Port 4B0:

4B0 4B1 4B2 4B3
1 0 0 0

--> 0x8

Am I'm right?

thank you very much!
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

Hi.
Does a logic 1 on 4B0 means the first binary "one" or the last one?
Means, 4 bit wide port and you are working with Bit 0. So, this bit will be 0 or 2^0 = 1.


4B0 = 4 bit wide port and you are working with Bit 0 so can be 0 or 2^0 = 1.
4B1 = 4 bit wide port and you are working with Bit 1 so can be 0 or 2^1 = 2.
4B2 = 4 bit wide port and you are working with Bit 2 so can be 0 or 2^2 = 4.
4B3 = 4 bit wide port and you are working with Bit 3 so can be 0 or 2^3 = 8.

Try with:

Code: Select all

if ((current_val&0x01) == 0x1) // to mask off the 4B0 bit only