Page 3 of 4

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Thu Sep 25, 2014 8:17 am
by lnevo
12 bit resolution is in the dev libraries and working great. You now get full 8 bit resolution on the built-in ports and 12 bit on the current dimming modules. Some older ones may still he 8 bit. PM Roberto (rimai) to purchase a 16channel module.

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Sep 26, 2014 10:26 am
by cosmith71
Could someone post a guide on how to work the 12 bit dimming?

Thanks,

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Sep 26, 2014 10:44 am
by lnevo
If your using InternalMemory you don't have to do anything. If your setting them manually with the parabola or slope functuons you can just add HighRes to the function name.

For set and get functions, just add Raw at the end.

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Sep 26, 2014 2:15 pm
by cosmith71
How does that work with the standard PWM ports? Still use PWMSlopeHighRes? How will it know the difference between, say, 50% and 50?

I guess the Portal and the RA Status app still use bytes to store the values for the PWM Expansion module? They're rolling over every 255.

Thanks,

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Sep 26, 2014 4:31 pm
by lnevo
Yes GetValue() and the portal will get the byte value. But if you want to write a high res number then you'd use SetDaylightRaw(). Then when it writes it will scale it down to 0-255. The HighRes functions all output 0-4095 (12 bit range)

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Sun Sep 28, 2014 5:14 am
by cosmith71
Disregard the second half of my previous statement. I was doing it wrong. :oops:

Got it running, but I've noticed I can't dim below a raw value of 21 with my LDD drivers. At 20 they shut off. Hardware limitation or software issue?

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Sun Sep 28, 2014 6:09 am
by lnevo
Thats pretty damn good. All drivers need some amount of voltage in order to get going. The LDDs are low for sure. 21 is like .005v

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Sun Sep 28, 2014 8:33 am
by rimai
Yeah, I think that is the minimum that your driver will take, which is pretty good in my opinion.
How does the LED look at 21?

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Sun Sep 28, 2014 8:45 am
by cosmith71
A little too bright for a moonlight, but I have 40 LED's on that channel. :D

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Mon Sep 29, 2014 7:06 am
by AlanM
Cool. I've never driven mine down that low on purpose, but I should try with some Raw commands. I know I used to do a slope from 0% to 3% over 3 hours using HiRes functions and it was really really dim at first. I don't know what the raw value was, though.

I owe Roberto a users guide to how the new dimming stuff works and how you'd access it if you wanted to get to it from the .ino file.

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Mon Dec 29, 2014 6:45 am
by cosmith71
cosmith71 wrote:Disregard the second half of my previous statement. I was doing it wrong. :oops:

Got it running, but I've noticed I can't dim below a raw value of 21 with my LDD drivers. At 20 they shut off. Hardware limitation or software issue?

--Colin
OK, so I've figured out that this really isn't a raw value of 21. I'm using the RANet dimming module which works off of an 8 bit value scaled up to 12 bits (multiplied by 40.95). So 21 is probably the break point between 0 and 1%.

What I'd like to do is use the bytes in the RANet packet normally used for the 16 channel dimmer for some sweet 12 bit dimming action.

What would be the best way, with a 6 channel dimming module defined, to send along some 16 channel data? I think plucking it out on the RANet receiver side would be easy enough. From what I've seen, you can have a 6 or a 16, but not both.

Maybe just define as a 16 channel and re-write the receiver code to translate to 6 channels?

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Mon Dec 29, 2014 9:28 am
by rimai
Damn... :) You are digging it deep huh? :) I like it.
I doubt this is the case.
21 in the RANet packet is really 21%.
Just to make sure we are talking about the same number, go to your dimming channels in your RA and look at the % for that channel.
Is it 21% or 1%?

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Mon Dec 29, 2014 9:34 am
by cosmith71
It's 1%. But I'm writing a raw value of 21, which I'm guessing is converted to 1%, sent to the RANet receiver, which then converts it to 1*40.95 and sends it on to the dimming module, right? So my end result is a raw value of 40.

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Mon Dec 29, 2014 9:43 am
by rimai
Yeap. You are correct then.
I think the only way we will be able to achieve this is to make the RANet payload bigger and send int values instead of byte values.
Can you open an issue in the github?

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Mon Dec 29, 2014 10:04 am
by cosmith71
Done.

Isn't an int 4 bytes? We only really need 2 (or even 1.5). Not sure how big the payload can be.

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Mon Dec 29, 2014 11:50 am
by lnevo
int is 2 bytes :)

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Mon Dec 29, 2014 12:20 pm
by cosmith71
Doh! I misread. :D Of course it is.

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Thu Jan 22, 2015 4:06 pm
by cosmith71
I did a little work on this, and got GitHub working.

Something is still wrong. I changed the payload to 68 bytes to accommodate 2 bytes for each expansion dimming and 16 channel expansion dimming and changed the RANet receiver software to read it. None of the channels are working as expected and I'm not really sure how to debug it.

My repositories are cosmith71/Libraries and cosmith71/RANet-Reciever. Not sure if that is what you need to find them?

Thanks,

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Thu Jan 22, 2015 10:31 pm
by rimai
I'll take a look at it.

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Jan 23, 2015 8:46 am
by cosmith71
Thanks. Made a couple of changes this morning, but still not correct. I'm wondering if I have my MSB's and LSB's reversed some how.

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Jan 30, 2015 2:30 pm
by cosmith71
OK, got it fixed! I now have full 12 bit dimming on my RANet 6 channel dimming expansion! :ugeek:

Not sure what happened. I spotted an error in the receiver code that I swear I fixed earlier. Changed that and it's working.

I used a spare Xbee and the USB module I bought to program them to intercept the data stream. I used a program called RealTerm to look at the hex stream the module was receiving and made sure the 16 bit payload was being sent correctly. It was. That led me back to the receiver code. Turns out I had an error in the code that selects the channel I'm loading. Once that was fixed, it worked!

So now the RANet payload consists 8 bytes for relay boxes, 8 bytes for fallback relay values, 12 bytes for 6 channel dimming (2 bytes per channel) and 32 bytes for 16 channel dimming (not yet implemented, but would be same as 6 channel).

Now, I just need to implement lightning and clouds. It'll take an adjustment to the trigger mechanism.

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Jan 30, 2015 2:35 pm
by rimai
Awesome!!!
While you are at it and hand on :), add the trigger to the payload.
If we add a new byte to the payload, we can trigger up to 255 commands.
So, 0 would be no commands, 1 would be lightning, 2 would be something else and so on.
Then, all the receiver needs to do is check for that byte and trigger it accordingly.

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Jan 30, 2015 2:39 pm
by cosmith71
Great idea! I was just going to hide it in the high 4 bits of one of the channels, but I like the idea of a dedicated byte better. Time to put my thinking cap back on. :ugeek:

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Jan 30, 2015 3:09 pm
by cosmith71
OK, so that's done. I just added a byte onto the packet at the end right before the terminal <CR><LF>.

Now my problem is I don't know how to set it. :oops: I guess we need a new library function? Something like ReefAngel.SetRANetTrigger(trigger value)?

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Jan 30, 2015 3:24 pm
by rimai
That should work :)

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Jan 30, 2015 7:42 pm
by cosmith71
Done. ReefAngel.RANetTrigger(byte) is now a thing. RANet Receiver with Lightning code updated as well. :ugeek: :ugeek:

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Fri Jan 30, 2015 9:14 pm
by lnevo
Holy cow! Way to go colin!!!

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Sat Jan 31, 2015 6:03 am
by cosmith71
Yes, certainly my crowning achievement as a coder. :lol:

Roberto, should I submit pull requests? It won't work on a RANet dimmer without updated code.

--Colin

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Sat Jan 31, 2015 9:12 am
by rimai
Yes, send me a pull request and also the updated firmware for the receiver.

Re: Adding support for 16 channel PWM expansion to libraries

Posted: Sat Jan 31, 2015 9:47 am
by cosmith71
Done.