Need to get 4 independently controllable frequency outputs, PBP can do that?


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Need to get 4 independently controllable frequency outputs, PBP can do that?

    The setup is as follows, there is a chip, PIC16F886, which does a lot of thing - updates 1602 LCD, monitors user input, endstops, issues enable/disable statement to motors, etc. Chip is quite busy, I want to say that.

    So I also need to have square wave outputs in say 50Hz-10Khz range, to control speed of stepper motors. Need at least 4 outputs, with independent control. Frequency precision and number of steps is not that important - having say 32 fixed frequencies in that whole range will be enough.

    The 1st idea is to use a PIC chip with 4 channel built-in PWM generator, but you can't set their frequencies independently and also minimal range is quite high - around 400-500Hz, depending on chip speed.

    The 2nd idea is to use ready modules like AD9833. Price is negligible, they cost $1.5 in china. But they require quite a lot of programming.

    The 3rd idea is to use CD4536B or similar timers (say CD4541), feed their input from HPWM output of MCU and use independent control to get desired frequencies. While there will be no such wide choice of frequencies as in case of AD9833, "programming" is straightforward and very simple.

    Another idea is to mod DT's multi-channel PWM into outputting not different duty cycle, but different frequencies. But that is beyond my knowledge of PBP

    Any other ideas?
    Last edited by CuriousOne; - 5th April 2020 at 08:20.

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    If you're not married to the PIC16F886, there are newer MCUs that might be able to meet your goals. Assuming a 50% duty cycle is desired, let's look at all the available Functions found on various PICs that would be capable of generating a square wave output.

    1 - Of course, CCP using the PWM function
    2 - Some PICs offer separate PWM SFRs in addition to the CCP
    3 - CLC: using the Flip Flop Mode, any timer could be fed into a CLC to generate PWM output
    4 - Timers where the Interrupt Handler Toggles the output
    5 - Numerically Controlled Oscillator (NCO)
    6 - Signal Measurement Timer
    7 - If you don't need all PWM outputs simultaneously, Peripheral Pin Select can change which pins output the PWM

    There are probably at least 1 or 2 I'm missing, but the point is to think outside the CCP box. Some PICs have upwards of 4 CCP modules, some up to 4 CLC, some have as many as 10 Timers, short of the new PIC18FxxQ43, only 1 NCO is available. You may be able to mix and match to achieve your goals.

    In addition to more Functions, newer PICs have more stable Internal Oscillators, Peripheral Pin Select, and are almost always way cheaper. You can use Microchip's Part Selector Guide (or whatever they call it) to find PICs that meet your needs:

    https://www.microchip.com/ParamChart...branchID=30048
    Last edited by mpgmike; - 5th April 2020 at 18:11. Reason: fixed typos

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    If you can accept frequencies up to only 1KHz, then the PCA9685 chip can output 16 pwm channels and is controlled by I2C bus.

    Ioannis

  4. #4
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    I need 4 outputs simultaneously, at different frequencies and w/o putting any load into "main" code execution.

    PCA9685 can output different dutycycle, but not frequency. There are a lot of such IC's with adjustable separate duty cycle, but not frequency (I even have 48 channel monster - LT8500)

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    The only suitable chips I've found are FM synthesis chips from early computer soundcards, like Yamaha YMF262 or AY-3-8910 But they require extra periphery and are loaded with unnecessary bells and whistles. Looks like CD4536B (4 of them) is the best choice so far.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    Nice chip this seems. But could not figure out how to use it as an PWM.

    Ioannis

  7. #7
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    I don't need PWM, I need frequency

  8. #8
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    4 separate PIC's with NCO modules. Done..... Why add unnecessary hardware?
    Dave Purola,
    N8NTA
    EN82fn

  9. #9
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    Quote Originally Posted by Dave View Post
    4 separate PIC's with NCO modules. Done..... Why add unnecessary hardware?
    I have a project I was using 3 PICs for 3 NCOs. I updated it adding a touch screen to replace buttons & LEDs, and while at it, replaced 3 PICs with a single PIC18F27Q43 (have to use MPLABX & XC8 since PBP doesn't yet cover that part). That still leaves one more NCO for you.

  10. #10
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    and 3 extra PIC chips does not count as extra hardware, but CD4536 does?

  11. #11
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    Please,Please explain how you are going to get a single CD14536 to support 4 independent frequency's. I must be REAL stupid.....
    Dave Purola,
    N8NTA
    EN82fn

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    Either 4 pics or 4 CD4536...

    He meant that in either case you need 4 chips. PIC's need also programming but CD.. need some parts.

    Ioannis

  13. #13
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    CD does not need any extra part. Frequency input of all 4 is connected to PICs HPWM output, which allows to do some extra things - since all these frequencies will be driving stepper motors, having them controlled by master clock (HPWM) will allow to make smooth startup and stopping

  14. #14
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    I still think you can do it with Timers. For a Timer 2/4/6, adjust the PR2 for your frequency. For Timer 1/3/5, adjust TMR1H_L for your frequency. Clear the IF & Toggle the output, and reset TMR1H_L in the ISR. For TMR2/4/6, you don't even need to reload PR2. Newer PICs with HLT can to that in the background without so much as an interrupt.

  15. #15
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Need to get 4 independently controllable frequency outputs, PBP can do that?

    Yes, I agree, technically that is possible. But this requires additional programming (not in PBP as I guess) - skills which I do not posses. And I'm immediate result oriented guy - If installing single IC will solve the problem, I'll prefer that way, instead learning C or ASM to do same task.

    I've already ordered CD4536B's so let's see how it turns out.

Similar Threads

  1. Single PIC to Blink 5 LEDs Independently?
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 68
    Last Post: - 18th July 2015, 17:56
  2. 4 x PWM outputs
    By Scampy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th February 2012, 07:40
  3. help with multiple outputs...
    By rickvan in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th November 2007, 18:34
  4. frequency meter in PBP
    By savnik in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 13th June 2007, 07:34
  5. PIC16F62X outputs
    By Deadeye in forum General
    Replies: 6
    Last Post: - 31st May 2005, 22:20

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