Simple PWM Module Example

Share code examples with other users

Simple PWM Module Example

Postby ohararp » Sat Apr 04, 2015 8:35 pm

I am dusting off my firewing hardware (Pic24) and was wondering if there is a simple PWM library example?
ohararp
 
Posts: 5
Joined: Fri May 03, 2013 1:01 pm

Re: Simple PWM Module Example

Postby Coccoliso » Mon Apr 06, 2015 7:08 am

User avatar
Coccoliso
 
Posts: 177
Joined: Sat Sep 27, 2014 10:02 am

Re: Simple PWM Module Example

Postby bitfogav » Mon Apr 06, 2015 4:02 pm

User avatar
bitfogav
 
Posts: 75
Joined: Sat Nov 17, 2012 11:46 am
Location: UK

Re: Simple PWM Module Example

Postby ohararp » Mon Apr 06, 2015 4:20 pm

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
ohararp
 
Posts: 5
Joined: Fri May 03, 2013 1:01 pm

Re: Simple PWM Module Example

Postby bitfogav » Mon Apr 06, 2015 4:57 pm

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 ;)
User avatar
bitfogav
 
Posts: 75
Joined: Sat Nov 17, 2012 11:46 am
Location: UK

Re: Simple PWM Module Example

Postby ohararp » Mon Apr 06, 2015 5:09 pm

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.
ohararp
 
Posts: 5
Joined: Fri May 03, 2013 1:01 pm

Re: Simple PWM Module Example

Postby David John Barker » Wed Apr 08, 2015 9:49 am

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
Attachments
Pwm-pic32.zip
(1.09 KiB) Downloaded 1087 times
Pwm-pic24.zip
(1.03 KiB) Downloaded 1121 times
Pwm-pic18.zip
(1.15 KiB) Downloaded 1091 times
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Simple PWM Module Example

Postby AndrewB » Sat Nov 11, 2017 1:06 pm

Does this work in the last update of Firewing?

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

Thanks
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Simple PWM Module Example

Postby AndrewB » Sat Nov 11, 2017 1:44 pm

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?
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Simple PWM Module Example

Postby Jerry Messina » Mon Nov 13, 2017 9:54 am

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().
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Next

Return to Code Examples

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x