4 Replies Latest reply on Nov 16, 2015 3:31 AM by mop.mop

    Hard to use PrISM to control LED

    mop.mop

      I just want to change color on the RGB LED, I modify the PrISM example code.

         

      here is the CODE:

         

      void sleep(int s)
      {
          int x;
          while(x<s)
              x++;
      }

         

      int main()
      {

         

          /* Start PrISM */
          PrISM_1_Start();

         

          /* Enable Global Interrupts */
          CyGlobalIntEnable;
          
          /* No work has to be done in main loop */
          while(1u){
                  PrISM_1_WritePulse0(255);
                  PrISM_1_WritePulse1(0);
                  sleep(1);
                  PrISM_1_WritePulse0(255);
                  PrISM_1_WritePulse1(255);
                  sleep(1);
          }
          
      }

         

       

         

      but it only change two times, after that, it  is no longer to change

        • 1. Re: Hard to use PrISM to control LED
          mop.mop

          void sleep(int s)
          {
              int x=0;
              while(x<s*1000000)
                  x++;
          }

          • 2. Re: Hard to use PrISM to control LED
            user_1377889

            Welcome in the forum, Mop.

               

            /* No work has to be done in main loop */

               

            Take that comment literally! What you are doing is to change the PrISM parameters at a frequency which you cannot observe with the naked eye. Your first sleep() just needs less than 1µs to return. Better (easier, but more complex) would be to use a timer that changes every second your PrISM. To have something you can rely on use CyDelay(number of ms) description in "System Reference Guide"

               

            It is always easier for us when you post your complete project, so that we all can have a look at all of your settings. To do so, use
            Creator->File->Create Workspace Bundle (minimal)
            and attach the resulting file. And do not forget to mention which kit you actually use.

               

             

               

            Bob

            • 3. Re: Hard to use PrISM to control LED
              mop.mop

              SOLVED.

                 

              In FindMe Profile example code,I added two PrISM in schematic.

                 

              But I found that StackEventHandler() executed following on startup:

                 

                      case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:
                          /* Start BLE advertisement for 30 seconds and update link
                           * status on LEDs */
                          CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);

                 

                          PrISM_1_WritePulse0(RGB_LED_ON);
                          PrISM_1_WritePulse1(RGB_LED_OFF);
                          PrISM_2_WritePulse0(RGB_LED_OFF);
                          RED_SetDriveMode(RED_DM_DIG_HIZ);
                          GREEN_SetDriveMode(RED_DM_STRONG);
                          BLUE_SetDriveMode(RED_DM_DIG_HIZ);

                 

                          alertLevel = NO_ALERT;
                      break;

                 

              After this, the RGB LED will always turn on all the pulse density value (0), so that RGB LED is always WHITE!

                 

              And I can't to control it with new pulse density value, it seems blocks by something...

                 

              How could I to handle this? Thanks a lot!

              • 4. Re: Hard to use PrISM to control LED
                mop.mop

                OK, I upload my combined project, just let RGB LED control by IAS

                   

                The first problem was solved, I remove the Time ISR,so I just coding in while loop, please to check out the FindMe project,I use PSOC BLE kit

                   

                Thanks a lot!