12bit PWMParabola?

Do you have a question on how to do something.
Ask in here.
KRavEN
Posts: 104
Joined: Sun Mar 17, 2013 8:21 am

12bit PWMParabola?

Post by KRavEN »

I'm trying to work with some external LED drivers that use a PCA9685 I2C PWM chip. It natively does 12bit PWM (0 - 4096). There is a table in the PCA9685 library that converts 8bit PWM (0 - 255) values to 12bit PWM values but I think it would be a much smoother effect to use 12bit with PWM Parabola.

How do I modify PWMParabola to support 12bit PWM?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

12bit PWMParabola?

Post by lnevo »

If you look in Globals.cpp in the libraries folder, you can search for the PWMParabola function.

I think you could just copy the function into your INO with a new name and change the bytes to int and then just pass in the range you want. I don't see any map or constrains in the function that would limit it to 0-100.

Then the next part would be how to write to the driver...that may be a bit more complex. Are you using an expansion module or the built in ports?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

12bit PWMParabola?

Post by lnevo »

Just realized that the native library now uses values over 100 to override the port setting so it may be tricky...but it also sounds like you may be writing to a custom i2c device? So maybe you'll handle it there? Hope I was somewhat helpful :(
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: 12bit PWMParabola?

Post by rimai »

v1.0.7 includes code to use that chip :)
Set your chip to I2C address:

Code: Select all

#define I2CPWM_PCA9685		0x40
Now, you can simply call:

Code: Select all

ReefAngel.PWM.SetChannel(0,50); // Set channel 0 to 50%
The libraries will do the heavy lifting for you :)
Roberto.
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Post by binder »

rimai wrote:v1.0.7 includes code to use that chip :)
Set your chip to I2C address:

Code: Select all

#define I2CPWM_PCA9685		0x40
Now, you can simply call:

Code: Select all

ReefAngel.PWM.SetChannel(0,50); // Set channel 0 to 50%
The libraries will do the heavy lifting for you :)
that is awesome :-)
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

12bit PWMParabola?

Post by lnevo »

Nice!
KRavEN
Posts: 104
Joined: Sun Mar 17, 2013 8:21 am

Re: 12bit PWMParabola?

Post by KRavEN »

Wow, very nice. Guess I should be updating my libraries.

I wrote my own library for the PCA9685 a long while back but I'll check out the one you're using so I can see if I was doing anything wrong/stupid. I used the I2C library with it because I was having problems with the old pre 1.0 arduino Wire library. It's actually a lot nicer than Wire because it only needs 2 or 3 method calls for a typical write operation vs the 6 to 8 that Wire needs.

But I digress. Thank you for the information and assistance.
KRavEN
Posts: 104
Joined: Sun Mar 17, 2013 8:21 am

Re: 12bit PWMParabola?

Post by KRavEN »

Haven't dug into it yet but I'm using 8 PCA9685 drivers with 6 LED channels per driver.

I have 2 Ecoray 60 LED fixtures I rewired. Each uses 2 of the driver boards. They have 5x 350mA LED RB strings, 5x 350mA LED white strings, 1x 750mA LED RB string, and 1x 750mA 405nm UV string. Each string has 5 LED's.

I also have 2 MakersLED fixtures that also use 2 driver boards each. They each have 3x 1000mA RB strings, 2x 1000mA NW strings, 3x 500mA OceanCoralWhite strings, and 2x 750mA 405nm/435nm UV strings.

So I'm dealing with 8 I2C addresses and I'll need 8 PCA9685 objects. The only problem I see is I'll either have to group the colors and do a slope for each color or if I want more control I'll need to do a slope for each channel.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: 12bit PWMParabola?

Post by rimai »

Wow... Lot's of channels :)
How big is your tank?
Roberto.
KRavEN
Posts: 104
Joined: Sun Mar 17, 2013 8:21 am

Re: 12bit PWMParabola?

Post by KRavEN »

rimai wrote:Wow... Lot's of channels :)
How big is your tank?
125g tall, 2' x 2' x 4'.

Yeah, it's overkill for sure. It started with the ecorays and I didn't like that they weren't dimmable. There aren't any dimmable drivers that can push 30 leds on one string so I designed my own drivers based on the PT4115 chip and had the PCB's fabbed by iseeedstudio. I also had to drill the ecoray PCB's to separate the big strings into manageable 5 led strings strings. Worked out well but they weren't enough spread because my canopy isn't very tall. So I built the makersled fixtures and they really put out the light so now I have too much output but good coverage.

Here's some pics http://www.dfwmas.org/Forums/viewtopic. ... 4&t=108378
KRavEN
Posts: 104
Joined: Sun Mar 17, 2013 8:21 am

Re: 12bit PWMParabola?

Post by KRavEN »

Looks like multiple boards should be easy as creating a new library based on RA_PWM with just the expansion methods. Modify the object instantiation to take the I2CPWM_PCA9685 address and store in a private variable. Then instantiate 8 RA_PCA9685 objects like so "RA_PCA9685 PCA1(0x40);" Then create parabolas for each channel of each object.
KRavEN
Posts: 104
Joined: Sun Mar 17, 2013 8:21 am

Re: 12bit PWMParabola?

Post by KRavEN »

Okay, I've modified RA_PWM a lot so I can pass the address and channels for each color during instantiation. Some issues because the "new" c++ keyword doesn't exist in Arduino.

Is there a better way to do this? I'm going to have 8 RA_PWM objects so the ReefAngelClass constructor is going to get pretty long once I add the other 7?

Code: Select all

// here's the RA_PWM constructor
RA_PWM(byte address, byte rbChannels, byte nwChannels, byte uvChannels, byte ocwChannels);

//  simplified ReefAngel.h
class ReefAngelClass {
  public:
    ReefAngelClass();
    RA_PWM Ecoray1RB;
}

// ReefAngelClass constructor
ReefAngelClass::ReefAngelClass() : Ecoray1RB(0x41, B00000000, 0, 0, 0) {

}
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Post by binder »

i would use an array as the constructor so you can pass one variable and it's not as long. then just reference the values of the array.

you can use the new construct on Arduino. it should be available, if not check out the globals files to see how to include it.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: 12bit PWMParabola?

Post by rimai »

I was thinking of adding this to the next update, but if you feel like sending me a pull request, that would be awesome!!!!
We only need 2 modules and they will use address 0x40 and 0x41, because I designed the hardware to only use those 2 addresses. But you would be able to easily modify it to your needs.
Here is my idea:
1. Increase the arrays:
#define NUM_PCA9685_MODULES 2
byte ExpansionChannel[PWM_EXPANSION_CHANNELS*NUM_PCA9685];
byte ExpansionChannelOverride[PWM_EXPANSION_CHANNELS*NUM_PCA9685];
Then, we can assign values to channels 0-11 for the 2 modules.
When the ExpansionWrite() function is called, we can adjust the I2C address depending on which channel you are sending it too... 0-5 would be address 0x40 and 6-11 would be address 0x41.
What do you think?
Roberto.
KRavEN
Posts: 104
Joined: Sun Mar 17, 2013 8:21 am

Re: 12bit PWMParabola?

Post by KRavEN »

Sounds like it would work but I went a different direction by creating a new library. The new library still has methods to set the channels individually or you can define a single slope or parabola for a color and the method creates the individual slope or parabolas needed for each channel assigned to that color. This is why I pass the constructor the address and the bit arrays assigning the channels to one of the 4 colors. This is of course customized to my particular scenario and a lot of my ReefAngel.cpp is custom because I added setup menus for each color on each fixture. I'm sure I could have gone the custom menu route with that but it was easier for me to just take everything out of the ReefAngel lib I wasn't using and add what I needed. That also helped me to figure out what is going on behind the scenes.

I'm also adding 12bit PWM to CIE luminance conversion as detailed here: http://neuroelec.com/2011/04/led-bright ... ection-no/. Multiplying the percentage by 40.95 works but it doesn't appear linear to me when I set a parabola over 1 minute to test. Not sure if this matters to the corals or not though.

Once I get things working I'll put it all up on my github so if there was anything useful that I did (who knows, stranger things have happened) then you can pull it over.
Meldrath
Posts: 20
Joined: Mon Mar 17, 2014 1:07 pm

Re: 12bit PWMParabola?

Post by Meldrath »

v1.0.7 includes code to use that chip :)
Set your chip to I2C address:
CODE: SELECT ALL
#define I2CPWM_PCA9685 0x40

Now, you can simply call:
CODE: SELECT ALL
ReefAngel.PWM.SetChannel(0,50); // Set channel 0 to 50%

The libraries will do the heavy lifting for you :)
I don't have my RA in front of me, does it still work like this for the newest versions of RA+?
Also how does one utilize the pwm as a non light pin within the ReefAngel? Or am I better off using BRunnel's library for this?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: 12bit PWMParabola?

Post by rimai »

Yeah, channel 0 is the output 0 in the chip.
What do you mean as non-light pin?
Roberto.
Meldrath
Posts: 20
Joined: Mon Mar 17, 2014 1:07 pm

Re: 12bit PWMParabola?

Post by Meldrath »

Roberto, how do you set it up with 2 chips?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: 12bit PWMParabola?

Post by rimai »

You would need to use custom code.
Search the forums for the 16 channel module. You will find the code.
Roberto.
Meldrath
Posts: 20
Joined: Mon Mar 17, 2014 1:07 pm

Re: 12bit PWMParabola?

Post by Meldrath »

Okay, i'm just a little more then slightly confused looking at the PWM class, how is this 16 channel capable when only 6 channels are defined in the library? The global variable #define PWM_EXPANSION_CHANNELS is 6, and the Internal EEPROM is only defined out to PWMChannel6 at 0x480.

Can you provide me a walk through on what I'm missing here, and what if anything I need to do to get just one chip working for now?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: 12bit PWMParabola?

Post by rimai »

There is no support for the 16 channel on our libraries. You need custom code as I mentioned before.
AlanM has started this though:
http://forum.reefangel.com/viewtopic.ph ... 16+channel
Take a look at this code to see how to do it without the libraries integration:
http://forum.reefangel.com/viewtopic.ph ... ion#p38671
Roberto.
Meldrath
Posts: 20
Joined: Mon Mar 17, 2014 1:07 pm

Re: 12bit PWMParabola?

Post by Meldrath »

Thank you!

Any sneaky pitfalls I should be on the look out for when I add in the custom code?
Meldrath
Posts: 20
Joined: Mon Mar 17, 2014 1:07 pm

Re: 12bit PWMParabola?

Post by Meldrath »

Okay, I finally got my code to compile correctly using Kraven's library.

Code: Select all

     int i = 0;
    
    while (i < 100)
    {
      ReefAngel.PCA.SetAllChannelsPercent(i);
      Serial.println(i);
      i++;
    }
    
    while (i >= 0)
    {
      ReefAngel.PCA.SetAllChannelsPercent(i);
      i--;
    }

The problem is when I hook up my adafruit breakout chip to the i2c port on the relay, I get a steady blinking red light under status and it does not dim up/down like it should.

I have tried my best to diagnose the issue, but am failing to see what the issue is at the moment.

To verify: I did create my own usb to i2c cable, with the following configuration;
Black - Ground
Green - SDA
White - SCL
Red - VCC
Meldrath
Posts: 20
Joined: Mon Mar 17, 2014 1:07 pm

Re: 12bit PWMParabola?

Post by Meldrath »

Shameless bump to figure this out. Any help from anyone would be appreciated.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: 12bit PWMParabola?

Post by rimai »

Did you try inverting the SDA/SCL wires?
It's something in the bus that is causing this.
Roberto.
Meldrath
Posts: 20
Joined: Mon Mar 17, 2014 1:07 pm

Re: 12bit PWMParabola?

Post by Meldrath »

I did. The chip is set to 0x4e (I believe) so I set that in the globals and moved the PHProbe to a different address.

Could this be the source of the issue?
Last edited by Meldrath on Tue May 13, 2014 8:04 am, edited 1 time in total.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: 12bit PWMParabola?

Post by rimai »

Can you confirm the breakout board is working with another arduino board?
Roberto.
Meldrath
Posts: 20
Joined: Mon Mar 17, 2014 1:07 pm

Re: 12bit PWMParabola?

Post by Meldrath »

Not readily available.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: 12bit PWMParabola?

Post by rimai »

The address won't be the issue.
If the status is blinking, it means your bus is locked.
So, I know it is something in that cable you've made or it is the breakout board/chip that is non-functional.
Burned out chips can cause this too.
Roberto.
Meldrath
Posts: 20
Joined: Mon Mar 17, 2014 1:07 pm

Re: 12bit PWMParabola?

Post by Meldrath »

Is there a verify within reef angel or something to see if the chip is functional?
Post Reply