Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-03-2001, 01:43 AM   #1
Member (7 bit)
 
aceMan's Avatar
 
Join Date: Nov 2001
Location: Singapore
Posts: 93
Exclamation PIC microcontroller program in ASM

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.
aceMan is offline   Reply With Quote
Old 12-12-2001, 12:27 AM   #2
Member (6 bit)
 
Join Date: Apr 2001
Location: SRI LANKA
Posts: 42
Send a message via Yahoo to hiran
give more details.
how u going tio count using timer1
hiran is offline   Reply With Quote
Old 12-12-2001, 01:10 AM   #3
Member (7 bit)
 
aceMan's Avatar
 
Join Date: Nov 2001
Location: Singapore
Posts: 93
Exclamation PIC timer 1.

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
aceMan is offline   Reply With Quote
Old 12-12-2001, 03:23 AM   #4
Member (6 bit)
 
Join Date: Apr 2001
Location: SRI LANKA
Posts: 42
Send a message via Yahoo to hiran
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.
hiran is offline   Reply With Quote
Old 12-12-2001, 08:17 PM   #5
Member (7 bit)
 
aceMan's Avatar
 
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
aceMan is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:47 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2