Hi Malcolm,
Using Darrels SPWM routines is probably easier but basically you can do something like this. (This is untested, meant to show the theory only)
/Henrik.Code:Duty1 VAR BYTE ' 0-255 = 0-100% Duty2 VAR BYTE Duty3 VAR BYTE Period VAR BYTE LED1 VAR PortB.0 LED2 VAR PortB.1 LED3 VAR PortB.2 Period = 0 PWMStart: ' Turn on outputs only if duty is more than 0 If Duty1 > 0 THEN LED1 = 1 ENDIF IF Duty2 > 0 THEN LED2 = 1 ENDIF IF Duty3 > 0 THEN LED3 = 1 ENDIF PWMLoop: ' Increment period Period = Period + 1 ' Time to turn off output 1? IF Period = Duty1 THEN LED1 = 0 ENDIF ' Time to turn off output 2? IF Period = Duty2 THEN LED2 = 0 ENDIF ' Time to turn off output 3? IF Period = Duty3 THEN LED3 = 0 ENDIF ' Go and do other stuff needed GOSUB DoOtherStuff IF Period = 0 THEN GOTO PWMStart ELSE GOTO PWMLoop ENDIF END '-------------------------------------------------------------- DoOtherStuff: ' Do the ADC stuff etc here. PAUSEUS 4000 ' Adjust to get desired PWM frequency. '--------------------------------------------------------------




Bookmarks