Page 1 of 2

Simple PWM Module Example

PostPosted: Sat Apr 04, 2015 8:35 pm
by ohararp
I am dusting off my firewing hardware (Pic24) and was wondering if there is a simple PWM library example?

Re: Simple PWM Module Example

PostPosted: Mon Apr 06, 2015 7:08 am
by Coccoliso

Re: Simple PWM Module Example

PostPosted: Mon Apr 06, 2015 4:02 pm
by bitfogav

Re: Simple PWM Module Example

PostPosted: Mon Apr 06, 2015 4:20 pm
by ohararp
b.o.g, Ah great link. I saw the first post about the other forum reference. However, the library reference was exactly what I was looking for! Thanx Ryan

Re: Simple PWM Module Example

PostPosted: Mon Apr 06, 2015 4:57 pm
by bitfogav
No problem, it's a simple library to use with only 4 routines :) without going off topic how's the RGB123 Ryan? I still have mine ;)

Re: Simple PWM Module Example

PostPosted: Mon Apr 06, 2015 5:09 pm
by ohararp
b.o.g. thanks for the help. Firewing looks like its growing into an awesome platform. A few more examples and I think getting started will be alot easier. I've been doing most of my development on the BBB and linux debian these days. It's both good :-) and bad :-(. RGB-123 is going pretty well. It's really all about managing production schedules and new control methods. We are looking to develop an "enterprise" (wank word alert) solution that's alot less DIY here in the near future.

Re: Simple PWM Module Example

PostPosted: Wed Apr 08, 2015 9:49 am
by David John Barker
I did update the PWM library module but have not released it yet, if someone wants to test. Basically, it allows you to use
Code: Select all
Pwm.SetFrequency(<freq-value>)

and it should calculate and set all pre-scale and max duty available automatically. Much easier to use. I've attached versions for PIC18, PIC24 and PIC32. The main library folders can be found under
Code: Select all
C:\ProgramData\Mecanique\Firewing\Library\lib.imports\MCU08\Pwm.bas
C:\ProgramData\Mecanique\Firewing\Library\lib.imports\MCU16\Pwm.bas
C:\ProgramData\Mecanique\Firewing\Library\lib.imports\MCU32\Pwm.bas

Re: Simple PWM Module Example

PostPosted: Sat Nov 11, 2017 1:06 pm
by AndrewB
Does this work in the last update of Firewing?

OK I just import this PWM.bas.....

Thanks

Re: Simple PWM Module Example

PostPosted: Sat Nov 11, 2017 1:44 pm
by AndrewB
OK I have replaced the original pwm.bas with this one in the library.

Have used Pwm.setfrquency(1000) in my program and loading Adc.Read(A2) into the PWM

But the PWM signal is only adjusting a fraction of the duty.

Is this setting the PWM as 16bit and not 10bit as it originally was? Hence the shorter duty scale?

Re: Simple PWM Module Example

PostPosted: Mon Nov 13, 2017 9:54 am
by Jerry Messina
The number of bits is determined by the system clock freq and the pwm freq.

After calling SetFrequency(), a call to MaxDuty() will return the max value you can use to set the duty cycle in Write().

If you're using Adc.Read(A2) to set the duty cycle, make sure it's no larger than MaxDuty().