Connect with us

PIC16F877, 250Hz PWM

Discussion in 'Microcontrollers, Programming and IoT' started by aymensmurf, Mar 14, 2016.

Scroll to continue with content
  1. aymensmurf

    aymensmurf

    28
    0
    Mar 14, 2016
    Hi,
    I need 250Hz PWM out of a 20MHz clock.
    I'm using PIC16F877.
    any help ?
     
    Last edited by a moderator: Mar 14, 2016
  2. Arouse1973

    Arouse1973 Adam

    5,164
    1,080
    Dec 18, 2013
    Firstly welcome to EP. Secondly, it's quite a good idea to give as much information as possible of your requirements. Unfortunately you haven't. Questions I would like answered are :

    1) What language are you programing in?
    2) What is the % of duty cycle you require?
    3) How far have you got already yourself?

    And out of interest what's the project, anything interesting?

    Thanks
    Adam
     
  3. Minder

    Minder

    2,922
    615
    Apr 24, 2015
  4. aymensmurf

    aymensmurf

    28
    0
    Mar 14, 2016
    1) What language are you programing in?
    ->C
    2) What is the % of duty cycle you require?
    ->50%
    3) How far have you got already yourself?
    ->so far, I'm doing everything using the delay function.

    And out of interest what's the project, anything interesting?
    ->I'm trying to command the speed of a subway, using three Pulses, every pulse command a Thyristor.
    The thing is, the pulses have to be "=1 in 50us and =0 in 150us" in a 4ms periode.

    (srry, my english is kinda bad)

    Thanks
     
  5. aymensmurf

    aymensmurf

    28
    0
    Mar 14, 2016
  6. Minder

    Minder

    2,922
    615
    Apr 24, 2015
    Then you may have to use a low freq clock in such as external osc or crystal input, I have used the 32khz watch crystals for some low freq apps to run TMR1.
    I would think the 16F877 has this feature.
    M.
     
  7. aymensmurf

    aymensmurf

    28
    0
    Mar 14, 2016
    #M.
    I think i have to use a 4Mhz external osc to get 250Hz PWM.
    and that won't help, coz the program will go slow.
     
  8. Minder

    Minder

    2,922
    615
    Apr 24, 2015
    Yes of course, I was thinking of capture, you can go down to 1.2Khz with 20mhz system clk is that too high? What is the application?
    M.
     
  9. Alec_t

    Alec_t

    2,757
    733
    Jul 7, 2015
    :confused: I make that a 200uS period (5kHz) with a 25% duty cycle. Or does the "1 in 50uS" and "0 in 150uS" relate to the pulse rise and fall times, respectively?
     
  10. BobK

    BobK

    7,673
    1,684
    Jan 5, 2010
    There should be no problem doing that using delays. 50uS is 250 instruction times.

    Bob
     
  11. aymensmurf

    aymensmurf

    28
    0
    Mar 14, 2016
    I'm trying to command the speed of a subway, using three Pulses, every pulse command a Thyristor.
    The thing is, the pulses have to be "=1 in 50us and =0 in 150us" in a 4ms periode.
     
  12. aymensmurf

    aymensmurf

    28
    0
    Mar 14, 2016
    the problem using the delay is that the cpu lose some time (us) repeating the (loop, for ... do, while(), if () ).
     
  13. Alec_t

    Alec_t

    2,757
    733
    Jul 7, 2015
    Can you explain that?
     
  14. aymensmurf

    aymensmurf

    28
    0
    Mar 14, 2016
    the number of pulses changes with the adc value
     

    Attached Files:

  15. BobK

    BobK

    7,673
    1,684
    Jan 5, 2010
    Then you need to use interrupts. Determine when each pulse starts and stops and use the timer to interrupt at those times and toggle the outputs.

    Bob
     
  16. aymensmurf

    aymensmurf

    28
    0
    Mar 14, 2016
    it will get really really complicated to do interrupts for every pulse
     
  17. BobK

    BobK

    7,673
    1,684
    Jan 5, 2010
    Then I guess you should just give up.

    Seriously, though:

    If the pulses are all on increments of 50uS you can set an interrupt to occur every 50uS and decide what needs to be done at each interrupt. This would be less complicated, but more overhead. How much of the processor time is needed for the other tasks?

    Bob
     
  18. aymensmurf

    aymensmurf

    28
    0
    Mar 14, 2016
    for UART, LCD and 2 ACD
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-