昨天用仿真器做测试的时候,老是出现问题,开始怀疑是仿真器的问题,然后就想着直接用PROTEUS仿真来做,然后就安装了proteus,然后就这么整了一下午。
今天把线路又弄了一下,然后仔细进行仿真,才发现是变量的类型没有设置正确。
上面的图中,采样的频率从3M到3HZ均采样正确,程序调试通过。
#include "p24hj128gp506.h"
#include "delay.h"
#include "Generic.h"
#include "incap.h"
#include "ports.h"
#include "timer.h"
uint Interrupt_Count = 0, Int_flag;
ulong Freq=0;
uint Flower_count=0,a=0;
ulong time_period1,time_period2;
unsigned int timer_first_edge, timer_second_edge,timer_third_edge, timer_fourth_edge;
void __attribute__((interrupt,auto_psv)) _IC1Interrupt(void)
{
ReadCapture1(&timer_first_edge);
WriteTimer3(0X0000);
mPORTDClearBits(IOPORT_BIT_0);
time_period1=(50000*Interrupt_Count)+timer_first_edge;
Interrupt_Count=0;
IFS0bits.IC1IF = 0;
}
void IC_Init(void)
{
ConfigIntCapture1(IC_INT_PRIOR_1 & IC_INT_ON);
OpenTimer3(T3_ON & T3_GATE_OFF & T3_IDLE_STOP &
T3_PS_1_1 &T3_SOURCE_INT, 50000);
OpenCapture1(IC_IDLE_STOP & IC_TIMER3_SRC &
IC_INT_1CAPTURE & IC_EVERY_RISE_EDGE);
}
int main(void)
{
mPORTDOutputConfig(IOPORT_BIT_0);
mPORTDSetBits(IOPORT_BIT_0);
IC_Init();
osc_init();
Int_flag=0;
while(1)
{
mPORTDSetBits(IOPORT_BIT_0);
if(IFS0bits.T3IF==1)
{
Interrupt_Count++;
IFS0bits.T3IF=0;
}
Freq=40000000/time_period1;
}
CloseCapture1();
}
ulong fre;
int main(void)
{
mPORTDOutputConfig(IOPORT_BIT_0);
mPORTDSetBits(IOPORT_BIT_0);
osc_init();
IC_Init();
while(1)
{
mPORTDSetBits(IOPORT_BIT_0);
fre=Freqent_ReadIC1();
// CloseCapture1();
// CloseTimer3();
// delay04ms();
//
// delay05ms();
}
}
文章评论(0条评论)
登录后参与讨论