Hai,
Now i writing one program for data acquisition using PIC18F57K42 uc and the hardware tool as Pickit3. The inputs are analog input and pulse. So I am using ADC module for analog meaurement and CCP-capture module for pulse width measurement. The conversion are taken out from UART. I am using three interrupt i.e timer3(regular time interval) and timer1&CCP1(pulse measurement).
The analog inputs are read at regular intervals using one of the timer interrupt for regular interval measurement and otherwise the pulse width is measured. I did the measurement separately, it is okay.
When i integrate both, i got some bugs. The bugs are (1) When i flash the program to the controller, at the same time, the pulse is fed at controller CCP capture input pin mean i got conversion at the UART otherwise sometimes i didn't get the ouput. (2) In this manner, suppose i switch OFF the pulse input, after i didn't get UART output. (3) Then I switch OFF the system, after switch ON system i didn't get anything from UART.
The code as
PIR4bits.CCP1IF = 0;
PIE4bits.CCP1IE = 1;
PIR4bits.TMR1IF = 0;
PIE4bits.TMR1IE = 1;
PIR6bits.TMR3IF = 0;
PIE6bits.TMR3IE = 1;
INTCON0bits.GIEH = 1;
INTCON0bits.GIEL = 1;
INTCON0bits.IPEN = 1;
while (1)
{
if(flag == true)
{
ADCC_GetSingleConversion(channel_AND4);
ADCC_GetConversionResult();
converted_value = ADCC_GetConversionResult();
actual_res = (float) converted_value *((float) VRef/(float) ADC_Resolution) ;
FPM = actual_res;
UART1_string("Forward Power Monitor (FPM) Value is : "); UART1_Write('\n');
UART_RES(FPM); UART1_Write('\n');
ADCC_GetSingleConversion(channel_AND5);
ADCC_GetConversionResult();
converted_value = ADCC_GetConversionResult();
actual_res = (float) converted_value *((float) VRef/(float) ADC_Resolution) ;
RPM = actual_res;
UART1_string("Reverse Power Monitor (RPM) Value is : "); UART1_Write('\n');
UART_RES(RPM); UART1_Write('\n');
flag = false;
}
if(cap == true)
{
ED = edge2 - edge1;
signal_period = (float) Timer_Freq/ (float) ED;
time = signal_period;
UART1_string("Frequency is : ");
UART1_Write('\n');
UART_RES(signal_period);
UART1_Write('\n');
cap = false;
}
}
}
void __interrupt() INTERRUPT_InterruptManager (void)
{
if(PIE6bits.TMR3IE == 1 && PIR6bits.TMR3IF == 1)
{
TMR3L = 0x06;
TMR3H = 0xFF;
count++;
if(count == 10000)
{
flag = true;
count = 0;
Pulse = ~Pulse ;
}
PIR6bits.TMR3IF = 0;
}
if(PIE4bits.CCP1IE == 1 && PIR4bits.CCP1IF == 1)
{
PIR4bits.CCP1IF = 0;
edge1 = (CCPR1H<<8) | (CCPR1L & 0xFF);
while(!(PIR4bits.CCP1IF));
edge2 = (CCPR1H<<8) | (CCPR1L & 0xFF);
TMR1H = 0x00;
TMR1L = 0x00;
if(edge1<edge2)
{
cap = true;
}
PIR4bits.CCP1IF = 0;
}
}
Please let me know which possibility make a wrong...!
Advance in thanks