Adding support for 16 channel PWM expansion to libraries

Related to the development libraries, released by Curt Binder

Posts: 263
Joined: Wed Jan 01, 2014 7:26 am
PostPosted: Sun Apr 20, 2014 8:49 am
Roberto has a custom 16 channel 12-bit PWM expansion that he makes for people from time to time. I see the code in for the standard PWM expansion with 6 channels. The 16 channel one uses the same chip, but is larger in size, physically, doesn't have a box for it yet (but I'm going to put mine in one), and needs custom code to address, and, by default runs on at 0x41 instead of 0x40 for the standard PWM expansion.

I have downloaded the dev branch of the libraries into the gibhub client and will make changes against that. I'm posting a thread here to keep track of what's going on with it and maybe to ask questions about things I don't understand with the RA_PWM.cpp file.

A few questions to start. I don't really get all of the "over 100 disables override" concept. What's going on with the override stuff and the if<= 100 return override value stuff? Also what's RA_STAR?

Should I just write a class wrapper for the 16 channel expansion how I'd want to use it at the moment and email it in and you guys could figure out if it's useful to scrape stuff out and incorporate since there seems to be some compatibility history in that file that I don't get?
User avatar
Posts: 5342
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sun Apr 20, 2014 9:12 am
RA_STAR is the next generation hardware being developed.

The way the override works you can set that value to 0-100 and it will override the default schedule and turn the leds to that %. If you want to disable the override you set it to 255 or really as you've seen, anything over 100.

Posts: 12188
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Sun Apr 20, 2014 9:33 am
Is that like Easter egg hunting for devs??? :)
You found RA_STAR... lol
There is a lot under the hood that people just don't get to see.
I think the best way is to do this:
Add a feature to our Arduino IDE. This is located in the features.txt file inside the /update folder.
For the sake of progressing, lets call it like this:
Code: Select all
16CHPWMEXPANSION,ReefAngel.Add16ChPWM,16 Channel Dimming Expansion Module

There is also a git repository I just created a few days ago for this file.
When you add that to the features.txt file, the Arduino IDE will scan your code and look for that keyword (ReefAngel.Add16ChPWM) and it will enable the define 16CHPWMEXPANSION.
So, make sure that your INO code has this line:
Code: Select all
ReefAngel.Add16ChPWM();

We usually put it in the setup(), but anywhere in the code works... Even if it is commented out.
Now, you have the ground work to start changing the library. You have the define 16CHPWMEXPANSION that can be enabled or disabled.
After I replied to your PM, I realized that the idea I had will not work.
It will disable the existing dimming module. I think the idea is to make both work at the same time.
So, with the new ifdef 16CHPWMEXPANSION, you will need to add code to the libraries so that you can interface with your module.
I think you will need to add these defines to Globals.h:
Code: Select all
#define 16CH_PWM_EXPANSION_CHANNELS           16
#define I2CPWM__16CH_PCA9685      0x41

And then add all the same methods we have for the regular dimming expansion module.
I think these are the basic ones you need:
Set16Channel
Get16Channel
Set16ChannelOverride
16ChExpansion
16ChExpansionWrite

Let me know what you think.
Roberto.

Posts: 263
Joined: Wed Jan 01, 2014 7:26 am
PostPosted: Sun Apr 20, 2014 10:00 am
Got it. I'll do it that way.

BTW, I know your PM would disable the regular PWM expansion, but figured that would be a quick and dirty way to see if it worked and then I'd back it out and do the extra define stuff.

I'm looking in RA_PWM.cpp and see lots and lots of stuff in there with multiple constructors for each channel in the standard expansion. If it's OK I'm going to wrap those #ifdef PWMEXPANSION lines with an #ifdef 16CHPWMEXPANSION one and not duplicate the code for the first 6 channels since they'll be the same. What do you think?

Also, I may try adding in the ability to use all 12 bits as a constructor argument to allow it to go from 0 to 4095 if specified. The only place all 12 bits will matter to me is when the lights are on very dimly. In that case the difference between 1% and 2% is a big jump in intensity. The difference between 40% and 41%, as a for instance, is not visible, but 1 and 2 definitely is.

And while I'm at it I'm going to take the liberty to add my SmoothRamp function to all the channels. 8)

Posts: 263
Joined: Wed Jan 01, 2014 7:26 am
PostPosted: Sun Apr 20, 2014 10:02 am
lnevo wrote:RA_STAR is the next generation hardware being developed.

The way the override works you can set that value to 0-100 and it will override the default schedule and turn the leds to that %. If you want to disable the override you set it to 255 or really as you've seen, anything over 100.


If that's what override does, then how could you have the default schedule ever set anything between 0 and 100 and keep running the "schedule" because it would think it was between in override status if it was between 0 and 100.
User avatar
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am
PostPosted: Sun Apr 20, 2014 10:20 am
This is awesome. I agree that 0-4095 is definitely better. I also have the 16 channel expansion, I haven't had much time lately to work with it, I just have it on a simple parabola program right now. I would like to keep the standard pwm expansion in my libraries as it runs my four dc pumps. I'll definitely be following and helping as much as I can.

Posts: 263
Joined: Wed Jan 01, 2014 7:26 am
PostPosted: Sun Apr 20, 2014 10:28 am
I assume that these in Globals.h have something to do with detecting when something is in override state?

Code: Select all
#define OVERRIDE_CHANNEL0      2
#define OVERRIDE_CHANNEL1      3
#define OVERRIDE_CHANNEL2      4
#define OVERRIDE_CHANNEL3      5
#define OVERRIDE_CHANNEL4      6
#define OVERRIDE_CHANNEL5      7


If so, since I don't really know what they're doing should I add my own set of OVERRIDE_16CH_CHANNEL0, etc defines or should I just add channels 6-15 at the end of that block of OVERRIDE defines?

Posts: 263
Joined: Wed Jan 01, 2014 7:26 am
PostPosted: Sun Apr 20, 2014 10:40 am
Also this section looks like all the bits up to 128 are used. Can I pick 256 for 16CHPWMEXPANSION?

Code: Select all
#ifdef PWMEXPANSION
   #define PWMEbit      1
#else
   #define PWMEbit      0
#endif  // PWMEXPANSIO
User avatar
Posts: 5342
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sun Apr 20, 2014 10:45 am
The override uses a different variable to store the percentage and that variable overrides the default

Posts: 12188
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Sun Apr 20, 2014 10:51 am
Code: Select all
#define OVERRIDE_CHANNEL0      2

This define is used by the internal webserver to identify which channel you are overriding when you call http://ipaddress:2000/pox,y
x is the channel and y is the value to override.
So, you will need to add all the 16 channels to the end of the list and make sure to leave OVERRIDE_CHANNELS as the last one.
Code: Select all
#define PWMEbit      1

This define is used by the portal and other apps to identify that you have the dimming expansion module activated in your code. I don't think you need to mess with that at this point.
Roberto.
Next

Return to Development Libraries

Who is online

Users browsing this forum: No registered users and 1 guest