//make the DAC value depending of the number of SET inputs
//there are only 16 inputs, so "scaling" is required
//the number of IO channels will be multiplied with 4
 
LABEL LOOP
     CALL COUNT_IO
     CALL MULTIPLY_WITH_4
     WAIT 250
GOTO LOOP
 
 
SUB COUNT_IO
     //set counter to 0
     VAR1 = 0
 
     //increase counter for each channel that is on
     VAR1 = VAR1 + $IO01
     VAR1 = VAR1 + $IO02
     VAR1 = VAR1 + $IO03
     VAR1 = VAR1 + $IO04
     VAR1 = VAR1 + $IO05
     VAR1 = VAR1 + $IO06
     VAR1 = VAR1 + $IO07
     VAR1 = VAR1 + $IO08
     VAR1 = VAR1 + $IO09
     VAR1 = VAR1 + $IO10
     VAR1 = VAR1 + $IO11
     VAR1 = VAR1 + $IO12
     VAR1 = VAR1 + $IO13
     VAR1 = VAR1 + $IO14
     VAR1 = VAR1 + $IO15
     VAR1 = VAR1 + $IO16
END SUB
 
 
SUB MULTIPLY_WITH_4
     //multiply with 4
     VAR2 = VAR1
     VAR1 = VAR1 + VAR2
     VAR1 = VAR1 + VAR2
     VAR1 = VAR1 + VAR2
 
     //send to DAC channel
     DAC01 = VAR1
 END SUB

BACK TO SAMPLE OVERVIEW