Hi,
Im a little bit stuck here. Im trying to do a PWM in assembly in software (not using the hardware PWM).
I also need this code to be simple so I can experiment with different frequencies. It is designed to turn a pump on and off. I will experiment with around with different frequencies but the pump has it own onboard electronics so I want to keep the frequency low to ensure I dont mess with that. I would think ranging it from 10HZ to 1HZ.
How would I code something like this? This is my preliminary mockup:
Sorry if this is the ugliest code you have ever seen, but I thought I would be better off showing you my attempt at it.
Im a little bit stuck here. Im trying to do a PWM in assembly in software (not using the hardware PWM).
I also need this code to be simple so I can experiment with different frequencies. It is designed to turn a pump on and off. I will experiment with around with different frequencies but the pump has it own onboard electronics so I want to keep the frequency low to ensure I dont mess with that. I would think ranging it from 10HZ to 1HZ.
How would I code something like this? This is my preliminary mockup:
Code:
;=====================
;0.1S on - 0.1S off
; 5 cycles per second
10HZ PWM
BSF PORTB,1
CALL DELAY 0.1S_DELAY
BCF PORTB,1
CALL DELAY 0.1S_DELAY
;=====================
;=====================
;0.1S on - 0.1S off
; 5 cycles per second
1HZ_PWM
BSF PORTB,1
CALL DELAY 0.1S_DELAY
movlw .10
mowf COUNT1
decfsz COUNT1,F
goto 1HZ_PWM
BCF PORTB,1
CALL DELAY 0.1S_DELAY
movlw .10
mowf COUNT1
decfsz COUNT1,F
goto 1HZ_PWM
movlw .10
mowf COUNT1
decfsz COUNT1,F
goto 1HZ_PWM
movlw .10
mowf COUNT1
decfsz COUNT1,F
goto 1HZ_PWM
movlw .10
mowf COUNT1
decfsz COUNT1,F
goto 1HZ_PWM
return
;=====================
0.1S_DELAY
.....
return
Sorry if this is the ugliest code you have ever seen, but I thought I would be better off showing you my attempt at it.