FREQOUT PORTA.0, 100,1000
I am just looking for ideas and examples.In case if you already know all of this, then what is you question
;=======================================
ORG 4
INT_SERVE: ; 2
MOVWF TEMP_W
SWAPF STATUS,W
CLRF STATUS ; Select RAM BANK0
MOVWF TEMP_S
MOVF PCLATH,W
MOVWF TPCLATH
CLRF PCLATH
;--------------------------------------------------
BTFSC SELECT_PIN
INCF PHASE_CNT,F
BTFSS SELECT_PIN
DECF PHASE_CNT,F
;
CALL GET_PHASE ; 8
MOVWF PORTB
;--------------------------------------------------
UPD_TIMER:
BTFSS UPD_TMR_VAL
GOTO UPD_TIMER_END
BCF UPD_TMR_VAL
;
MOVF TMR_VAL,W
MOVWF CCPR1L
MOVF TMR_VAL+1,W
MOVWF CCPR1H
UPD_TIMER_END:
;--------------------------------------------------
INT_SERVE_END:
BCF PIR1,CCP1IF
;
MOVF TPCLATH,W
MOVWF PCLATH
SWAPF TEMP_S,W
MOVWF STATUS
SWAPF TEMP_W,F
SWAPF TEMP_W,W
;
RETFIE ; 2
;=======================================
GET_PHASE:
MOVF PHASE_CNT,W
ANDLW B'00000011'
ADDWF PCL,F
RETLW B'00000101'
RETLW B'00001001'
RETLW B'00001010'
RETLW B'00000110'
;--------------------------------------------------
Andy_123 said:Just a quick update:
I was going over the program last night - I think it will do the job, I will modify interruput routie a little and add analog input readings.
- What is a max value in ccpr1l? 2^16-1= 65535?
If yes I will need to set only CCPR1L for all dividers leaving CCPR1H=0.
This will reduce a lookup table size from 2000 to 1000 values.
- Timer value updated only at the interrupt routine (ccpr1l, ccpr1h):
Can this be done in the main program?
I see the reaction time issue at the low speeds and at speed "0"
Yes, this is what I was planning to do, I just did not worded it correctly.I would recommend to add the analog input readings on the main program instead of the ISR
I did not realise that CCPR1H and CCPR1L are 8 bit each - my mistake, I will be using both.The maximum value is 65535. If CCPR1H is fixed at 0, the maximum value of the pair becomes 255. Therefore the minimum frequency is 2,500,000/255=9.8Khz. To generate 50Hz, you would need a value of 50,000 or CCPR1H=0C3h, CCPR1L=50h.
It takes 4 interrupts to generate a complete sequence, right?
With max interrupt rate of 50kHz we can generate only 12.5Khz stream not 50Khz.
If this is correct what will be the best way to correct it: change value in CCPR1?
;=======================================
ORG 8
INT_SERVE:
MOVLW 80h
ADDWF PHASE_CNT,F
;
BTFSC SELECT_PIN
RLCF PORTB,F ; All 8 bits must be used as outputs!
BTFSS SELECT_PIN
RRCF PORTB,F ; All 8 bits must be used as outputs!
;--------------------------------------------------
UPD_TIMER:
BTFSS UPD_TMR_VAL
BRA UPD_TIMER_END
BCF UPD_TMR_VAL
;
MOVFF TMR_VAL,CCPR1L
MOVFF TMR_VAL+1,CCPR1H
UPD_TIMER_END:
;--------------------------------------------------
INT_SERVE_END:
BCF PIR1,CCP1IF
;
RETFIE FAST ; Use fast return stack
;=======================================
;=======================================
ORG 8
INT_SERVE:
MOVLW 40h
ADDWF PHASE_CNT,F
RLCF PHASE_CNT,W ; Shift bit7 -> CARRY -> PORTB
;
BTFSC SELECT_PIN
RLCF LATB,F ; was PORTB
BTFSS SELECT_PIN
RRCF LATB,F ; was PORTB
;--------------------------------------------------
UPD_TIMER:
BTFSS UPD_TMR_VAL
BRA UPD_TIMER_END
BCF UPD_TMR_VAL
;
MOVFF TMR_VAL,CCPR1L
MOVFF TMR_VAL+1,CCPR1H
UPD_TIMER_END:
;--------------------------------------------------
INT_SERVE_END:
BCF PIR1,CCP1IF
;
RETFIE FAST ; Use fast return stack
;=======================================
Can we make routine shorter by updating timer values every interrupt even no change in value ?
These 3 instructions will be gone:
BTFSS UPD_TMR_VAL
BRA UPD_TIMER_END
BCF UPD_TMR_VAL
Will interrupt automatically save stack or I need to execute
CALL <adr>, fast ?
Any additional configuration registers I need to set?
really like the idea to use RLCF and RRCF instead of table !!!
INT_SERVE:
BTFSC SELECT_PIN
RLNCF LATB,F ; was PORTB
BTFSS SELECT_PIN
RRNCF LATB,F ; was PORTB
PHASE_CNT PORTB
00000000 -> bit7 of PHASE_CNT -> 00000000
01000000 -> bit7 of PHASE_CNT -> 00000000
10000000 -> bit7 of PHASE_CNT -> 00000001
11000000 -> bit7 of PHASE_CNT -> 00000011
00000000 -> bit7 of PHASE_CNT -> 00000110
01000000 -> bit7 of PHASE_CNT -> 00001100
10000000 -> bit7 of PHASE_CNT -> 00011001
11000000 -> bit7 of PHASE_CNT -> 00110011
00000000 -> bit7 of PHASE_CNT -> 01100110
01000000 -> bit7 of PHASE_CNT -> 11001100
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?