PDA

View Full Version : Help Choosing the correct PIC for 2 Channel PWM



JimAvanti
- 14th June 2016, 19:57
Hi,
I could use some help choosing the correct PIC. I need to have 2 independent PWM outputs to be used for generating two distinct tones. The only other thing required is to have two input pins to trigger the PWM outputs and a few inputs for dip switches to select the frequencies. I have spare 16f1938, 18F14k22 chips. I would like to keep the pin count as small as possible. The 16f1938 shows 3 ECCP ports, which I thought was all you need, but then it shows 0 for stand alone PWM. The Hardware PWM seems confusing to me once you go over one output so I want to make sure I am at least stating with a micro that can do what I need to do since I don’t really have enough hair left to pull out.
I am using PicBasic 2.6c

Thanks,
Jim

HenrikOlsson
- 14th June 2016, 20:23
Hi Jim,
As far as I can see the 1938 has three ECCP modules (for which HPWM might not work, I don't know for sure) AND two standard CCP (for which the HPWM command "should" work). And in the event you should find that HPWM doesn't work it's not that hard to setup manually - and it gives you more "power", like being able to have more than 8bits of resolution. I'll promise to help you out if you need, just make a post here.

So, if you already have the 1938 on hand and it's suitable from other perspectives then I'd use that.

/Henrik.

JimAvanti
- 15th June 2016, 18:45
Thanks Henrik. I will give it a try and let you know if (When?) I run into problems.

Jim


Hi Jim,
As far as I can see the 1938 has three ECCP modules (for which HPWM might not work, I don't know for sure) AND two standard CCP (for which the HPWM command "should" work). And in the event you should find that HPWM doesn't work it's not that hard to setup manually - and it gives you more "power", like being able to have more than 8bits of resolution. I'll promise to help you out if you need, just make a post here.

So, if you already have the 1938 on hand and it's suitable from other perspectives then I'd use that.

/Henrik.

peterdeco1
- 16th June 2016, 16:52
I don't think you will be able to generate 2 distinct tones. From the PBP manual:

Frequency is the desired frequency of the PWM signal. On devices
with 2 channels, the Frequency must be the same on both channels.

HenrikOlsson
- 16th June 2016, 18:23
That's a very valid point, one that I totally missed when reading Jims initial post, sorry about that!

That limitation comes from the fact that the CCP module(s) are (historically) tied to the same timebase so they need to have the same output frequency. Thankfully things have changed over the years and the CCP modules on the 16F1938 can individually be assigned any of TMR2/TMR4/TMR6 as their timebase. It does however mean that HPWM is out (at least I Think it is) and you'll need to setup the CCP modules manually.

/Henrik.

JimAvanti
- 21st June 2016, 21:13
So that means directly writing to the correct ports might do what I want? I didn't start testing yet. I did purchase an LED 3 channel 8-bit PWM driver to try (TLC59731DR). I thought it was SPI, but it isn't, and It also controls duty cycle. There are plenty of external devices available that look like they might work, but I'll wait until after I rule out the 16F1938 as an option.

Thanks


That's a very valid point, one that I totally missed when reading Jims initial post, sorry about that!

That limitation comes from the fact that the CCP module(s) are (historically) tied to the same timebase so they need to have the same output frequency. Thankfully things have changed over the years and the CCP modules on the 16F1938 can individually be assigned any of TMR2/TMR4/TMR6 as their timebase. It does however mean that HPWM is out (at least I Think it is) and you'll need to setup the CCP modules manually.

/Henrik.

HenrikOlsson
- 21st June 2016, 21:49
So that means directly writing to the correct ports might do what I want?
Well, not the ports but the registers for the CCP modules(s), yes. Two-three registers per module maby, so four to six lines of code to have both running. The "trick" is to figure out what to write to the registers, the datasheet is key.


I did purchase an LED 3 channel 8-bit PWM driver to try (TLC59731DR). I thought it was SPI, but it isn't, and It also controls duty cycle.
No, it's not SPI, more "like" async serial and yes the dutycycle of the fixed frequency output IS the only thing it controls - that's how it dims the LEDs.

It's not really clear what exactly you want to do. In the first post you mention generating two distinct tones but then you're talking about LED dimmers. Can you explain what you're trying to achieve?

JimAvanti
- 22nd June 2016, 18:26
Yes, Registers are what I meant. I just ordered a few PIC10F322 & 12F1840 chips (They are very small - 6 & 8 pin). I figure the best way to be sure I get the tones I want at a volume I expect would be to use one of these for each tone. One input pin to trigger, one output for the sound, and either two inputs to select 1 of 4 pre-set tones or one analog input to select a range of tones. the 6-pin SOT package wouldn't take up much board space and the price is right. I still plan on playing around with the CCP module of the 1938, but using a couple of these small chips seems to be the easiest way to go for this project.

I thank you for your help and will let you know the outcome of the testing.

Jim



Well, not the ports but the registers for the CCP modules(s), yes. Two-three registers per module maby, so four to six lines of code to have both running. The "trick" is to figure out what to write to the registers, the datasheet is key.


No, it's not SPI, more "like" async serial and yes the dutycycle of the fixed frequency output IS the only thing it controls - that's how it dims the LEDs.

It's not really clear what exactly you want to do. In the first post you mention generating two distinct tones but then you're talking about LED dimmers. Can you explain what you're trying to achieve?

CuriousOne
- 29th June 2016, 10:08
16F876A has 2 independent pwm channels, and I'm using them just fine.