3 channel PWM with customize duty cycle


Closed Thread
Results 1 to 40 of 57

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 3 channel PWM with customize duty cycle

    Hi,
    OK, so you're saying that it works in the simulator but not in the real world? Or does it not work in the simularor either?

    What do YOU think might be the problem and what have YOU tried in order to figure it out?

    Have you:
    A) Checked the datasheet to see if there's anything specific with PortB.3?
    B) Tried another pin, just as an experiment, to see if the logic of the code works?
    C) Connect a LED to PortB.3 and write code to turn that on and off so you KNOW that the pin actually works and is configured properly
    D) Disconnect the external logic and measured on the pin directly.
    E) Anything else?

    Let me know what you've tried and what the results are.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: 3 channel PWM with customize duty cycle

    Hi,
    its works on simulator for all phases but in real world only phase 3 as i mention before.

    i think its the pin portb.4 and portb.3 on the PIC16F737 but im not sure.

    A) yes, i have check the function of portb.3 and portb.4 -

    based on the datasheet
    portb.3:
    -Digital I/O.
    -CCP2 capture input, compare output, PWM output.
    -Analog input channel 9.
    portb.4:
    -Digital I/O.
    -Analog input channel 11.

    since i declare portb.5 as the ccp3, should be no problem for portb.3.
    portb.4 same function as i use for phase 1 and 2

    B)i tried another pin which is portb.2 and portb.3, still not function well (seem like it wont toggle properly)

    C)havent done it yet. will test using it next week and feedback to you again.

    D)Yes, i measure part A and B directly to the pin PIC

    btw, i test it on the breadboard. havent change the breadboard yet but i dont think its the reason.

    i will test it again friday next week and feedback to you.
    if u have any more idea on testing error please let me know

    photoelectric

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 3 channel PWM with customize duty cycle

    Hi,
    So it says that PortB.3 can be the output of CCP2 but that's likely not the problem because you get the PWM from CCP2 on PortC.1, correct?

    It also says that it (and PortB.4) can be an analog input. Have you investigated that part? Usually when the PIC starts up it defaults to analog inputs. In order to make them work as digital outputs you need to turn the analog functions off.

    If you look at the PortB section of the datasheet you'll see in table 5-4 that they mention the ADCON1-register. You'll also see that it defaults to all zeros on startup. If you then turn to the Analog-to-digital converter section of the datasheet and look at the ADCON1 register you'll see that all zeros mean that AN0-AN11 are configured as analog inputs. This needs to be changed in order for the pin to function as a digital pin.

    The other pins you're using (PortC.0, PortC.3, PortC.5 and PortC.6) doesn't have any analog circuitry so they work out of the box but PortB.3 and PortB.4 (as well as PortB.2 that you tried) DO have analog circuitry which is most likely the reason for them not to work as you expect.

    The fact that it works in the simulator only illustrates that the simulator isn't doing what the real PIC does....

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: 3 channel PWM with customize duty cycle

    hi,

    im back

    tq for your advice. i change the port b to digital by just adding:

    adcon1 = 7

    then it works fine. Actually, i only follow the example in the PBP book and i dint really understand the definition of it, how the PIC change the analog port to digital port and so on.
    Can you help explain about the ADCON1 command and what if i want to chnge ONLY portb.4 and portb.3 to digital??
    what should i do??

    thanks

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 3 channel PWM with customize duty cycle

    Hi,
    ADCON1 is not a command, it's register in the PIC which is used to control the ADC. When you do ADCON1 = 7 you set that register to 7 (which for the 16F737 sets AN8-13 to digital and leaves the rest as analog).

    As I tried to tell you in my previous response you need to open up the datasheet for the PIC and look at the ADC section in general and specifically the description of the ADCON1 register. You'll find that setting just PortB.3 and PortB.4 to digital isn't possible.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: 3 channel PWM with customize duty cycle

    Hi,

    Tq again,
    can i say if i want set AN9-AN13 to digital , i need to set the register value ADCON1 = 6 ?
    sry for this newbie question, still trying to learn this PIC things etc..
    correct me if im wrong

    thanks

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 3 channel PWM with customize duty cycle

    Hi,

    That is correct.

    Since you're leaving some of the pins as analog inputs I'm guessing you're going to use them as that - ie analog inputs. In that case it might be needed to set the bits 4-7 in ADCON1 properly as well. Sometimes it's easier to "see" what you're doing if you write the value in binary form, like:
    Code:
    ADCON1 = %10000110   'Right justified result, VDD/VSS used as Vref, AN9-13 set to digital
    /Henrik.

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