'************************************************************************* '* <3-Phase motor controller> * '* by * '* Dr.Godfried-Willem RAES * '* Stamp2 Hardware version 1.0 * '* Filename : <3Phase.bs2> * '* Code version 1.0 * '************************************************************************* ' 15.06.1998: designed for Laukhuff compressor motor speed control. ' speed should vary -20% to + 30%. ' With no data applied, the generated three phase voltage ' should be 50Hz. ' 16.07.2001: reconsidered. ' 18.07.2001: Now runs under NT with new Parallax editor. ' DECLARATIONS: Centrobyte VAR byte ' incoming byte, from midi microcontroller Motors VAR nib ' 3-bits is enough, we use the lower 3 bits Tempo VAR word ' in 2 microsecond units Ref50 VAR word ' 50Hz frequency reference Robot VAR word ' not yet in use... ' INITIALISATION: ' parallel input bits 0 to 7 ' these bits are mapped on midi notes 0-7 ' make this byte an input: DIRL = 0 ' pins 8 to 11 are not used. We configure ' them as outputs: DIRC = $F 'DIR12 = 1 :' phase U output 'DIR13 = 1 :' phase V output 'DIR14 = 1 :' phase W output 'DIR15 = 1 :' not used bit ' these pins feed an optocoupler, in its turn connected to ' the gates of 3 power mosfets. DIRD = $F ' Initialisation of variables: Centrobyte = INL :' low byte is incoming info Robot = 1 :' default is Robot ON Motors = 0 :' bit pattern for 3-phase current in bits 0-2 Ref50 = 1666 :' (20.000 microseconds / 6) / 2 Tempo = 1666 :' this value needs trimming. ' START OF RUN-CODE:***************************************************** Begin: Centrobyte = INL GOSUB FreqAlgo Motors = $5 :' 60 graden OUTD = Motors PAUSE tempo Centrobyte = INL GOSUB FreqAlgo Motors = $4 :' 120 graden OUTD = Motors PAUSE tempo Centrobyte = INL GOSUB FreqAlgo Motors = $6 : ' 180 graden OUTD = Motors PAUSE tempo Centrobyte = INL GOSUB FreqAlgo Motors = $2 : ' 240 graden OUTD = Motors PAUSE tempo Centrobyte = INL GOSUB FreqAlgo Motors = $3 : ' 300 graden OUTD = Motors PAUSE tempo Centrobyte = INL GOSUB FreqAlgo Motors = $1 : ' 360 graden OUTD = Motors PAUSE tempo Goto Begin FreqAlgo: IF Centrobyte = 0 THEN Geval0 IF Centrobyte < 128 THEN GevalSneller IF Centrobyte > 127 THEN GevalTrager Geval0: tempo = Ref50 RETURN GevalSneller: tempo = Ref50 - (Centrobyte * 3) RETURN GevalTrager: Centrobyte = Centrobyte - 127 tempo = Ref50 + (Centrobyte * 4) RETURN END