how can i stop the pic from sending a PWM???


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

    Default how can i stop the pic from sending a PWM???

    hi all.my pic16f877a did generate the 125kHz with 50% (get from this forum,thanx) but i don't know how to turn it off.what i mean is if i push the button 1 pic will generate the pwm & when i push the button 2 pic will stop from generate it (on/off the PWM).

    here is my coding:

    define osc 8
    TRISC = 0 'PORTC all outputs
    TRISB.5 = 1
    TRISB.4 = 1

    push1 var portb.5
    push2 var portb.4

    main:

    if push1 = 0 then inject
    if push2 = 0 then notinject

    goto main

    inject:

    if push2 = 0 then notinject

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

    if push2 = 0 then notinject

    goto inject

    notinject:

    if push1 = 0 then inject

    ????????????????????????????
    ????????????????????????????
    ????????????????????????????

    if push1 = 0 then inject

    goto notinject

    i don't know what to fill in the "??????"....i have try to set the TMR2=0, CCP1CON=0 & T2CON.2=0 but it did not work...help me please....

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


    Did you find this post helpful? Yes | No

    Default

    This should work.
    Code:
        DEFINE OSC 8
        TRISC.2 = 1  ' CCP1 pin stays input intil PWM on
        TRISB.5 = 1  ' button input (external pull-up with switch to ground)
        Push1 var PORTB.5
        
        PR2 = 15 'Load Period Register
        CCPR1L = 8 'Set 50% duty cycle
        CCP1CON = %1100 'PWM mode
        T2CON.2 = 1 'Start TIMER2
        
    Main:
      TRISC.2=Push1 ' if RB5=0 CCP1 pin is an output, PWM=on  
      GOTO Main     ' if RB5=1 CCP1 pin is an input, PWM=off
    The PWM module is still operationg so you shouldn't have any glitches in the signal, and
    you only need one button to control it.

    When the CCP1 pin is switched to an input, the PWM signal is disconnected. When it's
    flipped to an output it's back on.
    Regards,

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

  3. #3
    Join Date
    Aug 2008
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    wow.simple solution.haha.thanx a lot bruce.but are your coding mean i need to hold the push button to PWM on & release the button to PWM off...or push the button once to PWM on & push once again to PWM off????

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by texas5 View Post
    wow.simple solution.haha.thanx a lot bruce.but are your coding mean i need to hold the push button to PWM on & release the button to PWM off...or push the button once to PWM on & push once again to PWM off????
    Read the code! Do you see anything in that code saving the state of the button to remember for the next time the loop checks the buttons state?
    The bit in the TRIS register follows the state of the push button...simple as that...just like it's written...

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


    Did you find this post helpful? Yes | No

    Default

    Yep. Like Ski said, that's how it works.

    Here's another flavor.
    Code:
    Main:
      IF Push1=0 THEN
         GOSUB ChkState
      ENDIF
      GOTO Main    
      
    ChkState:
      WHILE Push1=0       ' wait for button release
      WEND
      TRISC.2=TRISC.2 ^ 1 ' toggle TRISC.2 on button release
      RETURN
    Endless simple possibilities.
    Regards,

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

  6. #6
    Join Date
    Aug 2008
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    thanx guys.it work....

Similar Threads

  1. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  2. Sending Commands from Visual Basic about IR to Pic
    By tne_de in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th April 2009, 06:09
  3. Replies: 9
    Last Post: - 8th October 2008, 11:15
  4. Sending data from 1 pic to other pic
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th September 2007, 00:51
  5. VB sending serial data to PIC
    By Tissy in forum Serial
    Replies: 7
    Last Post: - 8th March 2006, 18:31

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