Shop OBEX P1 Docs P2 Docs Learn Events
Digital compensator??? — Parallax Forums

Digital compensator???

jojo Posts: 15
edited 2005-12-05 13:33 in Learn with BlocklyProp
Dear


I use ADC0831 and MAX522 to build a digital controller.
I have trouble to build a lead compensator inside.
I don't know what happen to my code.
Can anyone check this code?

By the way, the input is square wave.



A2Ddata CON 0
A2Dclock CON 1
A2Dcs CON 2
Din CON 6
D2Acs CON 5
D2Asclk CON 4

SetDacA· CON %00100001
H VAR Word
E VAR Word
U VAR Word
Inputvalue VAR Byte
Outputvalue VAR Byte

Initialize:
LOW D2Asclk
LOW A2Dclock
HIGH A2Dcs
HIGH D2Acs
H=0

Main:
·GOSUB Read_0831
·GOSUB WriteDac
·GOTO Main

Read_0831:
·LOW A2Dcs
·SHIFTIN A2Ddata, A2Dclock, MSBPOST, [noparse][[/noparse]Inputvalue\9]
·HIGH A2Dcs
·E=Inputvalue
·U=22*E+H
·H=((12*U)-(22*91*E))/100
·Sign=H
·GOSUB SetSign
·H=ABS H/100
·H=H*Sign
·Outputvalue=U
·RETURN

WriteDac:
·LOW D2Acs
·SHIFTOUT Din,D2Asclk, MSBFIRST,[noparse][[/noparse]SetDacA,Outputvalue]
·HIGH D2Acs
·RETURN

SetSign:
· IF Sign.BIT15=0 THEN SignPos
···· Sign=-1
· RETURN
SignPos:
···· Sign=1
· RETURN




Questions:

1. SHIFTIN A2Ddata, A2Dclock, MSBPOST, [noparse][[/noparse]Inputvalue\9]
···
··· Why·is Inputvalue·9 bits?

2. The Outputvalue is 8-bit number, U is 16-bit number
···
··· Outputvalue=U

··· What is Outputvalue?· Is it first 8 bit of U or last 8 bit of U?

3. Please check·these·four lines.
··
·· E=Inputvalue
·· U=22*E+H
·· H=((12*U)-(22*91*E))/100
·· Outputvalue=U


·· How do I prevent that U become a negative number?
·· Because, the Max522 can not send the negative votage.



Best regards,

Jo
··

Post Edited (jo) : 12/5/2005 6:21:56 PM GMT

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2005-12-05 13:33
    Regarding 3 :

    MIN· Limits a Value to Specified Low

    The Minimum Operator (MIN) limits a value to a specified 16-bit positive minimum. The syntax of MIN is:
    result = Value MIN Limit

    There's more on this in HELP.

    As for the calculations of U and H: unlike in Algebra class, the STAMP doesn't work with parentheses and there is no precedence of operators -- it just works from left to right, so you have to structure your equation/s accordingly.

    Post Edited (PJ Allen) : 12/5/2005 1:37:02 PM GMT
Sign In or Register to comment.