Hi All,
I need some assistance with PBP3 integer arithmetic.
I am working on an RGB LED application where the intensity of each of the RGB LED's is PWM controlled.
The PWM will be controlled by slide pots with the values read by ADC channels.
All ADC and PWM channels are 10-bit, slider pots range from 0 to 1023.
This is all very straight forward - no problems thus far.
Where things get complicated is that I want to be able to adjust the overall light intensity of a specific colour mix via a fourth slider pot.
For example, suppose I have a colour mix of Red = 980, Green = 650 and Blue = 870 but I want to reduce the overall light output because it is too bright for a specific need.
To dim the overall light output but maintain the exact same colour mix would be quite difficult.
What I would like is to be able to use the fourth slider to scale the intensity of the three individual colours:
Scaled Red = 980 * Pot4 Setting/1024
Scaled Green = 650 * Pot4 Setting/1024
Scaled Blue = 870 * Pot4 Setting/1024
Let's assume that Pot4 is set at half scale (512). I am confused as to what the values for the three scaled colours will be using PBP integer maths?
For the red colour, 980 * 512 is too large and 512/1024 is too small (ie less than one) for 16-bit integer maths yet the actual equation solution (490) is well within word variable limitations.
As Pot4 Setting can vary anywhere between 0 and 1023, I am having difficulty working out a simple way to implement the scaled colour equations (Scaled Colour = Colour * Po4 Setting/1024) using PBP 16-bit integer math.
I am using a 16F1509 so using LONGS are not an option.
All comments and suggestions are welcomed and greatly appreciated.
Cheers
Barry
VK2XBP
I need some assistance with PBP3 integer arithmetic.
I am working on an RGB LED application where the intensity of each of the RGB LED's is PWM controlled.
The PWM will be controlled by slide pots with the values read by ADC channels.
All ADC and PWM channels are 10-bit, slider pots range from 0 to 1023.
This is all very straight forward - no problems thus far.
Where things get complicated is that I want to be able to adjust the overall light intensity of a specific colour mix via a fourth slider pot.
For example, suppose I have a colour mix of Red = 980, Green = 650 and Blue = 870 but I want to reduce the overall light output because it is too bright for a specific need.
To dim the overall light output but maintain the exact same colour mix would be quite difficult.
What I would like is to be able to use the fourth slider to scale the intensity of the three individual colours:
Scaled Red = 980 * Pot4 Setting/1024
Scaled Green = 650 * Pot4 Setting/1024
Scaled Blue = 870 * Pot4 Setting/1024
Let's assume that Pot4 is set at half scale (512). I am confused as to what the values for the three scaled colours will be using PBP integer maths?
For the red colour, 980 * 512 is too large and 512/1024 is too small (ie less than one) for 16-bit integer maths yet the actual equation solution (490) is well within word variable limitations.
As Pot4 Setting can vary anywhere between 0 and 1023, I am having difficulty working out a simple way to implement the scaled colour equations (Scaled Colour = Colour * Po4 Setting/1024) using PBP 16-bit integer math.
I am using a 16F1509 so using LONGS are not an option.
All comments and suggestions are welcomed and greatly appreciated.
Cheers
Barry
VK2XBP