PA3040
Advanced Member level 3
- Joined
- Aug 1, 2011
- Messages
- 883
- Helped
- 43
- Reputation
- 88
- Reaction score
- 43
- Trophy points
- 1,308
- Activity points
- 6,936
bsf T1CON,TMR1CS ; External clock from pin RC0/T1OSO/T1CKI (on the rising edge)
bsf T1CON,T1OSCEN ;Oscillator is enabled
bcf T1CON,T1SYNC ;Synchronize external clock input
bsf T1CON,TMR1ON ; turn TMR1 on
bsf T1CON,T1CKPS0 ; set Timer1 Pre-scale to 1:8 using
bsf T1CON,T1CKPS1
Dear All
My attached picture for PIC 16f877a seven segment display clock using timer1 external clock
Oscillator mode is enable correctly and my actual hardware is working but Proteus does not working
Please advice, Am I connected correctly watch Crystal to T1OS0 and T1OS1 pins
when I select the internal clock source then it is working properly
Code:bsf T1CON,TMR1CS ; External clock from pin RC0/T1OSO/T1CKI (on the rising edge) bsf T1CON,T1OSCEN ;Oscillator is enabled bcf T1CON,T1SYNC ;Synchronize external clock input bsf T1CON,TMR1ON ; turn TMR1 on bsf T1CON,T1CKPS0 ; set Timer1 Pre-scale to 1:8 using bsf T1CON,T1CKPS1
View attachment 91519
Please advice
Hi PA,
Isis does not recognize crystals attached to the pic, be it the main oscillator or some thing like timer1.
The main oscillator is set by Right clicking the Pic chip and Editing its properties for the frequency you need.
For signal inputs like timer1 and other ports you have to use the Generator Fuction, select the type of signal you require, then Right Click the generator and edit its properties for the frequency etc as show in the picture
I don't use Proteus but based on peoples experiences I read on here, I wouldn't trust it. If you want to simulate, I would suggest you inject 32768Hz into T1OSCI and just trust it would work in real life with a crystal fitted.
Brian.
BSF TRISC, T1OSO ; RC0 needs to be input for the oscillator to function
Note: The loading of either TMR1H or TMR1L
causes the prescaler to be cleared.When
Timer1 is in operation, extreme care
should be taken in modifying either the
TMR1H or TMR1L registers, since this
automatically configures the prescaler
to 1.
Dear WP100 / BrianHi,
Post your code and circuit for us to see /check...
ISR call Save_Regs
btfss PIR1,TMR1IF
goto Finish_Int
bcf PIR1,TMR1IF
movlw 0X80
movwf TMR1H
incf seg1
call Restore_Regs
retfie
Save_Regs
movwf Tmp_WREG
swapf STATUS,W
movwf Tmp_STATUS
movf PCLATH,W
movwf Tmp_PCLATH
return
Finish_Int
Restore_Regs
movf Tmp_PCLATH,W
movwf PCLATH
swapf Tmp_STATUS,W
movwf STATUS
swapf Tmp_WREG,F
swapf Tmp_WREG,W
return
Have you built it on a breadboard, the thin leads of the crystal and caps can give contact problems in them, so loosing the signals /time
; ***************************************************************************
; SETUP AND INIT TIMER1
movlw 0x80 ; preload tmr1h with h80 to give 1sec
movwf TMR1H
clrf TMR1L
clrf INTCON
clrf PIR1
bsf STATUS,RP0 ; bank1
clrf PIE1 ; disable all ints
bsf TRISC,0 ; set bit0 as tmr osc
bsf PIE1,TMR1IE ; enable tmr1 int
bcf STATUS,RP0
clrf PIR1
bsf INTCON,PEIE ; ENABLE PERIPH INT
bsf INTCON,GIE ; ENABLE GLOBAL INT
movlw 0x0E ; set t1 functions/ osc,extck,asy,p1
movwf T1CON
bsf T1CON,TMR1ON ; tm1 on
Hi,
Your ISR looks the same as mine, wonder if your Timer1 set up is the same ?
Also assume you have tried a different crystal and caps ? - I just use the cheapo watch crystals.
Code:; *************************************************************************** [QUOTE]Your ISR looks the same as mine, wonder if your Timer1 set up is the same ? [/QUOTE] This is my Timer1 setup [CODE]setup clrf PORTD clrf PORTC banksel TRISC clrf TRISD clrf TRISC bsf PIE1,TMR1IE banksel PORTC movlw 0X80 movwf TMR1H clrf TMR1L bsf T1CON,TMR1CS ; Set clock source Extranal bsf T1CON,T1OSCEN ;1 = Oscillator is enabled bsf T1CON,T1SYNC ;1 = Do not synchronize external clock input bcf T1CON,T1CKPS0 ; set Timer1 Pre-scale to 1:1 using bcf T1CON,T1CKPS1 ; T1CKPS0 and T1CKPS1 bsf T1CON,TMR1ON ; turn TMR1 on bcf PIR1,TMR1IF bsf INTCON,PEIE bsf INTCON,GIE clrf seg1 clrf seg2 clrf seg3 clrf seg4 return
The only other thing that could be causing a code problem is if somewhere else you are turning off the interrupts for a short while ??
No, Interrupt only off in the ISR ( GIE =0)
Please advice
The code looks OK but you can make it a little quicker. Instead of calling the routines to save and restore the registers, put them inside the ISR itself. They will only be used there anyway so all you are doing is adding an extra call and return instruction where they are not necessary. I suspect the capacitors are the problem, I suggest you replace one of them with a small 2-22pF trimmer so you can tweak the frequency exactly.
Brian.
Hi,
What is your main oscillator frequency ? - assume it is something reasonably fast over 500Khz ?
You have not said if you tried another crystal or 2 new caps, they are easily damaged by soldering.
The difference will not be great but I will explain:
You should still save the STATUS and W registers because you cannot tell when the interrupt will occur withing the flow of the rest of the program and these are likely to be trashed by the ISR. Remember that the bank select bits are in the STATUS register so they may be wrong to access TMR1 at entry and when set to TMR1, they may be wrong as the main program resumes.
However, TMR1 starts counting from 0x8000 as soon as that value is loaded into it and you want it to keep counting without any breaks. Therefore for best accuracy you should re-load it as soon as possible. At the moment you are adding an unneccessary extra subroutine call and return instruction just to reach the context saving code and get back again. If you forget that code being a subroutine and place it in-line with the entry and exit of the ISR it will save several instructions delay. Incidentally, it would be a good idea to 'banksel' TMR1 before loading it. Don't forgret you can add or subtract a little from the value you load into TMR1 to slightly adjust it's timing. For example, loading it with 0x8001 will slightly speed up the clock and 0x7FFF will make it slightly slower.
Brian.
ssd clrf PORTD
movf seg1,w ; get digit to display
call table
movwf PORTD
movlw b'10000000' ; Active Display Selection
movwf PORTC
call delay
clrf PORTD
movf seg2,w
call table
movwf PORTD
movlw b'01000000' ; Active Display Selection
movwf PORTC
call delay
movlw .10
xorwf seg1,w ; test first digit
btfss STATUS,Z
goto ssd
clrf seg1 ; Clear digit1
incf seg2 ; Increment digit2
movlw .6
xorwf seg2,w ; test Second digit
btfss STATUS,Z
goto ssd
clrf seg1 ; Clear digit1
clrf seg2 ; Clear digit2
goto ssd
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?