I have a simple problem but i don't can solve.
If pwr >= 255 always go to 0 and no to 255.Why happen this?Code:pwr var byte If up = 1 Then PAUSE 50 pwr = pwr + 1 If pwr >= 255 Then pwr = 255 Endif
I have a simple problem but i don't can solve.
If pwr >= 255 always go to 0 and no to 255.Why happen this?Code:pwr var byte If up = 1 Then PAUSE 50 pwr = pwr + 1 If pwr >= 255 Then pwr = 255 Endif
Since a byte can count up to 255 max when you add 1 to 255 the byte overflow and start from zero again (it cannot be 256).If pwr >= 255 always go to 0 and no to 255.Why happen this?
If you want to keep your variable pwr at 255 then you can skip the add command, or you must use a word variable.
Code:pwr var byte If up = 1 Then PAUSE 50 If pwr = 255 Then Skip00 pwr = pwr + 1 Skip00: Endif
Al.
Last edited by aratti; - 20th November 2009 at 07:13.
All progress began with an idea
Thank you. It is work.
I don't want use word variable , because pwr is for duty of HPWM.
Hi, Savnlik
You just can use :
or ...Code:For I = 1 to 255 PAUSE 50 HPWM 1,I,1000 ' The reason of your loop ( BTW ...). 1000 is pwm freq. NEXT I
Code:DO I = I + 1 .... While I < 255
For limiting Numbers:
AlainCode:I = J MIN 255 ' I is the smaller ( MIN ) number between J and 255 ...
Last edited by Acetronics2; - 20th November 2009 at 09:55.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Ouch, yes of course... my mistake, sorry.I had test and not work.Because next have count 255 + 1 = 256
Bookmarks