本帖最后由 any_014 于 2015-4-7 15:38 编辑
本来是个双积分AD测量,对基准电压积分固定时间后,转为对被测电压反向积分,运放产生的中断触发PCA中断,然后就是下个周期,周而复始。
想用PCA测量对被测电压的反向积分时间,发现能进了中断(有LED灯亮/灭),但串口发上来的数始终为0。PCA相关代码已贴上,附件工程文件。
PCA相关部分:
void PCAInit()
{
CCON = 0; //Initial PCA control register
//PCA timer stop running
//Clear CF flag
//Clear all module interrupt flag
CL = 0; //Reset PCA base timer
CH = 0;
CMOD = 0x00; //Set PCA timer clock source as Fosc/12
CCAPM0 = 0x11; //PCA module-0 capture by a negative tigger on CEX0(P3.7) and enable PCA interrupt
// CCAPM0 = 0x21; //PCA module-0 capture by a rising edge on CEX0(P3.7) and enable PCA interrupt
// CCAPM0 = 0x31; //PCA module-0 capture by a transition (falling/rising edge) on CEX0(P3.7) and enable PCA interrupt
// value = T4KHz; //Disable PCA timer overflow interrupt
// CCAP1L = value; //P3.5 output 4KHz square wave
// CCAP1H = value >> 8; //Initial PCA module-0
// value += T4KHz;
// CCAPM1 = 0x4d; //PCA module-1 work in 16-bit timer mode and enable PCA interrupt, toggle the output pin CEX1(P3.5)
CR = 1; //PCA timer start run
EPCAI = 1;
}
void PCA_isr() interrupt 6 using 1
{
EPCAI = 0;
if(CCF0 == 1)
{
CCF0 = 0;
PCAFlag = 1;
temp1 = CCAP0H;
temp2 = CCAP0L;
RUNLED = !RUNLED; //work LED flash
}
// if(CCF1 ==1)
// {
// CCF1 = 0;
// CCAP1L = value;
// CCAP1H = value >> 8;
// value += T4KHz;
// }
EPCAI = 1;
}
主函数部分:
void main(void)
{
init();
Delay20ms();
while(1)
{
if(PCAFlag == 1)
{
P1 &= 0xf0; //Çл»µ½»ù×¼µçѹͨµÀ
P1 |= 0x02;
TimerFlag = 1;
TR0 = 1; //Timer0 start run ¶¨Ê±Æ÷T0ÖжÏÑÓʱ20ms
while(TimerFlag);
CH = 0; //PCA¼ÆÊýÆ÷ÇåÁã
CL = 0;
P1 &= 0xf0; //Çл»µ½±»²âͨµÀ
P1 |= 0x07;
PCAFlag = 0;
temp_value1 = temp1;
temp_value1 = temp_value2<<8;
temp_value1 |= temp1;
temp_long_value = temp_long_value * 0x6b;
temp_long_value = temp_long_value / 0x4800;
temp2 = temp_long_value;
temp1 = temp_long_value>>8;
// SendDate(temp_value);
SendData(temp1); //·¢ËͲ¶»ñʱ¼äµÍλ
SendData(temp2); //·¢ËͲ¶»ñʱ¼ä¸ßλ
}
}
}
2PT_0_3.zip
(64.19 KB)
---------------------------------------------------------------------------------------------------------------
自己糊涂,PCA计数是没问题的,是我数据处理的问题。
|