Thanks for your continuous support.
okay its working now. the scope I was using to measure frequency was defective,and the multimeter was also unable to show as it was over range.
#define STEPWAVE PORTAbits.RA7
// #define STEPWAVE LATAbits.LATA7
void FrequencyScan(void)
{
//if (previous_option!=current_option)//first entry to this routine
TRISA=(TRISA&0b1111111101111111);
T4CON=0x00; // Stop any 16/32-bit Timer4 operation
T5CON=0x00;
TMR5=0x00; // Clear contents of the TMR4 and TMR5
TMR4=0x00;
PR5=preiod-65536;
PR4=preiod;
IPC7bits.T5IP2=TRUE;
T4CONbits.T32=TRUE; //enable 32 bit mode
IFS1bits.T5IF = 0; // Clear Timer 5 Interrupt Flag
IEC1bits.T5IE=TRUE; // Enable Timer5 interrupt
T4CONbits.TON=TRUE; // Start Timer
if(preiod<=125000 && preiod>20000)
{
preiod=preiod-preiod*.1;
}
else if(preiod<=20000 && preiod>10)
{
preiod=preiod-preiod*0.05;
}
/* else
{
if(c<=10000.99)
{
preiod=preiod-1;
}
else{}
}
*/
f=(1/(preiod*0.000000125));
c=f/64;
//DELAY();
if(c<10000.00)
{
DispL1(13);
Put_String_LCD("Running");
DispL2(0);
sprintf(LCDBuf,"F=%.2f ",c);
Put_String_LCD(LCDBuf);
}
else
{
DispL1(0);
Put_String_LCD(" Done ");
DispL2(0);
Put_String_LCD("F=640000 ");
LongDelay(8);
mainstate = OPENING_SCREEN;
}
}
void __attribute__((__interrupt__, auto_psv)) _T5Interrupt( void )
{
if (IFS1bits.T5IF)
{
// Clear the interrupt flag
IFS1bits.T5IF = 0;
OverflowFlag = TRUE;
Error3 = TRUE;
SyncFlag = 0;
STEPWAVE=STEPFLG;
STEPFLG=!STEPFLG;
if (KEY_PRESSED == S2)
{
KEY_PRESSED=0;
mainstate = OPENING_SCREEN;
return;
}
KEY_PRESSED=0;
}
}
Users browsing this forum: No registered users and 1 guest