sending a 120khz pwm with 50% duty cycle at several time(delay)


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2008
    Posts
    45

    Default sending a 120khz pwm with 50% duty cycle at several time(delay)

    hi all.i want to send the 120khz with 50% duty cycle pwm signal only for 1ms.how can i do it.i'm using pic16f877a.the following code show how the pic generate the pwm signal:

    define osc 8
    TRISC = 0 'PORTC all outputs

    main:

    PR2 = 15 'Load Period Register
    CCPR1L = 8 'Set 50% duty cycle
    CCP1CON = %1100 'PWM mode
    T2CON.2 = 1 'Start TIMER2

    goto main

    i only want my pic inject the pwm signal for only 1ms...please help me...

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The Hardware PWM is like the Energizer Bunny.
    It keeps going and going and ....
    And in the middle of the main loop, his going problem is getting really bad.

    Got to be something in there to disconnect the furry little b_______.

    A timer could work, a software loop could work. something to stop it after 1ms (maybe a PAUSE 1).

    Depends on what you want to shoot the Rabbit with.
    DT

  3. #3
    Join Date
    Aug 2008
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    thanx Darrel Taylor...did u mean this:

    define osc 8
    TRISC = 0 'PORTC all outputs

    main:

    PR2 = 15 'Load Period Register
    CCPR1L = 8 'Set 50% duty cycle
    CCP1CON = %1100 'PWM mode
    T2CON.2 = 1 'Start TIMER2

    PAUSE 1

    end

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Closer, but it seems to me, if you want a 1ms burst of 120Khz, you'll probably want lot's of them, and most likely timed with a Zero-crossing reference.

    Which if true, means you're trying to do X-10 stuff.

    Which if true, you might want to look at this thread ...

    XOUT and HPWM
    http://www.picbasic.co.uk/forum/showthread.php?p=20318

    Yes, I've just given you a sharp sword, with which to commit sepuku ... (a.k.a. Hari-Kari).
    DT

  5. #5
    Join Date
    Aug 2008
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    i really don't understand how to use the XOUT command.i just want to send the pwm signal at several time delay.lets say 1ms...so,is that correct if i use the following coding:

    define osc 8
    TRISC = 0 'PORTC all outputs

    main:

    PR2 = 15 'Load Period Register
    CCPR1L = 8 'Set 50% duty cycle
    T2CON.2 = 1 'Start TIMER2

    CCP1CON = %1100 'PWM on
    PAUSE 1 'generate 1ms burst
    CCP1CON = 0 'PWM off

    end

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    With the code above you'll only get a 1/2 ms delay...
    http://www.picbasic.co.uk/forum/showthread.php?t=558

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    With the code above you'll only get a 1/2 ms delay...
    Not necessarily true.
    If compiled with PM.exe which is NOT case sensitive. It'll do just fine at 8mhz.

    texas5,
    Much closer, but there's still one issue.
    That will work good for the first burst. But since timer2 is still running, the next time you try to send a burst, timer2 may have already past the PR2 value when you start the PWM. Then it will have to wait for it to roll over at 256 counts before it starts up the PWM again.

    That would cause the loss of up to 17 of the anticipated 125 cycles you would get during the 1ms period.

    After stopping the PWM you should also STOP and RESET Timer2 to 0 ...
    <br>
    DT

  8. #8
    Join Date
    Aug 2008
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    thanx skimask...thanx Darrel Taylor...your explanation seem clear to me.so i just need to set the 'T2CON.2 = 0' after stopping the pwm and set it to 'T2CON.2 = 1' back if i want to burst it one more time.

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Yes, but also set ...

    TMR2 = 0
    <br>
    DT

  10. #10
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    That would cause the loss of up to 17 of the anticipated 125 cycles you would get during the 1ms period.
    Which is not a deal-breaker as X-10 receivers only look for 48 cycles during a window that extends from ZC+250uS to ZC+900uS. Still, one should follow X-10's recommendations to start the 120kHz burst within ZC+100uS. You're already losing some of that window as the PIC is late detecting ZC on rising edges (assuming the ZC detector given in AN236).

Similar Threads

  1. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  2. PWM PIN(S), DUTY, CYCLE ?Plural possible?
    By earltyso in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th November 2007, 20:41
  3. HPWM the old fashioned way
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 19th November 2004, 19:09
  4. PWM _ Duty Cycle in Tenths
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 17th May 2004, 12:09
  5. Duty Cycle Dilemmas
    By crankshaft in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th February 2003, 12:40

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