PDA

Ver la Versión Completa : Duda con frecuencimetro y contador de revoluciones con Mikropascal


Mikro-77
14-01-2013, 02:04:59
Hola tengo un codigo escrito en Mikropascal el problema es que no entiendo porque toma la lectura al principio y luego la pone en 0 , no entiendo cual es la variable que hace que la lectura no siga , entiendo que este foro tratan sobre este lenguaje tambien asi que les agradezco su ayuda !

program Frekvens_taeller;

{/******************************************************************************
* Project name:
EP6_freq.c EasyPIC5 and 6 using a LCD display
* Copyright:
Open-source - Oct 2009 - Roman Black and CRH
* Description:
The incoming frequency to be measured must be
connected to PORTC.F0 (T1CKI) pin. Max freq measured is 65000 Hz.
Note! If you don't have a freq signal connected, you can test it
by pressing the RC0 pushbutton REALLY quickly.

* Test configuration:
MCU: PIC16F887

Dev.Board: EasyPIC5 and 6

Oscillator: HS, 8.0000 MHz
Ext. Modules: - freq signal comes in on PORTC.F0
SW: mikroC PRO for PIC v3.20


******************************************************************************/}
Var
// LCD module connections same as MikroPascal!
LCD_RS : sbit at RB4_bit;
LCD_EN : sbit at RB5_bit;
LCD_D4 : sbit at RB0_bit;
LCD_D5 : sbit at RB1_bit;
LCD_D6 : sbit at RB2_bit;
LCD_D7 : sbit at RB3_bit;

LCD_RS_Direction : sbit at TRISB4_bit;
LCD_EN_Direction : sbit at TRISB5_bit;
LCD_D4_Direction : sbit at TRISB0_bit;
LCD_D5_Direction : sbit at TRISB1_bit;
LCD_D6_Direction : sbit at TRISB2_bit;
LCD_D7_Direction : sbit at TRISB3_bit;
// End LCD module connections

int_sec_count: byte; // used to count ints/second
new_second: boolean; // is set once per second

//tchar: char; // text char used in LCD display numbers
freq: word; // 0-65000, holds freq value to display integer = heltal

rpm: dword; // holds RPM for calcs AND display RPM= Revolution pr minute = omdrejninger pr sekund

txt: array[16] of char; // used to display number string
//sec_count: char;

//----------------------------------------------------------------------------


// this is TMR2 overflow interrupt
procedure interrupt;
begin
Dec(int_sec_count);
if int_sec_count=0 then // if reached 1 second!
begin
// get the TMR1 count!
T1CON := 0; // TMR1 OFF
Hi(freq) := TMR1H ; // put TMR1 16bit value in freq
Lo(freq) := TMR1L;
TMR1L := 0; // clear TMR1
TMR1H := 0;
T1CON := %00000011; // TMR1 back ON again
// that's everything done for this second
new_second:=true;
int_sec_count := 125; // load ready to generate another second
end;
TMR2IF_bit := 0; // Clear TMR2IF before exit
end;




//-----------------------------------------------------------------------------
Begin
// setup PIC 16F887 registers
ANSEL := 0; // Configure AN pins as digital
ANSELH := 0;
C1ON_bit := 0; // Disable comparators
C2ON_bit := 0;

TRISC := %00000001; // PORTC.F0 = input from freq signal

TRISB := 0; //
PORTB := 0xFF; //
TRISB := 0xFF; //

//-------------------------------------------------------
// EasyPIC5 and 6 LCD setup

// show startup message
//Lcd_Config(0); // Initialize Lcd over SPI interface
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
txt := 'frekvens';
Lcd_Out(1,2,txt); // display startup text to Lcd
txt := ' & Omdrejtaller ';
Lcd_Out(2,2, txt);
Delay_1sec();
Delay_1sec();

// clear LCD again before main
Lcd_Cmd(_LCD_CLEAR);

//-------------------------------------------------------
// setup the timers for frequency counting

// setup TMR1
T1CON := %00000011; // TMR1 ON, external clock pulse on PORTC.F0

// setup TMR2 and enable TMR2 int
T2CON := %00011111; // TMR2 ON, 8MHz xtal, 16:4:1 = 31250 Hz (Timer 2 prescaler settings)
PR2 := 249; // TMR2 int is 31250 / 250 = 125 ints/sec
PIE1.TMR2IE := 1; // TMR2 interrupt is on
// load variables ready to run
int_sec_count := 125;
INTCON := %11000000; // GIE=ON, PIE=ON

//-------------------------------------------------------
// now do the main run loop
while true do
begin
// everytime we reach a second, calculate and display freq
if new_second then
begin
new_second := false;
// safe limit freq at 65 kHz
if freq > 65000 then
freq := 65000;

// display freq as "xxxxx Hz"
WordToStr(freq,txt);
Lcd_Out(1,8,txt);
txt := 'Hz';
Lcd_Out(1,14,txt);

// calc RPM from freq
rpm := (freq * 60);

// format rpm to display as "xxxxxxx RPM"
LongWordToStr(rpm,txt); // get the rpm as a string
Lcd_Out(2,2,txt); // and display RPM!
txt := 'RPM';
Lcd_Out(2,14,txt);

//************
Dec(int_sec_count);
if int_sec_count=0 then // if reached 1 second!
begin
// get the TMR1 count!
T1CON := 0; // TMR1 OFF
Hi(freq) := TMR1H ; // put TMR1 16bit value in freq
Lo(freq) := TMR1L;
TMR1L := 0; // clear TMR1
TMR1H := 0;
T1CON := %00000011; // TMR1 back ON again
// that's everything done for this second
new_second:=true;
int_sec_count := 125; // load ready to generate another second
end;
TMR2IF_bit := 0; // Clear TMR2IF before exit
//************


end;
end;
end.

Mikro-77
15-01-2013, 23:11:19
Vamos amigos ! se que hay verdaderos gurúes en este foro !!!

Ñuño Martínez
18-01-2013, 13:53:03
Es que Mikropascal no es muy utilizado. Aun así, sé que algunos miembros lo usan, o al menos lo han usado.

En el IRC (IRC-hispano, salas #delphi y #pascal) entra gente que usa Mikropascal a menudo, así que quizá te pueden ayudar.

fenixariel
16-03-2013, 22:46:39
No importa el lenguaje, se sigue de la misma manera, en C, Pascal, hasta en ASM,

Me parece que en la interrupcion no?


Saludos.