I was trying to generate a low freq. square wave about 100 Hz with 18M2+ running at 16MHz but PWM only goes down to 244 Hz. So tried to use Interrupts to trigger on rising edge of the PWM and toggle output B.0. This works quite well providing very little code or delay in the main loop. Even small counting and switching procedures seems to upset it. and Touch16 slows it down completely. attached is a test bit of code I was trying. would welcome any ideas. ??
init: #picaxe 18m2 pullup off setfreq m16 'pwmout pwmdiv64, B.6, 255, 511 '200 hz pwmout pwmdiv64, B.6, 141, 283 ' 441 Hz ' Link B.6 to C.6 (with 220 ohm resistor) - use interrupt on C.6 setint %01000000,%01000000 w2=0 b2=0 main: w2=0 'pause 1 pause 100 'gosub docount 'touch16 C.0, w6 'touch16 C.1, w7 'gosub dotouch goto main interrupt: ' toggle B.0 on count of C.6 rising edges if b2=0 then toggle B.0 b2=2 'set count of rising edges here endif interloop: if pinC.6 = 1 then interloop b2=b2-1 pause 1 setint %01000000,%01000000 return dotouch: touch16 C.0, w6 pause 10 touch16 C.1, w7 pause 10 return docount: w2=w2+1 if w2 < 50 then docount w2=0 return