Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Algorithm Implementation

Status
Not open for further replies.

nayakajit87

Member level 5
Member level 5
Joined
Aug 13, 2018
Messages
84
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
1,065
Dear all

I am looking for simple algorithm input.i cant post whole code. i pasted some part of it

i am using PISO to get input from 74hc165D ic. here i am trying to read data from DIP switch. Fault_Array[0] uses to read 8 position DIP switches
Code:
void PISO_INPUT(void) {
 unsigned char i;
 unsigned char j, k;
 unsigned char value;

 byteValue = 0; // accumulates image of 8 switches
 bitValue = 0;

 PISO_PL_EN = 0; // latch data


 PISO_PL_EN = 1; //ADD


 for (i = 0; i <16; i++) { //TBC // 8 bits

  bitValue = PISO_FAULT;
  byteValue |= (bitValue << (16- 1) - i));

  PISO_CLK = 1;
 

  PISO_CLK = 0;
 

 }

 FAULT_PISO = byteValue;

 Fault_Array[0] = (unsigned char)(FAULT_PISO & 0xff);
 

}

Now i am trying to read above input and identifying which is latest input. IN this code assume i have 4 input F1,F2,F3,F4 where F4 is latest f3 is 3rd and f1 is first. as per below code F4 will be flashing and remaining F1,F2,F3,will be steady. i m expecting First input F1 flash first later should be steady

similarly if order F2 is first, F3,f1,F4 i/p F2 is first i/p it should be flashing and remaining should be steady.

here i am checking which input is latest input. Below i have checked its working for LIFO latest in first out operation. but i need reverse first input detect should be flashing remaining should be steady. i need to change CHK_WINDOW() s

Code:
void CHK_WINDOW() {

 for (w = 0; w <= 8; w++) {
  switch (w) {

   case 1:
    if (((Fault_Array[0] & 0x01) == 0x01) != intype.INF25) {
     Debounce25++;
     if (Debounce25 >9) {
      if (((Fault_Array[0] & 0x01) == 0x01) != intype.INF25) {
       if ((WINDOW[0] & 0x01) == 0x00) {
        WINDOW[0] |= 0x01;
        PREVIOUS_FLT1 = PREVIOUS_FLT;
        PREVIOUS_FLT = LATEST_FLT;
        LATEST_FLT = 0x19;
        Debounce25 = 0;
       }
      }
     }

    } else
     Debounce25 = 0;
    break;

   case 2:
    if (((Fault_Array[0] & 0x02) == 0x02) != intype.INF26) {
     Debounce26++;
     if (Debounce26 >9) {
      if (((Fault_Array[0] & 0x02) == 0x02) != intype.INF26) {
       if ((WINDOW[0] & 0x02) == 0x00) {
        WINDOW[0] |= 0x02;


        PREVIOUS_FLT1 = PREVIOUS_FLT;
        PREVIOUS_FLT = LATEST_FLT;
        LATEST_FLT = 0x1A;
        Debounce26 = 0;
       }
      }
     }
    } else
     Debounce26 = 0;
    break;

   case 3:
    if (((Fault_Array[0] & 0x04) == 0x04) != intype.INF27) {
     Debounce27++;
     if (Debounce27 >9) {
      if (((Fault_Array[0] & 0x04) == 0x04) != intype.INF27) {
       if ((WINDOW[0] & 0x04) == 0x00) {
        WINDOW[0] |= 0x04;

        PREVIOUS_FLT1 = PREVIOUS_FLT;
        PREVIOUS_FLT = LATEST_FLT;
        LATEST_FLT = 0x1B;
        Debounce27 = 0;
       }

      }
     }
    } else
     Debounce27 = 0;
    break;

   case 4:
    if (((Fault_Array[0] & 0x08) == 0x08) != intype.INF28) {
     Debounce28++;
     if (Debounce28 >9) {
      if (((Fault_Array[0] & 0x08) == 0x08) != intype.INF28) {
       if ((WINDOW[0] & 0x08) == 0x00) {
        WINDOW[0] |= 0x08;

        PREVIOUS_FLT1 = PREVIOUS_FLT;
        PREVIOUS_FLT = LATEST_FLT;
        LATEST_FLT = 0x1C;
        Debounce28 = 0;
       }
      }
     }
    } else
     Debounce28 = 0;
    break;

default:
    break;

  }

 }

}
using i am trying to flash output
Code:
void FLASH_LED(void) {

  unsigned char Z;

  for (Z = 0; Z <= 8; Z++)

    switch (Z) {

    case 1:
      if (((ACKPRESS[0] & 0x01) == 0x00) && ((WINDOW[0] & 0x01) == 0x01)) {

        if (LATEST_FLT == 0X19)

        {

          if (bits.BLINKFLAG1 == 0)
            WINDOW_PATTERN &= 0x7FFFFFFF;
          else if (bits.BLINKFLAG1 == 1)
            WINDOW_PATTERN |= 0x80000000;
        } else if (PREVIOUS_FLT == 0X19) {
          if (bits.BLINKFLAG2 == 0)
            WINDOW_PATTERN &= 0x7FFFFFFF;
          else if (bits.BLINKFLAG2 == 1)
            WINDOW_PATTERN |= 0x80000000;

        } else if (PREVIOUS_FLT1 == 0X19) {
          WINDOW_PATTERN &= 0x7FFFFFFF;
          F25_Flag = 1;
        } else if (F25_Flag == 1)
          WINDOW_PATTERN &= 0x7FFFFFFF;

        else if ((WINDOW[0] & 0x01) == 0x01) {
          WINDOW_PATTERN &= 0x7FFFFFFF;
        }

      }

      break;

    case 2:
      if (((ACKPRESS[0] & 0x02) == 0x00) && ((WINDOW[0] & 0x02) == 0x02)) {

        if (LATEST_FLT == 0X1A)

        {
          if (bits.BLINKFLAG1 == 0)
            WINDOW_PATTERN &= 0xBFFFFFFF;
          else if (bits.BLINKFLAG1 == 1)
            WINDOW_PATTERN |= 0x40000000;
        } else if (PREVIOUS_FLT == 0X1A) {
          if (bits.BLINKFLAG2 == 0)
            WINDOW_PATTERN &= 0xBFFFFFFF;
          else if (bits.BLINKFLAG2 == 1)
            WINDOW_PATTERN |= 0x40000000;

        } else if (PREVIOUS_FLT1 == 0X1A) {
          WINDOW_PATTERN &= 0xBFFFFFFF;
          F26_Flag = 1;
        } else if (F26_Flag == 1)
          WINDOW_PATTERN &= 0xBFFFFFFF;

      }

      break;
    case 3:
      if (((ACKPRESS[0] & 0x04) == 0x00) && ((WINDOW[0] & 0x04) == 0x04)) {

        if (LATEST_FLT == 0X1B)

        {
          if (bits.BLINKFLAG1 == 0)
            WINDOW_PATTERN &= 0xDFFFFFFF;
          else if (bits.BLINKFLAG1 == 1)
            WINDOW_PATTERN |= 0x20000000;
        } else if (PREVIOUS_FLT == 0X1B) {
          if (bits.BLINKFLAG2 == 0)
            WINDOW_PATTERN &= 0xDFFFFFFF;
          else if (bits.BLINKFLAG2 == 1)
            WINDOW_PATTERN |= 0x20000000;

        } else if (PREVIOUS_FLT1 == 0X1B) {
          WINDOW_PATTERN &= 0xDFFFFFFF;
          F27_Flag = 1;
        } else if (F27_Flag == 1)
          WINDOW_PATTERN &= 0xDFFFFFFF;

        else if ((WINDOW[0] & 0x04) == 0x04) {

          WINDOW_PATTERN &= 0xDFFFFFFF;

        }

      }

      break;

    case 4:
      if (((ACKPRESS[0] & 0x08) == 0x00) && ((WINDOW[0] & 0x08) == 0x08)) {

        if (LATEST_FLT == 0X1C)

        {
          if (bits.BLINKFLAG1 == 0)
            WINDOW_PATTERN &= 0xEFFFFFFF;
          else if (bits.BLINKFLAG1 == 1)
            WINDOW_PATTERN |= 0X10000000;
        } else if (PREVIOUS_FLT == 0X1C) {
          if (bits.BLINKFLAG2 == 0)
            WINDOW_PATTERN &= 0xEFFFFFFF;
          else if (bits.BLINKFLAG2 == 1)
            WINDOW_PATTERN |= 0X10000000;

        } else if (PREVIOUS_FLT1 == 0X1C) {
          WINDOW_PATTERN &= 0xEFFFFFFF;
          F28_Flag = 1;
        } else if (F28_Flag == 1)
          WINDOW_PATTERN &= 0xEFFFFFFF;

        else if ((WINDOW[0] & 0x08) == 0x08) {

          WINDOW_PATTERN &= 0xEFFFFFFF;

        }

      }

    default:
      break;

    }

}
 

You sent us three fragments of mystery code with only one comment between them.

We don't stand a chance of working out what is wrong if we don't even know what the variables are for.

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top