|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (7 bit)
Join Date: Nov 2001
Location: Singapore
Posts: 93
|
![]() Hi there.Anyone out there used PIC microcontroller b4?? Especially 16F877. I am using it to count frequency. I am using Timer1. I know the routine for initialising. I am also transmitting the received frequency to PC com port. That also I know. The thing is I wanna know the code for getting the received frequency which is counted into frequency. The received frequency I guess will be as period in TMR1H:TMR1L. From here how am I to transform to frequency?? Can somebody help. Thanks in advance.
|
|
|
|
|
|
#2 |
|
Member (6 bit)
|
give more details.
how u going tio count using timer1 |
|
|
|
|
|
#3 |
|
Member (7 bit)
Join Date: Nov 2001
Location: Singapore
Posts: 93
|
I am using it as counter mode. I make a delay while turning on the timer. and stop the timer. I bring it into temporary vaiable and this is where the problem. I need to convert to frequency as what I seem to know is it is in period as the timer is counting at every rising edge.
Here is the part of programme: Main: clrf T1CON ; Initialize T1 Timer clrf INTCON Bank1 clrf PIE1 ; clear interrupt Bank0 clrf Index ; clear Index clrf PIR1 movlw 0x02 movwf T1CON clrf TMR1H clrf TMR1L bsf T1CON,TMR1ON call Delay200mS bcf T1CON,TMR1ON call SerialSetup ; whrn returns, still in bank0 again: clrf TMR1H clrf TMR1L bsf T1CON,TMR1ON call Delay200mS bcf T1CON,TMR1ON call GetFreq GetFreq: movf TMR1H,W movwf FreqHi movf TMR1L,W movwf FreqLo retlw 0 this is the programme. After GetFreq I dunno how to continue. I might have to use some Math function but seriously dunno how Thanks |
|
|
|
|
|
#4 |
|
Member (6 bit)
|
hey aceman!
I think Ur problem is how to calculate the frequency. now u have the no. of cycles for 200ms, as i understood, in 16 bit TMR1 register. why dont u make that delay 1 second and get the cyles per second value directly. or else u have to add the value 5 times to get the frequency. anyway u can get frequency in two 8 bit registers. I think this is ur problem now. anyway u can get upto 65536 x 5 Hz if u use 200ms duration. this is some 300kHz. for conversion check the attached B2BCD routine. i used it to convert hex data into bcd for a display driver. B2BCD MOVLW 0x08 MOVWF BIT ;stores the current bit position CLRF DIG1 CLRF DIG2 ROTATE RRF VALUE,F BTFSC STATUS, C CALL ADD DECFSZ BIT,F GOTO ROTATE RETURN ADD MOVF BIT,W CALL LOOKUP MOVWF INCVAL INCDIG1 INCF DIG1,F BTFSC DIG1,3 CALL CHKDIG1 DECFSZ INCVAL,F GOTO INCDIG1 RETURN LOOKUP ADDWF PCL,F NOP RETLW 0x80 RETLW 0x40 RETLW 0x20 RETLW 0x10 RETLW 0x08 RETLW 0x04 RETLW 0x02 RETLW 0x01 CHKDIG1 BTFSC DIG1,1 CALL INCDIG2 RETURN INCDIG2 CLRF DIG1 INCF DIG2,F BTFSC DIG2,3 CALL CLRDIG2 RETURN this is to control 8 bit value. u can use 2 lookup tables and with slight modifications u can do ur job. |
|
|
|
|
|
#5 |
|
Member (7 bit)
Join Date: Nov 2001
Location: Singapore
Posts: 93
|
Hi hiran,
thanks for your advice. I will try changing to 1 s delay and also use the B2BCD. I will let you know of any progress or trouble as soon as possible. If I havent tell u. I am uing this for speed detector. I have to use th doppler input and then convert to speed and pump it out to the serialport. Thx aceMan |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|