This example shows how to perform the LED Dimming using the PrISM module for the Cypress PSoC 4 Pioneer kit.
Here is the Application Schematics:
This example uses the PrISM module as the sole control of the LED output as well as the interrupt source to update the LED intensity(called Density in the program + PrISM API).
The internal timeout of the PrISM module is used to activate the ISR for the LED intensity update.
The PrISM module { PrISM [v2.20] } Settings are as follows:
In the code the LED intensity (Density factor) is stored and incremented to reach a specified high value. Then the operation flag is change and decrement is performed till it reaches near low value.
This cycle continues to give the breathing led effect like in the previous example.
Here is the code for this example:
#include <project.h> uint8 val = 0; // Used as a counter to store the LED Density value uint8 dir = 0; // Used as a flag to determine increment-1 or decrement-0 operation CY_ISR(Dimmer) { if((val == 0x00u) || (val == 0xFFu)) //Check for Maximum or Minimum value { dir ^= 1; // Perform a Flag operation Flip using XOR //- First time Increment will be automatically set as value of counter is 0 } if(dir&1) //Increment if the Direction is 1 { val++; } else // Decrement if the Direction is 1 { val--; } // Apply the calculated LED intensity value as a PrISM duty cycle value. PrISM_1_WritePulse0(val); } int main() { // Configure PrISM module PrISM_1_Start(); // Enable the ISR on PrISM overflow to perform the Dimming isr_Mod_StartEx(Dimmer); // Enable Interrupts CyGlobalIntEnable; while(1) ; }
After Building and loading this code the Green Color in the RGB LED would show the breathing effect.
This time one can clearly notice the smoothness in the effect rather than the PWM based approach.