nick703
Advanced Member level 1
Hello,
Actually my application is i want to measure RPM and this RPM to flashing LED to generate freeze motion using PIC18F4550 and XC compiler. So after searching many artical and doing some code and below is the problem.
1) measure RPM is a half of Actual RPM.
means if i measure using instrument that time i can see 1800 RPM but in LCD i got 900 RPM.
2) And Second Problem is i didn't Freeze my motion using RPM .
My calculation is RPM = FPM (Frequency Per Minute).
So i have Genrate Delay using this RPM is that wrong?
Please help me to resolve the issue. below is my code
please give me Some advise i want to correct RPM and that RPM to flashing LED to freeze motion.
Actually my application is i want to measure RPM and this RPM to flashing LED to generate freeze motion using PIC18F4550 and XC compiler. So after searching many artical and doing some code and below is the problem.
1) measure RPM is a half of Actual RPM.
means if i measure using instrument that time i can see 1800 RPM but in LCD i got 900 RPM.
2) And Second Problem is i didn't Freeze my motion using RPM .
My calculation is RPM = FPM (Frequency Per Minute).
So i have Genrate Delay using this RPM is that wrong?
Please help me to resolve the issue. below is my code
Code:
#include "Configuration_Header_File.h"
#include "LCD_8bit_file.h"
#pragma config PLLDIV = 1 // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 1 // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
// CONFIG1H
#pragma config FOSC = INTOSC_EC // Oscillator Selection bits (Internal oscillator, CLKO function on RA6, EC used by USB (INTCKO))
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
void Timer1_start();
void Timer0_config();
#define StrobePulse LATDbits.LATD2
#define MeasurePin LATAbits.LATA4
#define _XTAL_FREQ 4000000
char message1[] = "Tachometer";
unsigned long int count = 0;
unsigned long RPM_Value;
void main()
{
OSCCON=0x72; /* Configure oscillator frequency to 8MHz */
TRISB = 0; /* Set as output Port */
TRISA= 0x10;
Pulse = 1; /* send high on PortB */
LCD_Init();
Timer0_config();
Timer1_start();
LCD_Command(0xC0);
LCD_String_xy(1,4,message1);
while(1)
{
TMR0ON = 1;
TMR0L = 0;
TMR0H = 0;
MeasurePin = 1;
__delay_ms(1000);
MeasurePin = 0;
TMR0ON = 0; // Stop the timer
RPM_Value = TMR0 * 60;
Display_RPM(RPM_Value);
};
}
/*********************Interrupt Service Routine for Timer1************************/
void interrupt Timer1_ISR()
{
if(PIR1bits.TMR1IF)
{
TMR1 = RPM_Value / 60;
StrobePulse= ~StrobePulse;
PIR1bits.TMR1IF=0; /* Make Timer1 Overflow Flag to '0' */
}
}
void Timer1_start()
{
GIE=1; /* Enable Global Interrupt */
PEIE=1; /* Enable Peripheral Interrupt */
TMR1IE=1; /* Enable Timer1 Overflow Interrupt */
TMR1IF=0;
T1CON=0x80; /* Enable 16-bit TMR1 Register,No pre-scale,use internal clock,Timer OFF */
//TMR1=0xF830; /* Load Count for generating delay of 1ms */
TMR1=0xF97D; /* Load Count for generating delay of 1us */
//TMR1=0xFF38; /* Load Count for generating delay of 1us */
TMR1ON=1; /* Turn-On Timer1 */
}
void Timer0_config()
{
T0CON = 0b00101000;
}
void Display_RPM(unsigned int num)
{
char TempA = 0, TempB = 0, TempC = 0, TempD = 0, TempE = 0, TempF = 0;
unsigned int Temp = num;
char MessageFrame[8];
TempA = Temp / 100000;
Temp = Temp % 100000;
TempB = Temp / 10000;
Temp = Temp % 10000;
TempC = Temp / 1000;
Temp = Temp % 1000;
TempD = Temp / 100;
Temp = Temp % 100;
TempE = Temp / 10;
TempF = Temp % 10;
MessageFrame[0] = TempA + 0x30;
MessageFrame[1] = TempB + 0x30;
MessageFrame[2] = TempC + 0x30;
MessageFrame[3] = TempD + 0x30;
MessageFrame[4] = TempE + 0x30;
MessageFrame[5] = TempF + 0x30;
LCD_String_xy(2,4,MessageFrame);
}
please give me Some advise i want to correct RPM and that RPM to flashing LED to freeze motion.