40 KHz burst


Closed Thread
Results 1 to 5 of 5

Thread: 40 KHz burst

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Thanks for your response, I did try, but something very odd happens, I changed it to an infinite loop to produce a frequency that I can measure:

    Loop:
    Toggle PulsePin
    @NOP
    @NOP
    @NOP
    @NOP
    @NOP
    @NOP
    @NOP
    @NOP
    @NOP
    @NOP
    GOTO Loop

    But for some reason, no matter how many @NOP I add, the frequency does not change and stays at 62.5 KHz

    Any Ideas?

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


    Did you find this post helpful? Yes | No

    Default

    This will get you spot-on 40kHz with a 4MHz oscillator.
    Code:
      Cycles VAR BYTE 
      TRISIO.0=0  ' make pin an output first
      GOTO Main   ' jump over Pulse routine to Main
    
     ' @ 4MHz generate Cycles number of 40kHz pulses
    asm
    _Pulse
       bsf  GPIO,0 ; change to whatever port pin you have available
       goto $+1    ; 2uS per GOTO $+1
       goto $+1
       goto $+1
       goto $+1
       goto $+1     
       bcf  GPIO,0
       goto $+1 
       goto $+1
       goto $+1
       goto $+1
       goto $+1
       decfsz _Cycles,f
       goto _Pulse  ; 25uS total for 40kHz carrier
       RETLW 0      ; return to CALLing routine
    ENDASM	  
    
    Main:
      Cycles = 8    ' number of carrier cycles to generate
      CALL Pulse
      PAUSEUS 24
      GOTO Main
      END
    Just enter the number of carrier cycles you need to generate in the Cycles var, and
    CALL the routine.
    Regards,

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

  3. #3
    Join Date
    Jul 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Thank you both a million for your help, I had done it with ASM and ENDASM but not as elegant as Bruce did, I just coded the delay using NOPs and the the eight pulses hard coded.

Similar Threads

  1. What's the best way to output 30 to 40 kHz from a 12F683 pin?
    By fizyxman in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st June 2009, 00:08
  2. Resonator Suppliers for 40 MHz?
    By mcphill in forum General
    Replies: 5
    Last Post: - 23rd January 2009, 02:05
  3. with 40 MHZ osc serin2 not work
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th August 2006, 22:56
  4. 40 kHz wave
    By RUBiksCUbe in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 14th December 2005, 20:01
  5. Catching 12 khz
    By SuB-ZeRo in forum Schematics
    Replies: 4
    Last Post: - 15th June 2005, 07:11

Members who have read this thread : 0

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