What's wrong with this code?

mholguin

New Member
I finally got some time to play with pwmout, but, when I run this code on a 18X:

'**************
main:

for b0 = 100 to 400 step 10

pwmout 3 , 99, b0
wait 2
sertxd (#b0,13,10)

next b0

high 7 'sound buzzer to signal end of loop
wait 1
low 7

goto main

'*************** end

I get this output:

100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
4

And the cycle begins again. Funny it should go all the way to 100% duty cycle (400). Theres a small dc motor (actually an old cd-rom sipinner motor) attached to pin 3. Motor begins to spin at about 0.8 volts.
 

ylp88

Senior Member
Your counter in the FOR-NEXT loop, b0, is a byte variable and therefore will overflow when it reaches its maximum value of 255. Try using a word variable, w0, for example as this 16-bit variable can go to 65535 before overflowing.

ylp88

oooh! Post "888"...
 
Top