#include <m8c.h> // Part-specific constants and macros
#include “PSoCAPI.h” // PSoC API definitions for all user modules
#include “psocdynamic.h”
char counter_msg1[] = “Counter Mode”;
char pwm_msg1[] = “PWM Mode”;
char analog_msg1[] = “Analog Mode”;
void main()
{
int counter_data,analog_counter_data,pwm_counter_data;
char x,y;
while(1)
{
M8C_EnableGInt;
******************************************************************
// PWM LED driver module dawg
******************************************************************
PWM_PGA_SetGain(PWM_PGA_G1_00);
PWM_PGA_Start(PWM_PGA_HIGHPOWER);
LCD_Init();
LCD_Start();
LCD_Position(0,1);
LCD_PrString(pwm_msg1);
PWM_GREEN_WritePeriod(255);
PWM_GREEN_WritePulseWidth(128);
PWM_RED_WritePeriod(255);
PWM_RED_WritePulseWidth(10);
PWM_GREEN_Start();
PWM_RED_Start();
PWM_ADC_Start(PWM_ADC_HIGHPOWER);
PWM_ADC_GetSamples(0);
do{
while(PWM_ADC_fIsDataAvailable() == 0);
PWM_ADC_ClearFlag();
pwm_counter_data=PWM_ADC_iGetData();
PWM_RED_WritePulseWidth(pwm_counter_data & 0x00FF);
PWM_GREEN_WritePulseWidth(pwm_counter_data & 0x00FF /2);
}while(pwm_counter_data < 0);
UnloadConfig_dawg();
******************************************************************
// Counter-driven LED driver module counter
******************************************************************
LoadConfig_counter();
LCD_Init();
LCD_Start();
LCD_Position(0,1);
LCD_PrString(counter_msg1);
Counter_Grn_WritePeriod(65535);
Counter_Grn_WriteCompareValue(32768);
Counter_Red_WritePeriod(65535);
Counter_Red_WriteCompareValue(16384);
Counter_Grn_Start();
Counter_Red_Start();
counter_data = 0x7FF;
y = 0xFF;
do{
for(x=0;x<0xFF;++x)
—y;
—counter_data;
}while(counter_data);
UnloadConfig_counter();
***************************************************
// 16-bit Counter LED driver module analog
***************************************************
LoadConfig_analog();
PGA_Analog_SetGain(PGA_Analog_G1_00);
PGA_Analog_Start(PGA_Analog_HIGHPOWER);
LCD_Init();
LCD_Start();
LCD_Position(0,1);
LCD_PrString(analog_msg1);
Counter_Analog_WritePeriod(65535);
Counter_Analog_Start();
Counter2_Analog_WritePeriod(65535);
Counter2_Analog_Start();
ADC_Analog_Start(ADC_Analog_HIGHPOWER);
ADC_Analog_GetSamples(0);
do{
while(ADC_Analog_fIsDataAvailable() == 0);
ADC_Analog_ClearFlag();
analog_counter_data=ADC_Analog_iGetData();
Counter_Analog_WriteCompareValue(analog_counter_data);
Counter2_Analog_WriteCompareValue(analog_counter_data / 2);
}while(analog_counter_data > 0);
UnloadConfig_analog();
LoadConfig_dawg();
}
Listing 1—All of the function
prototypes are generated after you place your user modules and begin the build
process. To use PSoC dynamic reconfiguration, all you have to do is lay down your
placements in separate modules and write the code to load and unload your configurations.
In my opinion, the dynamic reconfiguration feature is the PSoC’s strongest point.