+ Reply to Thread
Page 2 of 3
First 1 2 3 Last
Results 16 to 30 of 44

Thread: PIC Delay calculator

  1. #16
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,797

    Default

    Quote Originally Posted by wmmullaney
    I'm just going to use the code I'v got.

    I read the datasheet. How do I do a config word? Is it done in hex? Can it be done in binary?
    Check any PIC code examples (like mine above), you can set it in hex (as I do), in binary, or (as many do) using long text strings full of AND'd from the include files.


    What resistor value do you suggest as a current limiting resistor for high brightness blue leds with a pic running at 5v?
    Use ohms law subtract the voltage drop of the LED from 5V to get the voltage, and decide what current you want, then apply ohms law to get the resistor.

    But it depends if you're multiplexing or not?.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk


  2. #17
    wmmullaney Good wmmullaney Good wmmullaney Good
    Join Date
    Dec 2006
    Location
    USA
    Posts
    368

    Default

    I'm not sure the voltage drop of the led, will 350 ohms be okay?

    Here's my clock code, how does it look?

    Code:
    	;********************
    	; Written by,       *
    	; William Mullaney  *
    	; On                *
    	; January 14, 2008  *
    	;                   *
    	; Binary Clock      *
    	; PIC16F628A        *
    	;********************
    	
    	LIST	p=16F628A
    	include "p16f628a"
    	__config 0x2118
    	
    	HOUR equ 20h
    	MIN  equ 21h
    	R1   equ 22h
    	R2   equ 23h
    	R3   equ 24h
    	
    	MOVLW    07h
    	MOVWF    CMCON
    	BSF      STATUS,	RP0
    	MOVLW    b'11111111'
    	MOVWF    TRISA
    	MOVWF    TRISB
    	BCF      STATUS,	RP0
    	
    SHR BTFSS    PORTB,     08h
    	GOTO     SHR
    	MOVF     PORTA,     HOUR
    	
    SMN BTFSS    PORTA,		08h
    	GOTO	 SMN
    	MOVF	 PORTB,		MIN
    	
    CHK	BTFSC	 PORTA,		08h
    	GOTO	 CHK
    	
    	BSF		 STATUS,	RP0
    	MOVLW	 b'00000000'
    	MOVWF	 TRISA
    	MOVWF	 TRISB
    	BCF		 STATUS,	RP0
    	
    CLK CALL	 DLY
    	INCF	 MIN,		1
    	MOVF	 MIN,		W
    	BCF		 STATUS,	C
    	MOVLW	 C3h
    	BTFSS	 STATUS,	C
    	GOTO	 PRT
    	CLRF	 MIN
    	INCF	 HOUR,		1
    	MOVF	 HOUR,		W
    	BCF		 STATUS,	C
    	MOVLW	 F3h
    	BTFSS	 STATUS,	C
    	CLRF	 HOUR
    	INCF	 HOUR,		1
    	
    PRT MOVF	 HOUR,		PORTA
    	MOVF	 MIN,		PORTB
    	GOTO	 CLK
    	
    DLY CBLOCK
    	R1
    	R2
    	R3
    	ENDC
    	
    	MOVLW	 22h
    	MOVWF	 R1
    	MOVLW	 CBh
    	MOVWF	 R2
    	MOVLW	 83h
    	MOVWF	 R3
    	
    DY0	DECFSZ	 R1,		F
    	GOTO	 $+2
    	DECFSZ	 R2,		F
    	GOTO	 $+2
    	DECFSZ	 R3,		F
    	GOTO	 DY0
    	RETURN
    
    sorry it looks bad, something with my text editor.

  3. #18
    wmmullaney Good wmmullaney Good wmmullaney Good
    Join Date
    Dec 2006
    Location
    USA
    Posts
    368

    Default

    Quote Originally Posted by wmmullaney
    I'm not sure the voltage drop of the led, will 350 ohms be okay?

    Here's my clock code, how does it look?

    Code:
    	;********************
    	; Written by,       *
    	; William Mullaney  *
    	; On                *
    	; January 14, 2008  *
    	;                   *
    	; Binary Clock      *
    	; PIC16F628A        *
    	;********************
    	
    	LIST	p=16F628A
    	include "p16f628a"
    	__config 0x2118
    	
    	HOUR equ 20h
    	MIN  equ 21h
    	R1   equ 22h
    	R2   equ 23h
    	R3   equ 24h
    	
    	MOVLW    07h
    	MOVWF    CMCON
    	BSF      STATUS,	RP0
    	MOVLW    b'11111111'
    	MOVWF    TRISA
    	MOVWF    TRISB
    	BCF      STATUS,	RP0
    	
    SHR BTFSS    PORTB,     08h
    	GOTO     SHR
    	MOVF     PORTA,     HOUR
    	
    SMN BTFSS    PORTA,		08h
    	GOTO	 SMN
    	MOVF	 PORTB,		MIN
    	
    CHK	BTFSC	 PORTA,		08h
    	GOTO	 CHK
    	
    	BSF		 STATUS,	RP0
    	MOVLW	 b'00000000'
    	MOVWF	 TRISA
    	MOVWF	 TRISB
    	BCF		 STATUS,	RP0
    	
    CLK CALL	 DLY
    	INCF	 MIN,		1
    	MOVF	 MIN,		W
    	BCF		 STATUS,	C
    	MOVLW	 C3h
    	BTFSS	 STATUS,	C
    	GOTO	 PRT
    	CLRF	 MIN
    	INCF	 HOUR,		1
    	MOVF	 HOUR,		W
    	BCF		 STATUS,	C
    	MOVLW	 F3h
    	BTFSS	 STATUS,	C
            GOTO PRINT
    	CLRF	 HOUR
    	INCF	 HOUR,		1
    	
    PRT MOVF	 HOUR,		PORTA
    	MOVF	 MIN,		PORTB
    	GOTO	 CLK
    	
    DLY CBLOCK
    	R1
    	R2
    	R3
    	ENDC
    	
    	MOVLW	 22h
    	MOVWF	 R1
    	MOVLW	 CBh
    	MOVWF	 R2
    	MOVLW	 83h
    	MOVWF	 R3
    	
    DY0	DECFSZ	 R1,		F
    	GOTO	 $+2
    	DECFSZ	 R2,		F
    	GOTO	 $+2
    	DECFSZ	 R3,		F
    	GOTO	 DY0
    	RETURN
    
    sorry it looks bad, something with my text editor.

    Fixed a bug.

  4. #19
    David / W9GF Good David / W9GF Good
    Join Date
    Apr 2008
    Location
    Dallas, Texas
    Posts
    17

    Default Excel Spreadsheet to help in calculating TIMER0 delays

    I created a small excel spreadsheet which i'm attaching that may be helpful in calculating the various delays available with a given clock frequency. All you need to enter is your clock frequency in mhz - everything else is calculated based on that.

    Enjoy!

    David

    Edit: An updated attachment is here: PIC Delay calculator
    Last edited by David / W9GF; 10th April 2008 at 04:42 AM.

  5. #20
    mike50 Okay
    Join Date
    Jun 2007
    Location
    Rochester, Minnesota
    Posts
    102

    Default

    Here is a little program that will calculate the settings (prescale, postscale and PR2) for TMR2 to generate interrupts for whatever time interval you want. If it can generate settings for exactly what you want, it shows all the ways that can be achieved. If there are no settings to get exactly what you want it shows the closest values (one greater and one less than what you want).

    You run it as:

    TMR2 n

    where n is the timer interval you want in instruction cycles.

    examples:

    Code:
    C:>TMR2 10000
    10000 Prescaler 1:16 Postscaler 1:5  PR2 124
    10000 Prescaler 1:4  Postscaler 1:10 PR2 249
    
    C:>TMR2 1234
     1233 Prescaler 1:1  Postscaler 1:9  PR2 136
     1235 Prescaler 1:1  Postscaler 1:13 PR2  94
    

    The maximum value for n is 65536


    ---updated with program that doesn't require the C-runtime DLL---

    Mike
    Attached Files
    Last edited by mike50; 9th April 2008 at 05:39 PM.

  6. #21
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,853
    Blog Entries
    13

    Default

    Quote Originally Posted by David / W9GF
    I created a small excel spreadsheet which i'm attaching that may be helpful in calculating the various delays available with a given clock frequency. All you need to enter is your clock frequency in mhz - everything else is calculated based on that.

    Enjoy!

    David
    Hi,
    Tried runs OK, BTW 'OPen Office' will run the program.
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

    Link to my Articles: http://www.electro-tech-online.com/a...icgibbs-55450/

  7. #22
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,853
    Blog Entries
    13

    Default

    Quote Originally Posted by mike50
    Here is a little program that will calculate the settings (prescale, postscale and PR2) for TMR2 to generate interrupts for whatever time interval you want. If it can generate settings for exactly what you want, it shows all the ways that can be achieved. If there are no settings to get exactly what you want it shows the closest values (one greater and one less than what you want).

    You run it as:

    TMR2 n

    where n is the timer interval you want in instruction cycles.

    examples:

    Code:
    C:>TMR2 10000
    10000 Prescaler 1:16 Postscaler 1:5  PR2 124
    10000 Prescaler 1:4  Postscaler 1:10 PR2 249
    
    C:>TMR2 1234
     1233 Prescaler 1:1  Postscaler 1:9  PR2 136
     1235 Prescaler 1:1  Postscaler 1:13 PR2  94
    

    The maximum value for n is 65536

    Mike
    Hi Mike,
    Unzipped, keep getting this error msg in Win XP.
    Attached Images
    Last edited by ericgibbs; 7th July 2008 at 11:23 AM.
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

    Link to my Articles: http://www.electro-tech-online.com/a...icgibbs-55450/

  8. #23
    mike50 Okay
    Join Date
    Jun 2007
    Location
    Rochester, Minnesota
    Posts
    102

    Default

    Quote Originally Posted by ericgibbs
    Hi Mike,
    Unzipped, keep getting this error msg in Win XP.
    Hmmm. The program is written in Visual C++, and shouldn't require .NET. But that is the error you can get for .NET applications trying to run on machines without .NET (or with the wrong version).

    Actually, the problem was that it was compiled to need the C-runtime library as a DLL. I've rebuilt it with the runtime contained within the .exe.

    This updated version should work okay.

    Mike
    Attached Files
    Last edited by mike50; 9th April 2008 at 04:50 PM.

  9. #24
    savnik Newbie
    Join Date
    Apr 2006
    Posts
    80
    Blog Entries
    1

    Default

    Quote Originally Posted by ericgibbs
    Hi Mike,
    Unzipped, keep getting this error msg in Win XP.
    Is a DOS programm.
    You must to runn this from CMD

  10. #25
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,853
    Blog Entries
    13

    Default

    Quote Originally Posted by savnik
    Is a DOS programm.
    You must to runn this from CMD
    Hi,
    Thought it was a Windows program, will try from DOS/cmd.

    Thanks.
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

    Link to my Articles: http://www.electro-tech-online.com/a...icgibbs-55450/

  11. #26
    mike50 Okay
    Join Date
    Jun 2007
    Location
    Rochester, Minnesota
    Posts
    102

    Default

    Quote Originally Posted by ericgibbs
    Hi,
    Thought it was a Windows program, will try from DOS/cmd.

    Thanks.
    It is a window's program, but you really need to run it from a command prompt so you can supply it with the parameter.

    The error that ericgibbs was seeing is due to not being able to find a .dll that it wanted. The new version doesn't require any .dll's.

    Mike

  12. #27
    David / W9GF Good David / W9GF Good
    Join Date
    Apr 2008
    Location
    Dallas, Texas
    Posts
    17

    Default Made some changes to the Excel Spreadsheet

    Saw your output mike50 with postscaler values so i corrected a couple of little bugs with mine, added a place to put in "Delay I need" - and it shows you all of your options - even converts the 8 bit stuff to hex for ya (guess microsoggy didn't think anyone would need a DECTOHEX32() function in Excel Grrrrr)...

    Also added some timer notes i found in the Data sheet for the 18F4550 at the bottom.

    Hope this stuff is accurate! I'll be testing & working with it for the next couple of weeks so i'll update my .xls if i find anything out of kelter!

    David

    The most current version of the attachment is here: PIC Delay calculator

    (today anyway )
    Last edited by David / W9GF; 10th April 2008 at 04:45 AM.

  13. #28
    mike50 Okay
    Join Date
    Jun 2007
    Location
    Rochester, Minnesota
    Posts
    102

    Default

    David,

    I'm not sure I understand the meaning of the Postscaler in your spreadsheet. TMR0 doesn't have a postscaler. If you are doing this for TMR2 then you want to include the PR2 register as part of the calculation.

    Mike

  14. #29
    David / W9GF Good David / W9GF Good
    Join Date
    Apr 2008
    Location
    Dallas, Texas
    Posts
    17

    Default postscaler

    I may have used the wrong terminology - but that's the value to write in the TMR0 & TMR1 register instead of 0 ... and now that i've typed this the value i have is incorrect - i forgot this thing is counting up and not down - so the value should be subtracted from 255 for the 8 bit mode and subtracted from 65535 for the 16 bit mode.

    That making sense or am i way off base?

  15. #30
    mike50 Okay
    Join Date
    Jun 2007
    Location
    Rochester, Minnesota
    Posts
    102

    Default

    Oh, I see what you are getting at. What you are calling "postscaler" is more like the PR2 register of TMR2. It defines how many counts before TMR0 overflows.

    There is a problem with that technique though. Some time elapses from the point where the TMR0 overflows and where your interrupt service routine can write the new value into TMR0. In some circumstances you could correct for that time, but in others (if there are other interrupts enabled, or the mainline sometimes disables interrupts) you can not accurately compensate.

    That is why TMR2, with a hardware postscaler and the PR2 (match) register, is so nice. It is all in hardware. Your timing has no dependency on the time it takes to get into your interrupt service routine. The interrupts come like, well , "clockwork"

    Mike

+ Reply to Thread
Page 2 of 3
First 1 2 3 Last

Similar Threads

  1. PIC Christmas Light Project
    By amdkicksass in forum Micro Controllers
    Replies: 28
    Latest: 9th July 2007, 07:54 PM
  2. Motor Controllers and serial comm?
    By RedCore in forum Micro Controllers
    Replies: 18
    Latest: 3rd July 2007, 01:27 AM
  3. Log Data using pic16F877A
    By williB in forum Micro Controllers
    Replies: 32
    Latest: 31st October 2006, 09:28 AM
  4. Delay routine not working
    By gregmcc in forum Micro Controllers
    Replies: 6
    Latest: 18th September 2005, 05:23 PM
  5. Effects
    By stephenpic in forum Micro Controllers
    Replies: 6
    Latest: 19th January 2004, 11:57 AM

Tags for this Thread