Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > Electronic Projects Design/Ideas/Reviews


Electronic Projects Design/Ideas/Reviews Are you building an electronic project or want to? Maybe you need some assistance? Come and submit your electronic questions here and let our experienced members find a solution.

Reply
 
Tools
Old 22nd November 2007, 11:29 PM   #1
Exclamation Building a stopwatch with PIC16F877a

hi all

im having problem with writing assembly language that will implement a stopwatch!!!
i have to design it so that it has a count to the base 7 and has max count of 66!
i also have to implement a delay of 1.38s for each count(i.e time taken for it to go from 1 value to the next) the clock is 20MHz and each instruction takes 200ns!

any help will be appreciated
ag501 is offline  
Old 23rd November 2007, 01:39 AM   #2
Default

Why do you "have" to design it that way?

Posting your code would help.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 23rd November 2007, 03:17 AM   #3
Default

Here's a code snippet that may help. It sets up timer 1 so that it overflows every 10mS.

Code:
		movlw	B'00000001'
		movwf	T1CON;		enable timer 1

		movlw	low(.50000)
		movwf	CCPR1L
		movlw	high(.50000)
		movwf	CCPR1H
		movlw	B'00001011';	enable special event trigger on CCP1
		movwf	CCP1CON;
The bit that gets set is PIR1,CCP1IF and you need to clear it afterwards. So your main code would be something like,
Code:
Wait		btfss	PIR1,CCP1IF
		goto	Wait
		bcf	PIR1,CCP1IF;	reset special event trigger bit
		incf	........etc
HTH

Mike.



Mike.
Pommie is online now  
Old 23rd November 2007, 11:14 AM   #4
Default RE

hey

i have to design it that way because its part of the specification for my project!!!

that snippet you sent is that for the pic16f877a(20MHz clock,200ns intruction cycle)
ag501 is offline  
Old 23rd November 2007, 11:22 AM   #5
Default

Quote:
Originally Posted by blueroomelectronics
Why do you "have" to design it that way?
Because it's obviously a school assignment! - the stupid base 7 requirement is probably to stop them just copying something off the net?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 23rd November 2007, 12:55 PM   #6
Default :-(

alrite

i think i have got the counter to count to the base7 but its the delay of 1.38s
im having problem with
ag501 is offline  
Old 23rd November 2007, 02:58 PM   #7
Default

Quote:
Originally Posted by ag501
alrite

i think i have got the counter to count to the base7 but its the delay of 1.38s
im having problem with
Try the "delay code generator" on the PICList.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 23rd November 2007, 03:12 PM   #8
Default

Just use the code I posted earlier. Test the bit and increment a counter, once it gets to 138 your 1.38s is up.

Mike.
Pommie is online now  
Old 23rd November 2007, 03:21 PM   #9
Default

Mike (Pommie) actually provided a workable 10 msec timer solution. The OP really just needs to add a counter that counts 138 of those timer 'ticks' before incrementing his digit counters. Gosh, how hard could it be?

Code:
;
;
Wait    btfss   PIR1,CCP1IF     ; 10 msec timeout?
        goto    Wait            ; no, branch and wait, else
        bcf     PIR1,CCP1IF     ; clear Timer 1 interrupt flag
        decfsz  Timer,F         ; has 1380 usecs elapsed?
        goto    Wait            ; no, branch, else
        movlw   d'138'          ; reset 1380 usec Timer var'
        movwf   Timer           ; 
;
;  increment digit counters here then jump back to the Wait sub'
;

Last edited by Mike, K8LH; 23rd November 2007 at 06:01 PM.
Mike, K8LH is offline  
Old 23rd November 2007, 04:03 PM   #10
Default

Mike,

Your absolutely spot on except for the bit that is set. It is PIR1,CCP1IF that gets set rather than the timer1 interrupt flg.

Mike.
Pommie is online now  
Old 23rd November 2007, 06:02 PM   #11
Default

Oops! Please pardon me. I corrected my previous post.
Mike, K8LH is offline  
Old 25th November 2007, 09:47 PM   #12
Default hi

hey all
what is PIR1,CCP1IF? are these variables set at the start of the prog?

is the very early ppost u put up is that the beginning of the 10msec delay?

thanks again

Quote:
Originally Posted by Mike, K8LH
Mike (Pommie) actually provided a workable 10 msec timer solution. The OP really just needs to add a counter that counts 138 of those timer 'ticks' before incrementing his digit counters. Gosh, how hard could it be?

Code:
;
;
Wait    btfss   PIR1,CCP1IF     ; 10 msec timeout?
        goto    Wait            ; no, branch and wait, else
        bcf     PIR1,CCP1IF     ; clear Timer 1 interrupt flag
        decfsz  Timer,F         ; has 1380 usecs elapsed?
        goto    Wait            ; no, branch, else
        movlw   d'138'          ; reset 1380 usec Timer var'
        movwf   Timer           ; 
;
;  increment digit counters here then jump back to the Wait sub'
;
ag501 is offline  
Old 26th November 2007, 11:48 AM   #13
Default hey

hi
i was on the PICList website and looking at the delay code generator
... it uses an instruction similar to this goto $+1?
what does the $ sign mean?
ag501 is offline  
Old 26th November 2007, 11:59 AM   #14
Default

Quote:
Originally Posted by ag501
hi
i was on the PICList website and looking at the delay code generator
... it uses an instruction similar to this goto $+1?
what does the $ sign mean?
It's explained in the MPASM helpfile, and has been explained here numerous times - $ is the current address - so 'goto $+1' jumps to the following line, essentially a two instruction time NOP.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 26th November 2007, 02:48 PM   #15
Default

Quote:
Originally Posted by ag501
hey all
what is PIR1,CCP1IF? are these variables set at the start of the prog?

is the very early ppost u put up is that the beginning of the 10msec delay?

thanks again
PIR1,CCP1IF is a bit that gets set very 10mS if you insert the code snippet that I posted earlier in your initialisation code.

Mike, K8LH posted example code to show how you would use this bit.

It sounds like you need to familiarise yourself with the pic opcodes. Having a read of the sticky and working your way through some of the tutorials would be a good way to learn.

Mike.
Pommie is online now  
Reply

Tags
building, pica, stopwatch

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Robot Building for Beginners Souper man Electronic Books 15 17th April 2009 08:07 PM
wind speed meter with direction using PIC16f877A, rotary encoder and LCD 16x2 mokh Electronic Projects Design/Ideas/Reviews 14 29th October 2008 08:00 AM
mclr pin problem for pic16f877a neelam29 Micro Controllers 6 7th February 2007 02:04 PM
What is the best C Compiler for PIC16F877A? dimastar85 Micro Controllers 14 23rd December 2006 11:21 PM
Building a signal mixer (for music primary) thec Electronic Projects Design/Ideas/Reviews 4 3rd October 2002 06:07 PM



All times are GMT. The time now is 12:19 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker