Timing on the 12F675


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2010
    Posts
    5

    Default Timing on the 12F675

    I am using PicBasic Pro with the 12F675. I am using the internal 4MHz oscillator and seem to be having some issues.

    I will need to create 30KHz, 33KHz, 36KHz, 38KHz, 40KHz and 56KHz. 38KHz is the most important and the one that I am working with first. I would like to make a 13uS on and 13uS off square wave.

    If I run just a tight loop turning the output on and off the output is about 4.4uS on and 4.4uS off. Does this sound correct?

    I tried to use pauseus 13 thinking that I would get a 13uS pause but it created about a 25uS pause. pauseus 1 still causes a 25uS pause. Is there that much overhead in turning the pin high and low.

    Here is what I am trying.

    freq38K:
    HIGH IrLed
    PAUSEUS 13
    LOW IrLed
    PAUSEUS 13
    GOTO freq38k

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    You might try
    Code:
    GPIO = %xxxxxxxx
    Make the x's 0 or 1. 1 being high.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    If the frequency needs to be accurate you would be much better off using a timer interrupt.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi,

    as the Holy Manual states ...

    min PAUSEUS @ 4 Mhz is ... 19µs ...

    soooo .... toobad !

    Now, for this " universal IR Tx " ...the use of a Xtal looks compulsory !

    Alain

    PS: an assembler stubb would be useful here ...

    Code:
    ;-------------------------------------------------------------
    ; Code generated by PDEL  ver 1.0  on 23/04/2010 at 09:01:45
    ; Description: Waits 13 cycles
    ;-------------------------------------------------------------
    PDelay  movlw     .2        ; 1 set number of repetitions
            movwf     PDel0     ; 1 |
    PLoop0  clrwdt              ; 1 clear watchdog
            decfsz    PDel0, 1  ; 1 + (1) is the time over?
            goto      PLoop0    ; 2 no, loop
            return              ; 2+2 Done
    ;-------------------------------------------------------------
    
    
    
    Code requirements
    -----------------
    - Declaration of PDel0 (register)
    - 1 stack level
    
    Example of use
    --------------
    call PDelay      ; Delay 13 cycles (including call+return)
    Last edited by Acetronics2; - 23rd April 2010 at 08:02.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    http://www.rentron.com/Infrared_Communication.htm

    Code:
    PROCESSOR 12c508
       #include "p12c508.inc"
       __CONFIG  _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
       #DEFINE PORT B'11111101'
    	MOVF OSCCAL
    	MOVLW PORT
    	TRIS GPIO
    		
       BEGIN
    	BCF GPIO, 1     ;1uS
    	NOP	        ;2uS each nop is 1uS long
    	NOP		;3uS
    	NOP		;4uS
    	NOP		;5uS
    	NOP		;6uS
    	NOP		;7uS
    	NOP		;8uS
    	NOP		;9uS
    	NOP		;10uS
    	NOP		;11uS
    	NOP		;12uS
    	NOP		;13uS
    	NOP		;14uS
    	NOP		;15uS
    	NOP		;16uS
    	NOP		;17uS
    	NOP		;18uS
    	NOP	        ;19uS 
    	BSF GPIO, 1 	;1uS Begin HIGH duty cycle
    	NOP		;2uS
    	NOP		;3uS
    	NOP		;4uS
    	NOP		;5uS
    	GOTO BEGIN      ;2uS (26uS total for 38KHz)
    	END
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Something like this is easier with PBP.

    This is in an include file;
    Code:
      ' IR carrier generator routines. Freq.inc.
    
      Cycles VAR BYTE    ' Number of carrier cycles
      
      GOTO OverFreq  ' jump over pulse routines
      
    ' Generate "Cycles" number of 40kHz pulses
    ASM
    _Pulse40
       bcf IRTX,PIN     ; 1uS, LED=on
       goto $+1         ; + 2uS = 3uS
       goto $+1         ; + 2uS = 5uS
       goto $+1         ; + 2uS = 7uS
       goto $+1         ; + 2uS = 9uS
       goto $+1         ; + 2uS = 11uS
       goto $+1         ; + 2uS = 13uS   
       bsf IRTX,PIN     ; 1uS, LED=on
       goto $+1         ; + 2uS = 3uS
       goto $+1         ; + 2uS = 5uS
       goto $+1         ; + 2uS = 7uS
       goto $+1         ; + 2uS = 9uS
       decfsz _Cycles,f ; + 1uS = 10S    
       goto _Pulse40    ; + 2uS = 12uS
       return           ; Return to caller    
    ENDASM
    
    ' Generate "Cycles" number of ~38.4kHz pulses
    ASM
    _Pulse38
       bcf IRTX,PIN     ; 1uS, LED=on
       goto $+1         ; + 2uS = 3uS
       goto $+1         ; + 2uS = 5uS
       goto $+1         ; + 2uS = 7uS
       goto $+1         ; + 2uS = 9uS
       goto $+1         ; + 2uS = 11uS
       goto $+1         ; + 2uS = 13uS   
       bsf IRTX,PIN     ; 1uS, LED=on
       goto $+1         ; + 2uS = 3uS
       goto $+1         ; + 2uS = 5uS
       goto $+1         ; + 2uS = 7uS
       goto $+1         ; + 2uS = 9uS
       nop              ; + 1uS = 10uS
       decfsz _Cycles,f ; + 1uS = 11S    
       goto _Pulse38    ; + 2uS = 13uS
       return           ; Return to caller    
    ENDASM
    
    OverFreq:
    Create one for whatever IR carrier freq you need, and just call them like this with PBP;
    Code:
    @ #define IRTX GPIO  ; Define port to use for IR out
    @ #define PIN 2      ; Define port pin to use for IR out
    
    INCLUDE "Freq.inc" ' 
    
      GPIO.2 = 1       ' IR LED off   -----|<|----/\/\/\----+5
      TRISIO.2 = 0     ' Output for IR signal
      CMCON = 7        ' Comparators disabled
      ANSEL = 0        ' A/D disabled
           
    Main:
      Cycles = 60      ' min 1, max 255
      CALL Pulse38
      GOTO Main
      
      END
    At 4MHz you won't be spot-on for every carrier frequency, but it will be close enough to work with pretty much any off-the-shelf IR receiver.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Have you considered using an 8-pin 12F683 and generating a 38-KHz PWM signal output in the background? Use a interval counter and turn the PWM output on or off at the correct intervals by setting the CCPR1L duty cycle register to 50% or 0%.

    Regards, Mike
    Last edited by Mike, K8LH; - 23rd April 2010 at 18:12.

  8. #8
    Join Date
    Apr 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Thanks for all the help and suggestions.

    Bruce, I tried your suggestion and it works great!

    Regards,

    Alan Parekh

    Last edited by Archangel; - 31st July 2010 at 08:04. Reason: Delete link

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts