Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

TMR0+counter don-t work together?

Status
Not open for further replies.

spotter-b

New Member
hellow!
when using the following script work perfectly, but if I uncoment the 3 lines labelled salto1: the routine stop working in a 16F84, also in a 16F628A, somebody know why?.
Thanks!

newlight: movlw 1e; 0d6
movwf ct15

timing1: Banco1
bcf intcon,2;clear de overflow flag
bcf optionr,0
bsf optionr,1
bsf optionr,2; tmr0 rate= 1:255
;bsf gie; habilita todas las interrupciones
;bsf intcon,5; habilita interupcion tmr0
bcf optionr,3; tmr0=activado
bcf optionr,5; reloj interno= on
;verificamos si el tmr0 es overflow
timing2: btfss intcon,2; toif; intcon,5; tmr0=overflow
goto timing2b
goto salto1
timing2b: Banco0
bsf portb,6
goto timing2

;salto1: bcf intcon,2
; decfsz ct15
; goto timing1

salto1: Banco0
bcf intcon,2;clear de overflow flag

Banco1
bsf Trisb,4;rb4= in
Banco0
btfss portb,4; bifurcacion 0/1
goto sicero
call rel4off;bsf portb,4; rb4=1
call rel5off
goto rama1
sicero: call rel4on;bcf portb,4; rb4=0
call rel5on
rama1: goto newlight
;.....................................................
 
hi,
In which type of PIC does it work perfectly.??
 
Last edited:
hi,
OK, so please post your full code so that we can check it out.

thanks!
this small script only flick on & off the leds 4 & 5 at a rate giving by TMR0 + CT15.
the MPLAB !!does do it!!, but the micro in the circuit does not!!
checking the pins with a Tektronik does not show any oscilation:

tmr0 equ 0x01
optionr equ 0x81
status equ 0x03
Trisa equ 85H
Porta equ 0x05
Trisb equ 86H
portb equ 0x06
intcon equ 0x0b
acub equ 0x0c
stab equ 0x0d
ct1 equ 0x0e
ct2 equ 0x0f
F equ 1
W equ 0
ct3 equ 0x10
ct4 equ 0x12

ct5 equ 0x14
ct6 equ 0x15
ct7 equ 0x16
ct8 equ 0x17
ct12 equ 0x22
ct15 equ 0x28

#define gie intcon,7
#define intf intcon,1
#define toif intcon,5
#define Banco0 Bcf status,5
#define Banco1 bsf status,5

;cierre del sw1
org 00
goto int1;int1;goto init
;.....................................................
;activacion de los reles
int1: call reloff; todos los leds= off

newlight: movlw 1e; 0d6
movwf ct15

timing1: Banco1
bcf intcon,2;clear de overflow flag
bsf optionr,0
bcf optionr,1
bcf optionr,2; tmr0 rate= 1:255
;bsf gie; habilita todas las interrupciones
;bsf intcon,5; habilita interupcion tmr0
bcf optionr,3; tmr0=activado
bcf optionr,5; reloj interno= on
;verificamos si el tmr0 es overflow
timing2: btfss intcon,2; toif; intcon,5; tmr0=overflow
goto timing2b
goto salto1
timing2b: Banco0
bsf portb,6
goto timing2

salto1: bcf intcon,2; overfow flag offf
call rel7on
decfsz ct15
; goto timing2 ;newlight ;timing1

Banco0
btfss portb,4; bifurcacion 0/1
goto sicero
call rel4off;bsf portb,4; rb4=1
call rel5off
goto rama1
sicero: call rel4on;bcf portb,4; rb4=0
call rel5on
rama1: goto newlight
;......................................................
redon Banco1
;movlw 01
;clrf Trisb
bsf Trisb,4
Banco0
bsf portb,3 ;red = on
return

relon ;Banco1
;movlw 01
;clrf Trisb
;movwf Trisb
Banco0
bsf portb,4
bsf portb,5
bsf portb,6
bsf portb,7
return
rel4on Banco1
;movlw 01
;clrf Trisb
;movwf Trisb
bcf Trisb,4
Banco0
bsf portb,4
return
rel5on Banco1
;movlw 01
;clrf Trisb
;movwf Trisb
bcf Trisb,5
Banco0
bsf portb,5
return
rel6on Banco1
;movlw 01
;clrf Trisb
;movwf Trisb
bcf Trisb,6
Banco0
bsf portb,6
return
rel7on Banco1
;movlw 01
;clrf Trisb
;movwf Trisb
bcf Trisb,7
Banco0
bsf portb,7
return

reloff Banco1
movlw 01
;clrf Trisb
movwf Trisb
Banco0
bcf portb,4
bcf portb,5
bcf portb,6
bcf portb,7
return
rel4off Banco1
;movlw 01
;clrf Trisb
;movwf Trisb
bcf Trisb,4
Banco0
bcf portb,4
return
rel5off Banco1
;movlw 01
;clrf Trisb
;movwf Trisb
bcf Trisb,5
Banco0
bcf portb,5
return
rel6off Banco1
;movlw 01
;clrf Trisb
bcf Trisb,6
Banco0
bcf portb,6
return
rel7off Banco1
;movlw 01
;clrf Trisb
bcf Trisb,7
Banco0
bcf portb,7
return

redoff Banco1
;movlw 01
;clrf Trisb
bcf Trisb,4
Banco0
bcf portb,3
return

end
 
hi,
As you are using MPLAB to assemble your code you should use the 'LIST, INCLUDE and CONFIG' at the start of your code listing. This will avoid the need to EQU all the PIC's special registers.

The ct15 register value is not being decremented to 0, ie: if you preload it with say 0xff [255] it only counts down by to 0xfe and then the program reloads with 0xff.!!!

The flash rate of the LED is VERY fast as you are using only 255 counts of the TIMER0. With a PIC internal clock of 1microsec you will never see the flash.

When you post a code listing wrap the list with the # sign , this will then retain the code formatting.

Look at the attached edit listing.:)
 

Attachments

  • timerbug1.asm
    3.2 KB · Views: 115
hi,
As you are using MPLAB to assemble your code you should use the 'LIST, INCLUDE and CONFIG' at the start of your code listing. This will avoid the need to EQU all the PIC's special registers.

The ct15 register value is not being decremented to 0, ie: if you preload it with say 0xff [255] it only counts down by to 0xfe and then the program reloads with 0xff.!!!

The flash rate of the LED is VERY fast as you are using only 255 counts of the TIMER0. With a PIC internal clock of 1microsec you will never see the flash.

When you post a code listing wrap the list with the # sign , this will then retain the code formatting.

Look at the attached edit listing.:)

Thanks Eric!
I try it , but it shows the following screen in the Mplab
""picture attached""
 

Attachments

  • errors.jpg
    errors.jpg
    128.7 KB · Views: 158
Thanks Eric!
I try it , but it shows the following screen in the Mplab
""picture attached""

hi,
Which version of MPLAB are you using, it assembles OK for me in MPLAB V7

Code:
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Asm4PICs2\Bryans1\MPLAB\tmrbug1.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F628A "timerbug1.asm" /l"timerbug1.lst" /e"timerbug1.err"
Loaded C:\Asm4PICs2\16F628A\timerbug1.cod.
[B]BUILD SUCCEEDED: Fri Jan 22 12:20:35 2010[/B]
 
hi,
Which version of MPLAB are you using, it assembles OK for me in MPLAB V7

Code:
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Asm4PICs2\Bryans1\MPLAB\tmrbug1.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F628A "timerbug1.asm" /l"timerbug1.lst" /e"timerbug1.err"
Loaded C:\Asm4PICs2\16F628A\timerbug1.cod.
[B]BUILD SUCCEEDED: Fri Jan 22 12:20:35 2010[/B]

Mplab 8.30, but I know why is show me that screen!!
I forgot to change the device in the configuration set
I wil try with it and I tell you
 
Looking at that avatar, I can see why!!!! Hehe.

so you don´t have anything to do?
nothing to say?
so why don´t you go to Haiti, they are happy receiving idle people there,
and maybe if we are lucky, the next earthquake will make a hole deep enough for you
to be swallow all the way down.
 
hi,
Which version of MPLAB are you using, it assembles OK for me in MPLAB V7

Code:
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Asm4PICs2\Bryans1\MPLAB\tmrbug1.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F628A "timerbug1.asm" /l"timerbug1.lst" /e"timerbug1.err"
Loaded C:\Asm4PICs2\16F628A\timerbug1.cod.
[B]BUILD SUCCEEDED: Fri Jan 22 12:20:35 2010[/B]

thanks Eric!
yes you are right, it was a problem of definition only
I have to take a close look of the way you right the definitions at the heading
but still I don´t know why it the Watch screen does show me in Portb, Status & Trisb= not found
I´ll be in the search!
and...
I own you a beer mate
just tell the me brand!!
thanks
 
thanks Eric!
yes you are right, it was a problem of definition only
I have to take a close look of the way you right the definitions at the heading
but still I don´t know why it the Watch screen does show me in Portb, Status & Trisb= not found
I´ll be in the search!
and...
I own you a beer mate
just tell the me brand!!
thanks

hi,

All the CONFIG's etc are supplied as part of MPLAB, mine are located here : C:\Program Files\Microchip\MPASM Suite\Template\Code

If you make a copy of the 16F628ATEMP.asm file for the ones you are working on, use it as a template for your planned program.

When you have debugged your existing program post the asm file and I'll run in thru the Oshonsoft sim.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top