• AVR Freaks

12F1822 TMR1 with gate control not working

Author
Birhan
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2019/03/07 03:28:36
  • Location: 0
  • Status: offline
2020/11/17 17:35:15 (permalink)
0

12F1822 TMR1 with gate control not working

Hi, ı'm digging google for hours and no results.
 
I'm trying measure PPM signal with gate control but TMR1 never counts while T1GCON,TMR1GE set.
If T1GCON,TMR1GE is low, TMR1 works as expected and overflow int. occurs.
mcu & code works perfectly except TMR1, I can read registers on OLED display so I must miss something on gate setup but can't find any problem. I'm trying Gate on RA4 without single pulse, mcu @32mhz, tmr1 1:1, gate high side, no TMR1 interrupt, only TMR1GIE interrupt.
 
I'm using mplab ide 8.92, main code is too long and most of it unrelated this problem (settings untouched) my config and setup is;
 __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_ON & _IESO_ON & _FCMEN_ON & 0x3FFF
 __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_ON & _BORV_LO & _LVP_OFF & 0x3FFF
 
initialize code
     org 0x0700
;********************************** Ayarlar ************************************
Ayarlar ;-------------- Bank -------------------------------------------------**
    goto    pinman
; I2C_Initialize ;----------------------------------------------------------+ **
    movlb   4           ; 4                                                 | **
    movlw   0x00        ; 4     +-----------> SSP1EN                        | **
    movwf   SSP1STAT    ; 4     |+----------> CKP                           | **
    movlw   0x38        ; 4     || ++++-----> I2CMaster Mode, clock = FOSC/(4*(SSP1ADD+1))(4)
    movwf   SSP1CON1    ; 4   0011 1000 =  0x38 = 56                        | **
    movlw   0x00        ; 4   0010 1000 =  0x28 = 40                        | **
    movwf   SSP1CON2    ; 4                                                 | **
    movlw   0x07        ; 4                                                 | **
    movwf   SSP1ADD     ; 4                                                 | **
    movlw b'11000000'   ;
    movwf   SSPSTAT     ;
    banksel PIR1
    bcf     PIR1,SSP1IF
    bcf     PIR2,BCL1IF
    ;bcf    SSP1CON1,SSPEN  ; 4                                             | **
pinman
    banksel CCP1CON
    clrf    CCP1CON
    
; PIN_MANAGER_Initialize ;--------------------------------------------------+ **
    banksel TRISA       ; Bank 1
    ;        RA 543210   RA0 <- POT RA1-RA2 I2C, RA4<-PPMin, RA5->PPMout,
    movlw   b'00010001' ;IO         ;   0011001
    movwf   TRISA       ; 1 0b0001 1110 TRISx registers

    banksel LATA        ; Bank 2
    movlw   b'00000110' ; All pins low except I2C's
    movwf   LATA        ; I2C iidle condition

    movlw   0x00        ;                                                   | **
    movwf   APFCON      ; 2 APFCONx registers                               | **
    
    movlb   3           ; 3 Bank 3
    movlw   0x00
    movwf   ANSELA      ; 3 ANSELx registers
    
    movlb   4           ; 4 Bank 4
    movlw   b'00000110'
    clrw
    movwf   WPUA        ; 4 WPUx registers
    ; OSCILLATOR_Initialize ;-----------------------------------------------+ **
    banksel BORCON      ; Bank 2
    clrf    BORCON      ; 2  SBOREN disabled                                | **
    movlb   1           ; 1 Bank 1                                          | **
    movlw   0x70        ;                                                   | **
    movwf   OSCCON      ; 1 SCS FOSC; SPLLEN disabled; IRCF 8MHz_HF;        | **
    movlw   0x00        ;                                                   | **
    movwf   OSCTUNE     ; 1 TUN 0                                           | **
PLLRbekle               ; PLL in sakinleşmesini bekle....                   | **
    btfss   OSCSTAT,PLLR; 1                                                 | **
;   goto    PLLRbekle   ;                                                   | **
; WDT_Initialize -----------------------------------------------------------+ **
    movlw   0x16        ;                                                   | **
    movwf   WDTCON      ; 1 WDTPS 1:65536; SWDTEN OFF;                      | **
; TMR2_Initialize ----------------------------------------------------------+ **
    movlb   0           ; 0 bank 0                                          | **
    goto    notimer2
    
    
    
    
    movlw   0xFF        ;
    movwf   PR2         ; 0 PR2 = 31
    clrf    TMR2        ; 0 TMR2 = 0
    bcf     PIR1,TMR2IF ; 0 Clearing IF flag before enabling the interrupt.
    ;         ++++---------------> Postscaler 0000 - 1111 = 1 - 16
    ;         |||| ++------------> Prescaler  00:1, 01:4, 10:16, 11:64
    movlw   b'00000000' ;
    movwf   T2CON       ; 0 0x0D; 1:8 post, 1:1 pre
    movlb   1           ; T2CKPS 1:4; T2OUTPS 1:2; TMR2ON on;
    bsf     PIE1,TMR2IE ; 1 Enabling TMR2 interrupt.

    
notimer2
; TMR1_Initialize ----------------------------------------------------------+ **
    banksel T1GCON      ; 0 bank 0                                          | **
    bcf     PIR1,TMR1IF ; 0 Clearing IF flag.
    bcf     PIR1,TMR1GIF; 0 Clearing IF flag before enabling the interrupt.
        ;     +-> 7 TMR1GE: Timer1 Gate Enable 1=Enable
        ;     |+-> 6 T1GPOL: Timer1 Gate Polarity bit 1=Active Hi, 0=Active Lo
        ;     ||+-> 5 T1GTM: Timer1 Gate Toggle Mode 1=Enable
        ;     |||+-> 4 T1GSPM: Timer1 Gate Single-Pulse Mode 1=Enable
        ;     ||||+-> 3 T1GGO/DONE: Timer1 Gate Single-Pulse Acquisition Status bit
        ;     |||||+-> 2 T1GVAL: Timer1 Gate Current State bit
        ;     ||||||++-> 1-0 T1GSS<1:0>: Timer1 Gate Source Select
    movlw   b'11000000' ;00 = Timer1 Gate pin
;   movlw   128
    movwf   T1GCON      ; 80 01010000
        ;    +-> 7-6 TMR1CS<1:0>: Timer1 Clock Source 00 = (FOSC/4)
        ;    | +-> 5-4 T1CKPS<1:0>: Timer1 Input Clock Prescale 00 = 1:1
        ;    | |+-> 3 T1OSCEN: LP Oscillator Enable 0=Disable
        ;    | ||+-> 2 T1SYNC: Timer1 External Clock Input Synchronization Control 0=Not Sync
        ;    | |||+-> 1 Unimplemented: Read as ‘0’
        ;   ++++|||+-> 0 TMR1ON: Timer1 On/Off
    movlw b'00000101'   ;
    movwf   T1CON       ; 35 00100011
    clrf    TMR1L
    clrf    TMR1H
; TMR0_Initialize ----------------------------------------------------------+ **
    banksel OPTION_REG
        ;   +-> WPUEN: Weak Pull-up Enable bit 0=Enable
        ;   |+-> INTEDG: Interrupt Edge Select bit 1=RB0 rising, 0=RB0 falling
        ;   ||+-> TMR0CS: Timer0 Clock Source Select bit 1=RA4, 0= FOSC/4
        ;   |||+-> TMR0SE: Timer0 Source Edge Select bit 1=high->low 0=low->high
        ;   ||||+-> PSA: Prescaler Assignment bit 0=Timer0, 1 = WDT
        ;   |||||+++-> Prescaler 000:2, 001:4, 010:8, 011:16, 100:32, 101:64, 110:128, 111:256
    movlw b'10000111'       ;
    movwf   OPTION_REG      ; 1
    movlb   0               ; 0 Bank 0
; INTCON Initialize ----------------------------------------------------------+ **
    clrf    INTCON          ;
        ;   +-> 7 GIE: Global Interrupt Enable 1=Enable
        ;   |+-> 6 PEIE: Peripheral Interrupt Enable 1=Enable
        ;   ||+-> 5 TMR0IE: Timer0 Overflow Interrupt Enable 1=Enable
        ;   |||+-> 4 INTE: INT External Interrupt Enable 1=Enable
        ;   ||||+-> 3 IOCIE: Interrupt-on-Change Enable 1=Enable
        ;   |||||+-> 2 TMR0IF: Timer0 Overflow Interrupt Flag
        ;   ||||||+-> 1 INTF: INT External Interrupt Flag
        ;   |||||||+-> 0 IOCIF: Interrupt-on-Change Interrupt Flag
    movlw b'00100000'       ;
    movwf   INTCON
;******************************** Ayarlar Sonu *********************************
; EEPROM ayar ----------------------------------------------------------------**
    banksel EECON1          ;
    clrf    EECON1          ;
; I2C idle -------------------------------------------------------------------**
    banksel LATA
    clrf    Global_16       ; En son global değişken
    bsf     Global_16,clk   ; clk pin = 1
    bsf     Global_16,dat   ; dat pin = 1
    movfw   Global_16       ; Neden doğrudan LATA yı kullanmıyoruz?
    movwf   LATA            ; Çünkü clk/data HI/LO sırası I2C start/stop/ack
                            ; anlamlarına gelebilir ama aynı anda HI/LO etkisizdir
    banksel 0
    call    Delay90ms       ; OLED Kendine gelsin diye biraz bekle

;********************************* OLED Init ***********************************
    call    I2C_Start
    movlw   I2C_Adres
    call    I2C_Write
    clrw
    call    I2C_Write

    movlw   0xAE        ; 10101110 DISPLAYOFF                                 **
    call    I2C_Write   ;                                                     **
    movlw   0xD5        ; 11010101 SETDISPLAYCLOCKDIV                         **
    call    I2C_Write   ;                                                     **
    movlw   0x80        ; 10000000 the suggested ratio 0x80                   **
    call    I2C_Write   ;                                                     **
    movlw   0xA8        ; 10101000 SETMULTIPLEX                               **
    call    I2C_Write   ;                                                     **
    movlw   32-1        ; 00011111 LCDHEIGHT                                  **
    call    I2C_Write   ;                                                     **
    movlw   0xD3        ; 11010011 SETDISPLAYOFFSET                           **
    call    I2C_Write   ;                                                     **
    movlw   0x00        ; 00000000 no offset                                  **
    call    I2C_Write   ;                                                     **
    movlw   0x40 | 0x0  ; 01000000 SETSTARTLINE line #0                       **
    call    I2C_Write   ;                                                     **
    movlw   0x8D        ; 10001101 CHARGEPUMP                                 **
    call    I2C_Write   ;                                                     **
    movlw   0x14        ; 00010100 internal VCC                               **
    call    I2C_Write   ;                                                     **
    movlw   0x20        ; 00100000 MEMORYMODE                                 **
    call    I2C_Write   ;                                                     **
    movlw   0x00        ; 00000000 horizontal addressing page addressing      **
    call    I2C_Write   ;                                                     **
    movlw   0xA0 | 0x0  ; 10100001 SEGREMAP rotate screen 180 Sağdan sola     **
    call    I2C_Write   ;                                                     **
    movlw   0xDA        ; SETCOMPINS                                          **
    call    I2C_Write   ;                                                     **
    movlw   0x02        ;                                                     **
    call    I2C_Write   ;                                                     **
    movlw   0x8         ; SETCONTRAST                                         **
    call    I2C_Write   ;                                                     **
    movlw   0x8F        ;                                                     **
    call    I2C_Write   ;                                                     **
    movlw   0xd9        ; SETPRECHARGE                                        **
    call    I2C_Write   ;                                                     **
    movlw   0xF1        ;                                                     **
    call    I2C_Write   ;                                                     **
    movlw   0xDB        ; SETVCOMDETECT                                       **
    call    I2C_Write   ;                                                     **
    movlw   0x40        ;                                                     **
    call    I2C_Write   ;                                                     **
    movlw   0xA4        ; DISPLAYALLON_RESUME                                 **
    call    I2C_Write   ;                                                     **
    movlw   0xA6        ; NORMALDISPLAY                                       **
    call    I2C_Write   ;                                                     **
    movlw   0x2E        ; DEACTIVATE_SCROLL                                   **
    call    I2C_Write   ;                                                     **
    movlw   0xAF        ; DISPLAYON -- turn on oled panel                     **
    call    I2C_Write   ;                                                     **
    movlw   0x21        ; COLUMNADDR                                          **
    call    I2C_Write   ;                                                     **
    movlw   0           ; Column start address (0 = reset)                    **
    call    I2C_Write   ;                                                     **
    movlw   127         ; Column end address (127 = reset) (LCDWIDTH)         **
    call    I2C_Write   ;                                                     **
    movlw   0x22        ;                                                     **
    call    I2C_Write   ;                                                     **
    movlw   0           ; Page start address (0 = reset)                      **
    call    I2C_Write   ;                                                     **
    movlw   3           ; Page end address                                    **
    call    I2C_Write   ;                                                     **
;-----------------------------------------------------------------------------**
    call    I2C_Stop
;******************************* OLED Init Sonu ********************************
    banksel TMR0
    clrf    TMR0        ; TMR0 ı sıfırdan başlat
    bsf     INTCON,GIE  ; Global Interruptları aç
    bsf     INTCON,PEIE ; Pripheral Interruptları aç
    bsf     T1CON,TMR1ON; TMR1 açık
    banksel PIE1            ; 1 Bank 1
    clrf    PIE1
    bsf     PIE1,TMR1GIE; 1 Enabling TMR1 GATE interrupt.
    banksel 0
    bsf     T1GCON,T1GGO
    goto    Basla
;******************************** Ayarlar Sonu *********************************




 
Thanks.
#1

4 Replies Related Threads

    Birhan
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2019/03/07 03:28:36
    • Location: 0
    • Status: offline
    Re: 12F1822 TMR1 with gate control not working 2020/11/21 08:09:40 (permalink)
    0
    Registers  Rest/after initialize;
          REGISTER          RESET   INITIALISE   CHANGED BITS
    1 PCL = 00000000 10101000
    2 STATUS = 00011000 00011101 Z:(2)1 C:(0)1
    3 WREG = 00000000 00001000
    4 INTCON = 00000000 11100000 GIE:(7)1 PEIE:(6)1 TMR0IE:(5)1
    5 PORTA = 00001000 00001110 RA2:(2)1 RA1:(1)1
    6 TMR1 = 00110010 00000000
    7 TMR1L = 00110010 00000000
    8 T1CON = 00000000 00000101 NOT_T1SYNC:(2)1 TMR1ON:(0)1
    9 T1GCON = 00000100 11000000 TMR1GE:(7)1 T1GPOL:(6)1 T1GVAL:(2)0
    10 TRISA = 00111111 00011001 TRISA5:(5)0 TRISA2:(2)0 TRISA1:(1)0
    11 PIE1 = 00000000 10000000 TMR1GIE:(7)1
    12 OPTION_REG = 11111111 10000111 INTEDG:(6)0 TMR0CS:(5)0 TMR0SE:(4)0 PSA:(3)0
    13 OSCCON = 00111000 01110000 IRCF3:(6)1 IRCF0:(3)0
    14 ADCON0 = 00000000 00000001 ADON:(0)1
    15 ADCON1 = 00000000 01010000 ADCS2:(6)1 ADCS0:(4)1
    16 CM1CON0 = 00000100 00000000 C1SP:(2)0
    17 BORCON = 10000000 00000000 SBOREN:(7)0
    18 FVRCON = 00000000 10001111 FVREN:(7)1 CDAFVR1:(3)1 CDAFVR0:(2)1 ADFVR1:(1)1 ADFVR0:(0)1
    19 ANSELA = 00010111 00000001 ANSA4:(4)0 ANSA2:(2)0 ANSA1:(1)0
    20 WPUA = 00001000 00000000 WPUA3:(3)0
    21 BSR_SHAD = 00000001 00000000
    post edited by Birhan - 2020/11/21 08:23:46
    #2
    Birhan
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2019/03/07 03:28:36
    • Location: 0
    • Status: offline
    Re: 12F1822 TMR1 with gate control not working 2020/11/21 15:05:52 (permalink)
    0
    Hi again,
    My team (me, myself and I) decide move T1G pin to RA3 instead of RA4 and problem solved (Kind of)
     
    thank you for not being interested.
    #3
    ric
    Super Member
    • Total Posts : 28967
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: 12F1822 TMR1 with gate control not working 2020/11/21 15:12:09 (permalink)
    +2 (2)
    RA4 is also CLKOUT.
    Your _CLKOUTEN_ON config setting will be overriding the pin function.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    Birhan
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2019/03/07 03:28:36
    • Location: 0
    • Status: offline
    Re: 12F1822 TMR1 with gate control not working 2020/11/21 17:14:50 (permalink)
    0
    Good catch, I'm getting old...
    But no clkout on pin RA4, my  scope only shows the signal to be measured (correctly) and yes i changed config to _CLKOUTEN_OFF and its worked now...
     
    Thank you.
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5