PDA

View Full Version : PWM-OUT Question


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

nmitech
08-26-04, 10:14 AM
? - Is PWMA1 always slaved to PWMA0 ?
>> Only when you set it up for complimentary pair. But It did not look like so in your code. I will check it out shortly.

? - with v.74, the autostart does not use a vector? The autostart line below leaves 7C00 on the stack.
>> Sorry for lack of documentation on the beta version, V0.61 or newer.
From V0.63 up to latest, The autostart address will be auto set by the Kernel. So you do not need to specify the address,

HEX AUTOSTART RUN

RMDumse
08-26-04, 10:26 AM
Originally posted by Pacetech
Is PWMA1 always slaved to PWMA0 ?


Looking at DSP56F801-7UM.pdf, it says "In the PWM configure register, writing a logic one to the INDEPxx bit configures a pair of the PWM outputs as two independent PWM channels. Each PWM output has its own PWM value register operating independently of the other channels in independent channel operation.

So you could make the two channels independent by writing 1's into the PWM Config Register.

The PWM Config Register is at offset F and three low bits control what is and what isn't complementrary.

So if you want all independent channels for PWM A, try this

HEX
E0F @ E OR E0F !


Also, with v.74, the autostart does not use a vector? The autostart line below leaves 7C00 on the stack.


Latest version we took away concept of needing to specify an autostart location, and instead just look in one location.

The idea of using every 1K boundary was left over from the days when you could insert small memories in the map, to grab an autostart ahead of the main one on your board. With the memory internal, and not removeable or insertable, having multiple autostart addresses just doen't make the same sense.