View Full Version : Need to get 4 independently controllable frequency outputs, PBP can do that?
CuriousOne
- 5th April 2020, 06:55
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?
mpgmike
- 5th April 2020, 17:09
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/ParamChartSearch/chart.aspx?branchID=30048
Ioannis
- 5th April 2020, 17:18
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
CuriousOne
- 5th April 2020, 20:21
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)
CuriousOne
- 5th April 2020, 20:23
The only suitable chips I've found are FM synthesis chips from early computer soundcards, like Yamaha YMF262 or AY-3-8910 :D 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.
Ioannis
- 5th April 2020, 21:18
Nice chip this seems. But could not figure out how to use it as an PWM.
Ioannis
CuriousOne
- 6th April 2020, 05:49
I don't need PWM, I need frequency :)
Dave
- 6th April 2020, 15:07
4 separate PIC's with NCO modules. Done..... Why add unnecessary hardware?
mpgmike
- 6th April 2020, 16:46
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.
CuriousOne
- 6th April 2020, 22:02
and 3 extra PIC chips does not count as extra hardware, but CD4536 does? :D
Dave
- 7th April 2020, 16:12
Please,Please explain how you are going to get a single CD14536 to support 4 independent frequency's. I must be REAL stupid.....
Ioannis
- 7th April 2020, 20:29
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
CuriousOne
- 8th April 2020, 05:42
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 :)
mpgmike
- 8th April 2020, 14:21
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.
CuriousOne
- 9th April 2020, 07:27
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.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.