Change square wave generator to rectangular wave with 30% duty cycle

463 views Asked by At

I have this code here for generating a square wave of 50% duty cycle and 0.1 Hz frequency with 8 MHz Fosc:

BCF TRISD,7
MOVLW   0x07
MOVWF   T0CON
HERE    MOVLW   0x67
MOVWF   TMR0L
MOVLW   0x69
MOVWF   TMR0H
BCF INTCON,TMR0IF
BTG PORTD,7
BSF T0CON,TMROON
AGAIN   BTFSS   INTCON,TMR0IF
BRA AGAIN
BCF T0CON,TMR0ON
BRA HERE

How can I modify this code in order to perform rectangular wave instead of square wave and with 30% duty cycle instead of 50%?

1

There are 1 answers

0
AudioBubble On

Thanks for the help Mr Weather Vane I have edited the code to perform the 30% duty cycle but the delay part I couldn't solve it so far....

Here is the update..

BCF TRISD,2
MOVLW   0x07
MOVWF   T0CON
HERE:   MOVLW   0xE5
MOVWF   TMR0L
MOVLW   0x48
MOVWF   TMR0H
BCF INTCON,TMR0IF
BTG PORTD,2
BSF T0CON,TMR0ON
AGAIN:  BTFSS   INTCON,TMR0IF
BRA AGAIN
BCF T0CON,TMR0ON
BRA HERE