Pacetech
08-25-04, 07:56 PM
I developed the following code to run 2 motors based on 2 input joysticks (analog) and first tried to use PWMA0 and PWMA1, but A1 looked like it was anti-phase A0. I eventually changed it to PWMA0 and PWMA2.
Is PWMA1 always slaved to PWMA0 ?
Also, with v.74, the autostart does not use a vector? The autostart line below leaves 7C00 on the stack.
SCRUB
HEX
\ Setup on PlugAPod ISOMAX V0.74
\ Outputs
\ PWM0 and PA7 -> drive PWM & DIR for motor #1
\ PWM2 and PA6 -> drive PWM & DIR for motor #2
\ PA0 -> REDLED
\ PA1 -> YELLED
\ PA2 -> GRNLED
\
\ Inputs
\ Joystick Potentiometer #1 output on ADC0
\ Joystick Potentiometer #1 center reference on ADC1
\ Joystick Potentiometer #2 output on ADC2
\ Joystick Potentiometer #2 center reference on ADC3
\
\ Joystick Pot references tied to Vref and Vssa
\ note: Joystick pots are spring loaded to center and
\ provide a 2nd voltage output to indicate the center position.
\ Pots output is subtracted from the reference to get input
\ This value is checked for being positive or negative and then
\ is used to set the direction
\ the PWM is the subtracted number * 4 to get full scale 0-FFFF
\ Analog Front-End Code
7D CONSTANT 20KHZ EEWORD \ PWM period for 20kHz
3FFF CONSTANT MAXAD EEWORD \ maximum AD value
MAXAD NEGATE CONSTANT MINAD EEWORD \ minimum AD value
: INIT-PWM ( -- )
20KHZ PWMA0 PWM-PERIOD
PA6 IS-OUTPUT
PA7 IS-OUTPUT
; EEWORD
: READADC01 ( -- ) \ Reads analog input & Updates PWM & DIR
ADC0 ANALOGIN ADC1 ANALOGIN -
DUP 1 <
IF
PA7 OFF \ REVERSE
REDLED OFF
ELSE
PA7 ON
REDLED ON
THEN
MINAD MAX MAXAD MIN
ABS 2* 2*
PWMA0 PWM-OUT
; EEWORD
: READADC23 ( -- ) \ Reads analog input & Updates PWM & DIR
ADC2 ANALOGIN ADC3 ANALOGIN -
DUP 1 <
IF
PA6 OFF \ REVERSE
YELLED OFF
ELSE
PA6 ON
YELLED ON
THEN
MINAD MAX MAXAD MIN
ABS 2* 2*
PWMA2 PWM-OUT
; EEWORD
\ State Machine Code
MACHINE CHECKPOT EEWORD
ON-MACHINE CHECKPOT
APPEND-STATE ADC0POT1 EEWORD
APPEND-STATE ADC0POT2 EEWORD
IN-STATE
ADC0POT2
CONDITION
TRUE
CAUSES
READADC01
GRNLED TOGGLE
THEN-STATE
ADC0POT1
TO-HAPPEN IN-EE
IN-STATE
ADC0POT1
CONDITION
TRUE
CAUSES
READADC23
GRNLED TOGGLE
THEN-STATE
ADC0POT2
TO-HAPPEN IN-EE
DECIMAL
: RUN ( -- )
INIT-PWM
ADC0POT2 SET-STATE
EVERY 50000 CYCLES SCHEDULE-RUNS CHECKPOT
; EEWORD
SAVE-RAM
HEX 7C00 AUTOSTART RUN
Is PWMA1 always slaved to PWMA0 ?
Also, with v.74, the autostart does not use a vector? The autostart line below leaves 7C00 on the stack.
SCRUB
HEX
\ Setup on PlugAPod ISOMAX V0.74
\ Outputs
\ PWM0 and PA7 -> drive PWM & DIR for motor #1
\ PWM2 and PA6 -> drive PWM & DIR for motor #2
\ PA0 -> REDLED
\ PA1 -> YELLED
\ PA2 -> GRNLED
\
\ Inputs
\ Joystick Potentiometer #1 output on ADC0
\ Joystick Potentiometer #1 center reference on ADC1
\ Joystick Potentiometer #2 output on ADC2
\ Joystick Potentiometer #2 center reference on ADC3
\
\ Joystick Pot references tied to Vref and Vssa
\ note: Joystick pots are spring loaded to center and
\ provide a 2nd voltage output to indicate the center position.
\ Pots output is subtracted from the reference to get input
\ This value is checked for being positive or negative and then
\ is used to set the direction
\ the PWM is the subtracted number * 4 to get full scale 0-FFFF
\ Analog Front-End Code
7D CONSTANT 20KHZ EEWORD \ PWM period for 20kHz
3FFF CONSTANT MAXAD EEWORD \ maximum AD value
MAXAD NEGATE CONSTANT MINAD EEWORD \ minimum AD value
: INIT-PWM ( -- )
20KHZ PWMA0 PWM-PERIOD
PA6 IS-OUTPUT
PA7 IS-OUTPUT
; EEWORD
: READADC01 ( -- ) \ Reads analog input & Updates PWM & DIR
ADC0 ANALOGIN ADC1 ANALOGIN -
DUP 1 <
IF
PA7 OFF \ REVERSE
REDLED OFF
ELSE
PA7 ON
REDLED ON
THEN
MINAD MAX MAXAD MIN
ABS 2* 2*
PWMA0 PWM-OUT
; EEWORD
: READADC23 ( -- ) \ Reads analog input & Updates PWM & DIR
ADC2 ANALOGIN ADC3 ANALOGIN -
DUP 1 <
IF
PA6 OFF \ REVERSE
YELLED OFF
ELSE
PA6 ON
YELLED ON
THEN
MINAD MAX MAXAD MIN
ABS 2* 2*
PWMA2 PWM-OUT
; EEWORD
\ State Machine Code
MACHINE CHECKPOT EEWORD
ON-MACHINE CHECKPOT
APPEND-STATE ADC0POT1 EEWORD
APPEND-STATE ADC0POT2 EEWORD
IN-STATE
ADC0POT2
CONDITION
TRUE
CAUSES
READADC01
GRNLED TOGGLE
THEN-STATE
ADC0POT1
TO-HAPPEN IN-EE
IN-STATE
ADC0POT1
CONDITION
TRUE
CAUSES
READADC23
GRNLED TOGGLE
THEN-STATE
ADC0POT2
TO-HAPPEN IN-EE
DECIMAL
: RUN ( -- )
INIT-PWM
ADC0POT2 SET-STATE
EVERY 50000 CYCLES SCHEDULE-RUNS CHECKPOT
; EEWORD
SAVE-RAM
HEX 7C00 AUTOSTART RUN