Question

In: Electrical Engineering

With a PSoC4 in PSoC creator: Using 2 external buttons b0 and b1 to represent ‘0’...

With a PSoC4 in PSoC creator:

Using 2 external buttons b0 and b1 to represent ‘0’ and ‘1’, design a sequence detector using C code in PSoC Creator to detect a pattern “1101”. The board LED lights up once, when the sequence “1101” occurs. Use a serial terminal (UART component and serial terminal emulator application) to display the sequence entered. Use the board button for the sequence detector reset.

Solutions

Expert Solution


// A flag variable is used to verify the sequence is correct. flag is incremented at each correct input.
int flag = 0;

int check(int x,int y)
{
switch(flag)
{
    case 0 : {
              if(y==1 && x==1) //evaluates true when b1 is pressed
              {
                flag =1;        // 1 detected
              }
              else flag = 0;
              break;
    }
    case 1 : {
              if(y==1 && x==1) //evaluates true when b1 is pressed
              {
                flag = 2;       // 1 detected
              }
              else flag = 0;    // 0 detected
              break;
    }
    case 2 : {
               if(y==0 && x==0) //evaluates true when b0 is pressed
               {
                flag = 3;       // 0 detected
               }
               else if(y==1 && x==1) //evaluates true when b1 is pressed
               {
                flag = 2;       // 1 detected, Now sequence is '111....' Hence flag =2;
               }
               else ;
               break;
    }
    case 3 : {
              if(y==1 && x==1) //evaluates true when b1 is pressed
              {
                flag = 4;       // 1 detected
              }
              if(y==0 && x==0) //evaluates true when b0 is pressed
              {
                flag = 0;       // 0 detected
              }
              break;
    }
}
if(flag==4)
{
digitalWrite(3,HIGH);         // LED set to high
delay(2000);
digitalWrite(3,LOW);         // LED set to low
flag=2;                       //'1101' detected. If las one has to be taken as 1st input of following sequnece keep it. Else if you want to start fresh, change value of flag to 0.
}

return 0;
}


void setup() {

//let the inputs be connected at pin 0,1
//note that PIN0 represents b0 which signifies '0' and hence should be pulled up using a resistor to +5V. This is necessary to identify a change from high level(5V) to low level(0).
//note that PIN1 represents b1 which signifies '1' and hence should be pulled down using a resistor to ground. This is necessary to identify a change from low level(0V) to high level(5V).
pinMode(0,INPUT);
pinMode(1,INPUT);

//let the LED be connected to pin 3
pinMode(3,OUTPUT);

}

void loop() {
//receive inputs and check whether the sequence is 1101

int x = digitalRead(0); //evaluates 0 when b0 is pressed and 1 when not pressed
delay(500);              // avoid debouncing
int y = digitalRead(1); //evaluates 1 when b1 is pressed and 0 when not pressed
delay(500);              // avoid debouncing

check(x,y);
}


Related Solutions

With an Arduino Uno: Using 2 external buttons b0 and b1 to represent ‘0’ and ‘1’,...
With an Arduino Uno: Using 2 external buttons b0 and b1 to represent ‘0’ and ‘1’, design a sequence detector to detect a pattern “1101”. An LED lights up once, when the sequence “1101” occurs.
Find b0, b1, and b2  to fit the second degree parabola =b0+b1 x+b2 x2 for the following...
Find b0, b1, and b2  to fit the second degree parabola =b0+b1 x+b2 x2 for the following data: x 1 2 3 4 y 1.7 1.8 2.3 3.2 b0 = -2, b1=-0.5, b2 = -0.2 b0 =2, b1= -0.5, b2 = 0.2 b0 =2, b1=0.5, b2 =0.2    b0 =2, b1=0.5, b2 = -0.2   
Solve the recurrence relation with the given initial conditions. b0 = 0, b1 = 4, bn...
Solve the recurrence relation with the given initial conditions. b0 = 0, b1 = 4, bn = 2bn ? 1 + 2bn ? 2 for n ? 2
iii Show that any finite Lattice L has a b0 and b1, where t ≥ b0,...
iii Show that any finite Lattice L has a b0 and b1, where t ≥ b0, t ≤ b1, for all t ∈ L.
What are the purposes and properties (magnitude, frequency, duration, and direction) of B0 and B1 in...
What are the purposes and properties (magnitude, frequency, duration, and direction) of B0 and B1 in MRI?
Demand function for Greek yogurt is assumed to be: QGY = B0 + B1 * PGY...
Demand function for Greek yogurt is assumed to be: QGY = B0 + B1 * PGY + B2 * PNGY + E QGY : demand quantity of Greek yogurt. PGY: price of Greek yogurt. PNGY: price of Non-Greek yogurt. (1) What signs do you expect on B1 and B2? Why B0, B1, B2 are estimated as follows: ^B0 = −20.05 with standard error se^B0 = 36.97. ^B1 = −19.50 with standard error se^B1 = 1.35. ^B2 = 7.56 with standard...
Show that OLS estimators of b0 and b1 are efficient? please answer is not be too...
Show that OLS estimators of b0 and b1 are efficient? please answer is not be too long or short
A. Assume b0 = 12.953, and b1 = -2.5. For x = 25, predict y. Round...
A. Assume b0 = 12.953, and b1 = -2.5. For x = 25, predict y. Round to 3 digits. B. if x is increased by 10 units, how much does y-hat change? Round to 3 digits. Use the points to answer the following: x y 12 17 21 15 28 22 8 19 20 24 C. How much correlation is there between x and y? Round to four decimals and use leading zeros if necessary. D. How much of the...
6) (a) Denote the successive intervals that arise in the bisection method by [a0,b0, [a1,b1] ,...
6) (a) Denote the successive intervals that arise in the bisection method by [a0,b0, [a1,b1] , [a2,b2], and so on    Show that   bn – an = 2-n(b0-a0) (b) The bisection method is said to have a linear convergence. Explain as clearly as possible what that means c) For the bisection method, prove that |cn – cn+1| = 2-n-2 (b0 – a0)    where cn is the midpoint of each interval (ie) cn = (an + bn) /2
How do you Interpret the meaning of the different coefficients (b0, b1, b2, b3,b4,…bn) in a...
How do you Interpret the meaning of the different coefficients (b0, b1, b2, b3,b4,…bn) in a multiple regression? (slightly different from the interpretation in simple regression)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT