kevinr
12-20-00, 10:41 PM
I wrote a program in Forth to control a servo with PWM. It ran fine so I wanted to run two servos. Now I have a problem: I seem to be running out of memory. I bought the NMIL-0012 because it had extra RAM. Here are the two code files. The first one which runs and the second one which loads to a point and then seems to run out of memory:<p>COLD <br>HEX ( Works on the B32 )<p>04 000A C! ( Allow access to external memory )<br>B0 000B C!<p>40 CONSTANT PWCLK <br>41 CONSTANT PWPOL ( PWM outputs )<br>42 CONSTANT PWEN ( PWM enables )<br>48 CONSTANT PWCNT0<br>49 CONSTANT PWCNT1<p>4C CONSTANT PWPER0 ( period for channel 0 )<br>4D CONSTANT PWPER1 ( period for channel 1 )<p>50 CONSTANT PWDTY0 ( duty cycle for channel 0 )<br>54 CONSTANT PWCTL<br>56 CONSTANT PORTP ( port P outputs )<p>: INIT ( -- )<br> 0 PORTP ! ( set outputs to zero just in case they are used )<br> 0 PWCTL ! ( not really needed )<br> E0 PWCLK C! ( Prescale clock A : E/32, catenate 0 & 1 , 2 & 3)<br> 27 PWPER0 C! ( set the period on channel 0 )<br> 10 PWPER1 C!<br>1F4 PWDTY0 ! ( set the duty cycle on channel 0 )<br> 0 PWCNT0 ! ( zero counter )<br> 1 PWPOL C! ( set initial output as high )<br> F PWEN C! ( enable all of the PWM outputs )<br>;<p>DECIMAL<p>INIT<p>: D PWDTY0 ! ; ( set duty cycle )<br>: P PWPER0 ! ; ( set period )<p>: WAIT 32000 0 DO LOOP ; ( WAIT LOOP )<br>: T 1000 500 DO I DUP . D WAIT 5 +LOOP ;<br>: RT 500 1000 DO I DUP . D WAIT -5 +LOOP ;<p>: FORWARD 1000 D ;<br>: STOP 750 D ;<br>: REVERSE 500 D ;<br>: HALF 875 D ;<br>: QUARTER 800 D ;<br>: DEAD 770 D ;<br>: RHALF 625 D ;<br>: RQUARTER 700 D ;<br>: RDEAD 740 D ;<br>: FULL FORWARD ;<br>: RFULL REVERSE ;<p>: LWAIT 50 0 DO WAIT LOOP ;<p>: COURSE DEAD LWAIT RQUARTER LWAIT RDEAD<br> LWAIT FULL LWAIT RDEAD LWAIT STOP ;<br> ( Test for dead zone in a servo )<br>: STEST 770 730 DO I D WAIT I . WAIT LOOP ;<p><p>COLD <br>HEX ( Works on the B32 )<p>04 000A C! ( Allow access to external memory )<br>B0 000B C!<p>40 CONSTANT PWCLK <br>41 CONSTANT PWPOL ( PWM outputs )<br>42 CONSTANT PWEN ( PWM enables )<br>48 CONSTANT PWCNT0<br>49 CONSTANT PWCNT1<p>4C CONSTANT PWPER0 ( period for channel 0 )<br>4D CONSTANT PWPER1 ( period for channel 1 )<p>50 CONSTANT PWDTY0 ( duty cycle for channel 0 )<br>54 CONSTANT PWCTL<br>56 CONSTANT PORTP ( port P outputs )<p>: INIT ( -- )<br> 0 PORTP ! ( set outputs to zero just in case they are used )<br> 0 PWCTL ! ( not really needed )<br> E0 PWCLK C! ( Prescale clock A : E/32, catenate 0 & 1 , 2 & 3)<br> 27 PWPER0 C! ( set the period on channel 0 )<br> 10 PWPER1 C!<br>1F4 PWDTY0 ! ( set the duty cycle on channel 0 )<br> 0 PWCNT0 ! ( zero counter )<br> 1 PWPOL C! ( set initial output as high )<br> F PWEN C! ( enable all of the PWM outputs )<br>;<p>DECIMAL<p>INIT<p>: D PWDTY0 ! ; ( set duty cycle )<br>: P PWPER0 ! ; ( set period )<p>: WAIT 32000 0 DO LOOP ; ( WAIT LOOP )<br>: T 1000 500 DO I DUP . D WAIT 5 +LOOP ;<br>: RT 500 1000 DO I DUP . D WAIT -5 +LOOP ;<p>: FORWARD 1000 D ;<br>: STOP 750 D ;<br>: REVERSE 500 D ;<br>: HALF 875 D ;<br>: QUARTER 800 D ;<br>: DEAD 770 D ;<br>: RHALF 625 D ;<br>: RQUARTER 700 D ;<br>: RDEAD 740 D ;<br>: FULL FORWARD ;<br>: RFULL REVERSE ;<p>: LWAIT 50 0 DO WAIT LOOP ;<p>: COURSE DEAD LWAIT RQUARTER LWAIT RDEAD<br> LWAIT FULL LWAIT RDEAD LWAIT STOP ;<br> ( Test for dead zone in a servo )<br>: STEST 770 730 DO I D WAIT I . WAIT LOOP ;<p>HEX<p>4A CONSTANT PWCNT2<br>4B CONSTANT PWCNT3<br>4E CONSTANT PWPER2<br>4F CONSTANT PWPER3<br>52 CONSTANT PWDTY2 ( duty cycle for channel 2 )<p> 27 PWPER2 C! ( set the period on channel 0 )<br> 10 PWPER3 C!<br>1F4 PWDTY2 ! ( set the duty cycle on channel 2 )<br> 0 PWCNT2 !<p>DECIMAL<p>: D2 PWDTY2 ! ;<br>: P2 PWPER2 ! ;<p><p>Do you know why I can't use the expanded memory to run the second code example? The first one breaks at the number 625 if I leave out the two lines :<p>04 000A C! ( Allow access to external memory )<br>B0 000B C!<p>They allow access to the external memory but it doesn't seem to allow very much more. Only a few more lines of Forth and it is used up. How does all of the memory get used up on so little code? <p>Help!