Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8051 - calculating the value of frequency by using counter

Status
Not open for further replies.

ecestar

Newbie level 5
Joined
May 1, 2009
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,404
8051

hello
can any one helpe me about who can i calculate the value of frequency by using counter
if i want to input frequency to the microcontro then i want to now what is the value of it .
please i need code to do that and any information about it .
 

Re: 8051

Hai

Use interrupt to on the timer and off timer

then u can easily calculate the frequency with the formula 1/time

Regards
Nandhu
 

Re: 8051

ecestar said:
hello
can any one helpe me about who can i calculate the value of frequency by using counter
if i want to input frequency to the microcontro then i want to now what is the value of it .
please i need code to do that and any information about it .

There is source code and an example in the Kenneth Ayala 8051 book. Google it.
 

Re: 8051

How can i Use interrupt to on the timer and off timer

to calculate the frequency with the formula 1/time
please i need example to explan that with code
:cry:
 

8051

did you mean a frequency counter?
you want use C or assembly?
 

Re: 8051

herlambang said:
did you mean a frequency counter?
you want use C or assembly?

yes with c language please if you can
 

Re: 8051

ecestar said:
herlambang said:
did you mean a frequency counter?
you want use C or assembly?

yes with c language please if you can

Okay my friend that's no problem but..
because I'am busy now, please wait for a couple days..
I'll prepare it for you.
 

Re: 8051

herlambang said:
ecestar said:
herlambang said:
did you mean a frequency counter?
you want use C or assembly?

yes with c language please if you can

Okay my friend that's no problem but..
because I'am busy now, please wait for a couple days..
I'll prepare it for you.


ok i am waiting
 

Re: 8051

Hi..
This is the basic one..
You can learn about basic freq. counter on 8051 microcontroller.
This is not the perfect one but it's good for learning purpose. In attachment file included Proteus ISIS simulation for easy debugging. If you want to build on the real hardware, you must modify the schematics on ISIS to meet your requirements such as display and another hardware.

I hope it's can help you..

Regards,

Herlambang.
 

Re: 8051

thank you very much

and now i have idea about frequency counter

and now if i want to display 25 on the lcd when the frequency value is 500HZ
and 40 when the frequency value is 5kHZ.

SO how can i change the program to do that .

and now i work with my code but i have problem to get the resulte

so i need your helpe


thanks,

Added after 1 hours 11 minutes:

and this is my code

but i want to define the range in it and display more than one number in the lcd because now i have problem to display more than one like 1 (49 in ascii code) so what can i do if i want to display 11 or 12 or any two number and this is my code

/*---------------------------------------------------------
---------------------------------------------------------*/
#include <reg66x.h>
#include <reg52.h>
#include <stdio.h>
#define NewLine 0xc0
#define ClrDisp 0x01
#define TwoLine10dots 0x38
#define ScrOnCurOffBlinkOff 0x0F
#define IncCurDntMovDis 0x06
#define OUT P1


int check ;
sbit BusyFlag=P1^7;
sbit RS =P3^5;
sbit RW =P3^6;
sbit E =P3^7;
sbit ref =P2^2;


/*---------------------------------------------------------
Timer 0 Overflow Interrupt
---------------------------------------------------------*/
unsigned long tt ;
unsigned long t;

void T0_ISR (void) interrupt 1
{
TF0 = 0;
// Reset the interrupt request

}


/*---------------------------------------------------------
MAIN C function
---------------------------------------------------------*/

/*---------------------------------------------------------
---------------------------------------------------------*/
int calcul(){
int t;
if((tt<=5678)&&(tt>=4689)){
t=49;
}

if((tt<=4689)&&(tt>=3456)){
t=50;
}
if((tt<=2800)&&(tt>=1200)){
t=51;
}

return t;
}



void freqcheck (void){
{
check=calcul() ;
}
//else {
//check ='A' ;
//}
}
}
void checkBusy(void){


OUT=0XFF ;
do{ ;
E =0;
RS =0;
RW =1;
E =1;
}while(BusyFlag);
E=0;
RW = 0;
}

void sendCmd (unsigned char Cmd){
checkBusy();
RS = 0;
RW = 0;

OUT = Cmd;
E =1;
E =0;
}
void sendData (unsigned char ch){
checkBusy();
RS = 1;
RW = 0;
OUT=ch;
E = 1;
E = 0;
}
void init_LCD (void){
sendCmd(TwoLine10dots);
sendCmd(ScrOnCurOffBlinkOff);
sendCmd(IncCurDntMovDis);

}
void main (void)
{
/*--------------------------------------
Set serial port for 9600 baud at
11.0592 MHz. Note that we use Timer 1
for the baud rate generator.
--------------------------------------*/
SCON = 0x50;
PCON =0x00;
TH1 = 0xFA;
TL1 = 0xFA;
TR1 = 1;
TI = 1 ;







/*--------------------------------------
Enable interrupts for timer 0.
--------------------------------------*/
ET0 = 1;
EA = 1;

/*--------------------------------------
Set Timer0 for 16-bit interval timer
mode.
--------------------------------------*/
TMOD = 0x21;

while (1)
{
/*--------------------------------------
Clear the timer overflow counter and
the timer low and high registers. Then,
start the timer.
--------------------------------------*/
TH0 = 0;
TL0 = 0;

TR0 = 1;


/*--------------------------------------
Wait for the pulse to start.
Then, wait for the pulse to end.
--------------------------------------*/
while (!INT0);
while (INT0);

/*--------------------------------------
Compute the width of the pulse -- one
clock cycle is 1us for a standard 8051
and display it.
--------------------------------------*/
init_LCD();
sendCmd(ClrDisp);
freqcheck();
sendData(check);
sendCmd(NewLine);
printf ("%1d\n",tt=(unsigned long)(TH0*256)+TL0) ;


for(t=0;t<100000;t++);

}



}
 

8051

can anybody give me the 8051 programmer circuit which is tested by anyone and it's software
 

Re: 8051

h_waqasahmed said:
can anybody give me the 8051 programmer circuit which is tested by anyone and it's software

Post your request under new post, so that some one can really help you out. Goodluck
 

8051

¿Alguién puede indicarme como puedo hacer un frecuencímetro en ASM?
La señal la paso por un conversor A/D y necesito conocer la frecuencia y el Ton para poder visualizar en un lcd.
¿Cómo paso del valor de los registros a valor en LCD?
Un saldo y gracias
 

Re: 8051

can any one helpe me about who can i calculate the value of frequency by using counter
if i want to input frequency to the microcontro then i want to now what is the value of it .
please i need code to do that and any information about it.

I need code in asm languaje.

I need pass the values of tl1,th1 y r3 (ej.asm) to Hz.

Thanks

Added after 1 minutes:

This is my example code (ej.asm)

ORIGIN 0000H
JMP INICIO


ORIGIN 8200H



*******************************************************
*********INICIALIZACION DEL LCD************************
*******************************************************

INICIO: CALL TIEMPO
MOV A,#38H
CALL ESCI_1
CALL TIEMPO
CALL ESCI_1
CALL TIEMPO
CALL ESCI

CALL ESCI
MOV A,#08H
CALL ESCI
MOV A,#01H
CALL ESCI
MOV A,#06H
CALL ESCI
MOV A,#0FH
CALL ESCI










*************MUESTRA EL PRIMER MENSAJE*******************
*********************************************************

MOV DPTR,#B000H
MENS1: MOV A,#00H
MOVC A,@A+DPTR
CALL ESCD
INC DPTR
MOV A,DPL
CJNE A,#05H,MENS1



MOV A,#86H
CALL ESCI







************VALORES DE EJEMLPO PARA COMPROBAR FUNCIONAMIENTO****************
************INCPOS PASA DE HEXADECIMAL A BCD********************************

CLR 21H
MOV TL1,#38H
MOV TH1,#42H
MOV R3,#0FH



INCPOS EQU C000H

MOV 60H,TL1

MOV DPH,#D0H
MOV DPL,#00H

MOV 50H,#01H
MOV 51H,#04H

CALL INCPOS

MOV 50H,#02H
MOV 51H,#03H

CALL INCPOS

MOV 50H,#03H
MOV 51H,#01H

CALL INCPOS


MOV 60H,TH1

MOV DPH,#D0H
MOV DPL,#0DH


MOV 50H,#03H
MOV 51H,#02H

CALL INCPOS

MOV 50H,#04H
MOV 51H,#04H

CALL INCPOS

MOV 50H,#05H
MOV 51H,#02H

CALL INCPOS

MOV 60H,R3

MOV DPH,#D0H
MOV DPL,#2DH


MOV 50H,#05H
MOV 51H,#01H

CALL INCPOS

MOV 50H,#06H
MOV 51H,#03H

CALL INCPOS

MOV 50H,#07H
MOV 51H,#04H

CALL INCPOS





**********************ESCRIBE EL VALOR DEL TH1,TL1 Y R3 EN EL LCD***************

MOV A,39H
ADD A,#30H
CALL ESCD

MOV A,38H
JNZ S
JMP S11
S: SETB 21.2H
S11: ADD A,#30H
CALL ESCD

JNB 21.2H,SEG
MOV A,#'.'
CALL ESCD


SEG: MOV A,37H
ADD A,#30H
CALL ESCD

MOV A,36H
ADD A,#30H
CALL ESCD

MOV A,35H
JNZ MS
JMP SMS
MS: SETB 21.1H
SMS ADD A,#30H
CALL ESCD
JB 21.2H,SEG1
JNB 21.1H,SEG1
MOV A,#'.'
CALL ESCD



SEG1: MOV A,34H
ADD A,#30H
CALL ESCD

MOV A,33H
ADD A,#30H
CALL ESCD


MOV A,32H
ADD A,#30H
CALL ESCD



JB 21.2H,SEGUNDO
JB 21.1H,MILISEG
JMP US

US: MOV A,#'U'
CALL ESCD
MOV A,#'s'
CALL ESCD
JMP FINI


MILISEG:MOV A,#'m'
CALL ESCD
MOV A,#'s'
CALL ESCD
JMP FINI

SEGUNDO:MOV A,#'s'
CALL ESCD
JMP FINI


















FINI: JMP FIN
FIN: JMP FIN


********************SUBRUTINAS DEL LCD***********************
*************************************************************


ORIGIN 9450H
ESCI_1: MOV DPTR,#4000H
MOVX @DPTR,A
RET



ORIGIN 9500H
ESCI: MOV DPTR,#4000H
MOVX @DPTR,A
CALL CHEQUE
RET


ORIGIN 9550H
CHEQUE: MOV DPTR,#4002H
OCUPA: MOVX A,@DPTR
JB A.7,OCUPA
RET



ORIGIN 9600H
ESCD: PUSH DPL
PUSH DPH
MOV DPTR,#4001H
MOVX @DPTR,A
CALL CHEQUE
POP DPH
POP DPL
RET


ORIGIN 9650H
TIEMPO: MOV R7,#50
S1: MOV R6,#17
S2: DJNZ R6,S2
DJNZ R7,S1
RET

***********MENSAJE*************

ORIGIN B000H

BYTE 'TON: '


*****************************************************
******RUTINA INCPOS: pASA DE HEXADECIMAL A BCD******
*****************************************************

ORIGIN C000H

CLR 20H.0
SIGBIT: MOV C,20.0H
MOV A,60H
RRC A
MOV 60H,A
MOV 20.0H,C
MOV R1,50H
JC A_UNO
PUSH A
MOV A,DPL
ADD A,50H
MOV DPL,A
POP A

OTROBIT:DJNZ 51H,SIGBIT
RET

A_UNO: MOV R0,#32H
OTRAVEZ:CLR A
MOVC A,@A+DPTR

INCDIGIT:CJNE A,#00H,INCMAS2
JMP FINDIGIT

INCMAS2:DEC A
CJNE @R0,#09H,INCR0
MOV 61H,R0

INCMAS: MOV @R0,#00H
INC R0
CJNE @R0,#09H,INCR02

INCR02: INC @R0
MOV R0,61H
JMP INCDIGIT

INCR0: INC @R0
JMP INCDIGIT

FINDIGIT:INC DPL

DJNZ R1,OTRAV
JMP OTROBIT

OTRAV: INC R0
JMP OTRAVEZ


************************************************************
*************TABLA CON LOS PESOS DE CADA POSICION***********
************************************************************

ORIGIN D000H
BYTE 1,2,4,8,6,1,2,3,4,6,8,2,1,6,5,2,2,1,5,4,2,0,1
BYTE 8,4,0,2,6,9,0,4,2,9,1,8,4,8,3,6,1,8,6,7,2,3,6
BYTE 3,5,5,6,2,7,0,1,3,1,4,4,1,2,6,2,8,8,2,4,2,5,6
BYTE 7,5,8,4,0,1,2,5,1,7,9,0,2,4,0,3,4,9,1,4,8,0,6
BYTE 8,8,3,8

END
 

8051

@osoenbolsa,
I disagree with your needs. You don't need code, you need to improve your understanding of what you are doing and it would also help if you improve your English skills. This group has lots of very nice people and I am not an English native speaker either, however I try to do my homework first and then ask for help if I can't get it done.
Your problem is so basic, it does sound like homework of some school and you are the one that is supposed to get it done!
No offense, Bob
 

Re: 8051 - calculating the value of frequency by using count

frequency counter and led display of counts , for further information
**broken link removed**
 

Re: 8051 - calculating the value of frequency by using count

Απλοποιημένος αλγόριθμος ενεγοποίησης/απενεργοποίησης βενζινοκινητήρα και ηλεκτροκινητήρα με on/off διακόπτες και με βάση τις ενδείξεις αισθητήρων ταχύτητας/στροφών, γκαζιού, φρένου. Με 8051... Μπορει να ριξει κανείς καμιά ιδέα ή να με παραπέμψει κάπου;
 

Re: 8051 - calculating the value of frequency by using count

Here is an example code for determine a frequency from one of my STM32 project (took it off from a post in the ST forum and modify for my own needs). I have tested using signal generator and it seems to be very accurate. The thing you should be looking at is the logical statements. If it doesn't help you search the ST forum.

void MeasureSpeed (void)
{
if (bCalcFreqFlag)
{
freq = (cpt1*2)/3;
cpt1 = 0;
bCalcFreqFlag = 0;
}

bln_E1=GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_10);
bln_F1=~bln_HF1&bln_E1;
bln_HF1=bln_E1;

if (bln_F1)
{
cpt1++;
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top