40 kHz wave


Closed Thread
Results 1 to 13 of 13

Thread: 40 kHz wave

Hybrid View

  1. #1
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest

    Default 40 kHz wave

    I need to pulse an LED signal at 40 kHz for an IR project, but
    PULSOUT A1, 40
    didn't work on a 4 MHz 12F683, and the manual said that a pic running at 4 MHz has a PULSOUT period of 10 us. The datasheet (http://pdf.alldatasheet.com/datashee.../PNA4614M.html) of the IR detector I am using said that the typical signal width is 200 us.
    Does the PIC not actually pulse out at 10 us intervals?

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink with a little help from peripherals

    Hi, Rubik

    a 555 running at 40 khz would easily solve your headache ...without any program timing difficulties ...

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  3. #3
    Join Date
    Sep 2005
    Location
    Dayton, Ohio
    Posts
    72


    Did you find this post helpful? Yes | No

    Default The peripherals are already built-in!

    Just use the PIC12F683's internal hardware PWM peripheral. This way you can easily generate the 40KHz, turn it on and off, adjust the duty cycle and it runs in the background. The datasheet will show you exactly how to set it up.

    Personally I don't like using the HPWM command in PB Pro because its too limited. It's easier to do it by manually setting the registers.

    This is exactly how I generate the 40KHz IR for my lasertag systems.

    'register setup (this is for a 16F684, so it may need to be modified slightly for your chip)

    PR2 = 49 'PWM Period 40K=49
    CCPR1L = 10 'PWM Duty Cycle
    T2CON = 4 'Timer2 = ON; Prescale = 1:1
    CCP1CON = 0 'PWM module off

    'generate 1ms 40KHz pulse

    CCP1CON = 12 'PWM ON
    PauseUS 1000
    CCP1CON = 0 'PWM OFF
    Last edited by milestag; - 10th December 2005 at 16:07.
    Jim Robertson
    "MilesTag" DIY Lasertag
    www.lasertagparts.com/mtdesign.htm
    Dayton, Ohio

  4. #4
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Default

    Woah I didn't know about the HPWM command. I'm still learning PBP. It seems like it will do the trick in my case.

    I don't like using 555s because they heat up and their output changes.

    I think that for a 40kHz square wave I need to say:
    HPWM 1,127,40000
    Right?
    Last edited by RUBiksCUbe; - 11th December 2005 at 01:25.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Nop! HPWM will not do the job in this case... look in the PBP manual for the specific limitation on different crystal speed.

    in your case you must write directly to the internal register related by the PWM module. look section 11 of the datasheet and look to the Milestag's example. I'm not a fan of HPWM myself too.

    555's are not as this bad.. it's working great but it's still a RC oscillator ... like the PIC internal one. So both will shift a litlle bit with the temperature variation.

    There's still some easy circuit to build with some CMOS inverter OR Route the CLKOUT of the PIC to a frequency divider OR.... OR...
    Last edited by mister_e; - 11th December 2005 at 09:17.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Default

    How do you write stuff to the internal registers? I've tried to set up my PIC as a counter before but I didn't know how to, and the COUNT command didn't really work too well. I'm looking through my PICs datasheet (12F683) and I don't understand what it's talking about. What is the CCP1CON register? It mentions it a lot in the PWM section.

    It says that in order to set the PWM period I need to the PR2 register. How/What do I write?
    Last edited by RUBiksCUbe; - 11th December 2005 at 15:27.

Similar Threads

  1. To Generate Sine Wave Using PCPWM of PIC18F4331 (Issue)
    By Cyborg in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd March 2014, 13:39
  2. 40 KHz burst
    By aherrera in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th November 2009, 22:36
  3. 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
  4. Sine wave
    By Darrenmac in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 18th May 2009, 03:31
  5. PIC 16F877 I2C communications
    By sigmoideng in forum General
    Replies: 7
    Last Post: - 13th July 2007, 10:28

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