PWM modules in PIC16F177* family

26 views
Skip to first unread message

David VB

unread,
Apr 3, 2024, 5:14:12 PMApr 3
to jallib
Hi there,

It appears that the PIC16F177* family have PWM modules named up to PWM12, which is not foreseen in Jallib

Example: PIC16F1777 or 1779 have:
PWM3, PWM4, PWM9, PWM10 : 10 bits PWM modules
PWM5, PWM6, PWM11, PWM12 : 16 bits PWM modules (with more functionnalities as 10-bit modules, such as four offset modes, and different operation modes)

Is there anything foreseen for those in Jallib ?

Kind regards,

David


Rob CJ

unread,
Apr 4, 2024, 1:12:22 PMApr 4
to jallib
Hi David,

In 2022 I added PWM5 and PWM6 like the previous pwm's.

What is foreseen is what is requested 🙂 (and there is a need for it).

So it can be straight forward to add the 10-bit PWM 9 and PWM 10 but not sure if there is a need for it.

For the 16-bit I think we need a complete new library, something like pwm16_hardware.jal and add more features. That may take quite some time. 

Do you - or does anybody else - have plans to use the 16-bit pwm with all its nice features?

Kind regards,

Rob






Van: jal...@googlegroups.com <jal...@googlegroups.com> namens David VB <pinhe...@gmail.com>
Verzonden: woensdag 3 april 2024 23:14
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] PWM modules in PIC16F177* family
 
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/ab0fbea9-025c-49bf-b37f-18159885fa2fn%40googlegroups.com.

David VB

unread,
Apr 5, 2024, 9:49:06 AMApr 5
to jallib
To be honest, in my application, I need 6 PWM signals.
Since they must be equivalent to one another, I will use some 16-bits modules but without those new features, and with a duty cycle defined with only the 10 MSB

So, as far as I am concerned, there is no need for a specific 16-bit PWM library now, but it would be a nice addition to the lib, just to keep its attractiveness in the future and avoid a technical debt when more and more PIC's will implement these new modules.  

(The same goes for the ADCC module, the new CLB module)

I cannot commit to write a specific library since I can never be sure to be ok with all of the rules of the style guide, not to be extensive in the funcitonnalities written, but I can offer to send here some libraries to serve as a starting point, if someone can review and amend them as needed.

Kr,

D.

Rob CJ

unread,
Apr 5, 2024, 12:51:32 PMApr 5
to jal...@googlegroups.com
Hi David,

When I took over the device file generation scripts of Rob Hamerling I also got all his - hundreds - of PIC samples and  because of that I do have a PIC16F1778 which is of the same family and has 6 PWM's (three 10-bit and three 16-bit) so I could give it a try if I can extend the current PWM library with the 16-bit addition providing the same basic functionality.

Not sure how long it will take but will start this weekend.

Kind regards,

Rob



Verzonden: vrijdag 5 april 2024 15:49
Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: [jallib] PWM modules in PIC16F177* family
 

Rob CJ

unread,
Apr 5, 2024, 1:49:43 PMApr 5
to jal...@googlegroups.com
Hi David,
 
I did a quick program change. 

I just extended the existing 6 standard pwm's to 12 and all compiles. In the sample program I am using pwm 3, 4, 5, 6, 9 and 11 since that is what the PIC16F1778 has on board so you may have changed the number for your PIC (that's why I made it up to 12).

Did not test it yet but you can give it a try. I attached a zip-file but not sure if it is blocked or not.

I will see if it works this weekend.

If the zipfile does not work I can send it via wetransfer.

Kind regards,

Rob




PWM_1_12.zip

Rob CJ

unread,
Apr 6, 2024, 4:40:46 AMApr 6
to jal...@googlegroups.com
Hi David,

Update. I did a test but it does not yet work for the 16-bit PWM's. I am in the process of getting it working.

Will give you an update as soon as I have more info.

Kind regards,

Rob

Verzonden: vrijdag 5 april 2024 19:49

Rob CJ

unread,
Apr 6, 2024, 1:55:46 PMApr 6
to jal...@googlegroups.com
Hi David,

I got it working. The nice thing about these 16-bit PWM's is that each has its own timer register. This means that the frequency can be set for each of these PWM's individually which is not the case for the 10-bit PICs that all seem to use Timer2. For the 10-bit you can only change the duty cycle individually.

I still need to clean things up and check with other PICs what the names of the PWM modules are.

For example PWM5 seems to be a 10-bit PWM for the PIC16F18323 but is a 16-bit PWM for the 16F1778. 

In the attached zip-file I only did the 10-bit and 16-bit modifications for  PWM5 and PWM6 and I only created the 16-bit PWM version for PWM11 and PWM12 so that at least you can use it for your project.

As said, I need to check other PICs to see for which modules there is overlap in the names  for 10-bit and 16-bit.

I could not test PWM12 since my 16F1778 does not have it but I assume it works.

Let me know if it works for you too.

Thanks

Kind regards,

Rob



Verzonden: zaterdag 6 april 2024 10:40
PWM_1_6.zip

David VB

unread,
Apr 12, 2024, 12:44:38 PMApr 12
to jallib
Hi Rob,

Thanks for your efforts !
(No matter what, I cannot subsribe to the emails again.... and have to check directly the list on the website....  that's why I didin't see your messages before)

This week-end, I hope to be able to experiment more with this project.
I also openend a discussion on eevblog for a rather totally different subject (but it's about the same project)

In short, I have, from one PIC, to drive six channels that may use up the 1.2 or 1.5 A (very worst case).
I MUST have the voltage varying between around 2 V and around 5 V.    PWM is allowaed to control, but the ouptut voltage must be somewhat clean
And now I am struggling: ADC to control a switching regulator, or (filtered) PWM to control a emitter-follower transisotr..... 
Tough choice....

A lot of experimentation foreseen this week-end....

Kind regards,

David

Rob CJ

unread,
Apr 12, 2024, 1:04:37 PMApr 12
to jal...@googlegroups.com
Hi David,

Strange that you are not notified. On Google Groups it says that you would get an e-mail every time something happens.

The PWM should work since I tested all your channels except for PWM12 since I do not have that PIC but the code is the same as PWM11.

I am still in the process of cleaning up some code. Next to that I removed the 16-bit code for PWM7, 8, 9, and 10  (I mention that in the pwm_common.jal file) since they do not yet exist for 16-bit, only 10-bit. I do that because I apply YAGNI (You Ain't Gonna Need It) and only add code for which the hardware exists.

I think I will test the other PWM channels this weekend and will then upload the final version for PWM1..PWM12 but let me know if you got it working.

Last week I discovered something new. There are PICs with 10-bit PWM where you can assign another timer to the PWM output than only timer 2 so that each PWM (like the 16-bit version) can have a different frequency. Since there is no request for that I will not create that now.

About your project. If you use an emitter follower you will not be able to create 5 Volt due to the voltage drop. You almost need to make some kind of buck converter ...

Good luck with your project.

Kind regards,

Rob


Verzonden: vrijdag 12 april 2024 18:44

David VB

unread,
Apr 14, 2024, 12:26:48 PMApr 14
to jallib
About the voltage drop, I can live with that up to 500 or even 600 mV.
The problem is the dissipation of the transistor if it has to pass 1.2 A with a drop of 3 V as VCE  (Voltage rail = 5 V, Vbase = VEmitter = 2 V).   This is more than 3.5 W to dissipate.
Multiply this by 6 channels.....  

From there, on the eevblog forum, we discuss the possibility to use a small fake-LM2596 (actual LM2576) switching module from chinese resellers, one per channel..
I could adjust them with the help of one DAC buffered by an OPA configured as Unity gain (all within the PIC).

Problems:
- There are not enough independant 10-bit DAC's (only 3) and OPA's (only 3) in the PIC16F1778 I use for 6 channels
- I am still struggling to understand exactly how to drive the ADJ (or Feedback) pin of the regulator....



This is off topic here, but if you got ideas, feel free to join the discussion on weblog

(For the mails, strangely, I only receive a notification when *I* and only me post a subject to either list (jallist or jallib) )

Rob CJ

unread,
Apr 14, 2024, 12:49:32 PMApr 14
to jal...@googlegroups.com
Hi David,

I did some testing this weekend and made some fixes to the PWM files. I uploaded them to GitHub so they should be part of the next bee-package.

About your design. I assume that you want to control the ADJ pin with a DAC? I do not think it will work since the ADJ is used to continuously keep the output voltage at the right level and that can only be done realtime. 

What you could do is use a digital potentiometer (but I assume the resolution is too low) to feedback - a part of - the signal to the ADJ input.

Good luck figuring it out.

Kind regards,

Rob


Verzonden: zondag 14 april 2024 18:26
Reply all
Reply to author
Forward
0 new messages