This is what I understand or misunderstand possibly.One thing I would like to know is what the */ function means
Internally the maths can have a 32 bit result because the PIC has a 32 bit register. But if your maths calculation will fit in a word then using word=byte*byte will work and you do not need ** or */.
If you have wordH=word**word and wordL=word*word then you have all 32 bits stored in two words.
*/ is less obvious but gives the middle word of the 32 bits. Which is the same as word=word*word/256 losing the top and bottom 8 bits.
If as in your case and as you know 4095/100 gives a result of 40 therefore B_max = (4095/100)*maxbright will give 2000 when maxbright is 50.
Whereas 4095*256/100 gives result of 10483 and 50*/10483 gives 2047 because by multiplying by 256 and using the */ to remove the 8 lower bits (or divide by 256 which is the same) increased accuracy is achieved. So where is the precision lost? The division /100 is the source of lost precision so as a rule multiply first and divide last which is exactly what */ does in that your program multiplies by 256 and */ divides by 256 last. As an aside working this way reduces the calculations within the program, there is only a division
A question then. What is the result of 50*4095/100 2000 or 2047? and (4095/100)*50?
Bookmarks