我撰写的一份程式,需要持续输出PWM讯号且不能中断并且开启动态重配置功能读取ADC功能
在基本配置放置两个PWM输出,另外开了一个配置放置ADC
但在PWM输出会有问题,切换模块的时候PWM会停止大概2ms
请问各位高人如何解决这个问题
附上以下程式:
//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include "PSoCDynamic.h"
#pragma interrupt_handler PSoC_GPIO_ISR
void swichset (void) ;
WORD PWMADCData (void) ;
BYTE SET1,s1,WD;
int i,time1,t1;
long WD1,WD2,WD3,WD4,ADdata;
WORD PWMData;
void main(void)
{
time1=0;
PRT0IC0 |= 0x10;
PRT0IC1 |= 0x10;
PRT0IE |= 0x10;
s1=0;
M8C_EnableGInt; // Enable Global Interrupt
M8C_EnableIntMask(INT_MSK0, INT_MSK0_GPIO);
PWM8_1_WritePeriod(255);
PWM8_2_WritePeriod(255);
while(1)
{time1++;
swichset();
if(time1>=5000)
{
PWMData=(BYTE)PWMADCData ();
time1=0;
}
WD2=PWMData*320;
if(WD3<=WD2)
{
WD3=WD3+1;
WD4=WD3/320;
PWM8_2_WritePulseWidth(WD4);
}
else
{
WD3=WD3-1;
WD4=WD3/320;
PWM8_2_WritePulseWidth(WD4);
}
}
}
/* *************************************************************************************************************** */
WORD PWMADCData (void)
{ int PWMData1,data1;
BYTE data;
LoadConfig_DAC();
// perform sample only if the conguration is loaded properly
if (IsDACLoaded() )
{
PGA_1_Start(PGA_1_MEDPOWER);
ADCINC_1_Start(ADCINC_1_HIGHPOWER); // Apply power to the SC Block
ADCINC_1_GetSamples(0); // Have ADC run continuously
while(ADCINC_1_fIsDataAvailable() == 0); // Loop until value ready
ADCINC_1_iClearFlagGetData(); // Clear ADC flag and get data
PWMData1=ADCINC_1_iGetData()+2048;
if(PWMData1>=16)
{
data1=PWMData1/16;
}
if(data1>=15)
{
data1=data1;
}
else
{
data1=0;
}
ADCINC_1_Stop();
}
UnloadConfig_DAC();
return (data1) ;
}
/* *************************************************************************************************************** */
void swichset (void)
{
if(PRT0DR & 0x80)
{
while(PRT0DR & 0x80)
{
t1=t1+1;
}
}
if(t1>2000)
{
WD=51;
PWM8_1_WritePulseWidth(WD);
PWM8_1_Start();
PWM8_2_WritePulseWidth(0);
PWM8_2_Start();
t1=0;
}
else
{
t1=0;
}
if(PRT0DR & 0x20)
{
while(PRT0DR & 0x20)
{
t1=t1+1;
}
}
if(t1>2000)
{PWM8_1_WritePulseWidth(0);
PWM8_2_WritePulseWidth(0);
PWM8_1_Stop();
PWM8_2_Stop();
t1=0;
}
else
{t1=0;}
if(PRT1DR & 0x02)
{
while(PRT1DR & 0x02)
{
t1=t1+1;
}
}
if(t1>2000)
{ t1=0;
if(WD<=40)
{WD=40;
PWM8_1_WritePulseWidth(WD);}
else
{
WD=WD-5;
PWM8_1_WritePulseWidth(WD);
}
}
else
{t1=0;}
if(PRT0DR & 0x08)
{
while(PRT0DR & 0x08) {
t1=t1+1;
}
}
if(t1>2000)
{t1=0;
if(WD>=200)
{
WD=200;
PWM8_1_WritePulseWidth(WD);}
else
{
WD=WD+5;
PWM8_1_WritePulseWidth(WD);
}
}
else
{t1=0;}
} |