• AVR Freaks

AnsweredHot!Timer0 16 bits

Page: 123 > Showing page 1 of 3
Author
Chabb
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2019/11/14 10:16:01
  • Location: 0
  • Status: offline
2019/11/15 03:59:35 (permalink)
0

Timer0 16 bits

MPLABX ide V5.30 under window 7. I cannot use timer0 in 16 bits mode. T0CON0 is 90h.
tmr0l gives an interrupt when it overrun. Never reports to tmr0h.
#1
hexreader
Super Member
  • Total Posts : 1036
  • Reward points : 0
  • Joined: 2008/05/04 03:06:55
  • Location: England
  • Status: offline
Re: Timer0 16 bits 2019/11/15 11:52:50 (permalink)
0
Which MCU?
 
PIC ?  Atmel?   Exactly which one?

Experienced Hobbyist
#2
AMPS
Super Member
  • Total Posts : 468
  • Reward points : 0
  • Status: offline
Re: Timer0 16 bits 2019/11/15 20:23:09 (permalink)
0
which controller,which compiler
If use MPLAB X ide with code configuration it should show 16 bit timer in Timer

Amps
*.*.*.*.*.*.*.*.*.*.*.*.*
#3
Chabb
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2019/11/14 10:16:01
  • Location: 0
  • Status: offline
Re: Timer0 16 bits 2019/11/18 03:44:29 (permalink)
0
Thank AMPS I use mplabx ide simulator Pic18f25k42. mpasm v5.30.
#4
AMPS
Super Member
  • Total Posts : 468
  • Reward points : 0
  • Status: offline
Re: Timer0 16 bits 2019/11/18 04:13:41 (permalink)
0
Select the compiler XC8  v X.X instead of mpasm v5.30.  you might downloaded Xc8 .
Then goto MCC code config -> select timer0-> then 16bit 
 
enable timer bit and start coding
i have attached img for reference
 
post edited by AMPS - 2019/11/18 04:31:25

Attachment(s)

Attachments are not available: Download requirements not met

Amps
*.*.*.*.*.*.*.*.*.*.*.*.*
#5
1and0
Access is Denied
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Timer0 16 bits 2019/11/18 04:37:20 (permalink)
+1 (1)
ajitnayak87
Select the compiler XC8  v X.X instead of mpasm v5.30.

Why?  The XC8 compiler will NOT "assemble" assembly code written in MPASM syntax.
#6
ric
Super Member
  • Total Posts : 24608
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Timer0 16 bits 2019/11/18 04:50:30 (permalink)
+1 (1)
I suspect AMPS is not aware that MCC can generate assembly source.
 

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!
#7
1and0
Access is Denied
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Timer0 16 bits 2019/11/18 10:34:53 (permalink)
+1 (1)
Chabb
I use mplabx ide simulator Pic18f25k42. mpasm v5.30.


I just upgraded and installed MPLAB X v5.30 and tested the simulator briefly for the PIC18F25K42. The Simulator has bugs simulating Timer0. With the following code:
        #include "p18f25k42.inc"
        config  XINST = OFF
        config  WDTE = OFF
    
        org     0x0000
        movlw   b'00010000'    ; 16-bit timer, postscaler 1:1
        movwf   T0CON0
        movlw   b'01010000'    ; Fosc/4 clock source, asynch, prescaler 1:1
        movwf   T0CON1
        movlw   0xFF           ; TMR0 = 0xFF00
        movwf   TMR0H
        clrf    TMR0L
        bsf     T0CON0,EN      ; Timer0 On (Reset Stopwatch here)
       
        banksel PIR3
        bcf     PIR3,TMR0IF
main    btfsc   PIR3,TMR0IF
        bra     $              ; Breakpoint here, Stopwatch cycle count = 65540
        bra     main
        end

Here are what I have observed so far:
  • it does not load the high byte of Timer0, since it takes over 65K cycles to overflow, and
  • TMR0_Internal in the Watches and Variables windows does not reflect the internal Timer0 value (always shown as 0x0000).

Maybe George Pauley can comment on this.
 
post edited by 1and0 - 2019/11/18 10:38:44
#8
Chabb
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2019/11/14 10:16:01
  • Location: 0
  • Status: offline
Re: Timer0 16 bits 2019/11/18 12:01:00 (permalink)
0
thank you 1and0 you observe exactly the same as me your explanation is better than mine. I tryed the last week with the compiler XC8 but it did not appreciate my literature! then I return whit mpasm. so we are waiting for a correction from Microchip. best regards.
#9
1and0
Access is Denied
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Timer0 16 bits 2019/11/18 12:05:10 (permalink)
+3 (3)
Chabb
so we are waiting for a correction from Microchip.

That might take a while. ;)  Best to test with the real hardware!
 
#10
ric
Super Member
  • Total Posts : 24608
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Timer0 16 bits 2019/11/18 12:15:29 (permalink)
+3 (3)
... and now you see why many of us don't trust the simulator for precisely simulating 100% of the hardware.
I always do my real testing on real hardware, and only resort to the simulator if I have some complex logic I want to double check.
 

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!
#11
Chabb
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2019/11/14 10:16:01
  • Location: 0
  • Status: offline
Re: Timer0 16 bits 2019/11/18 12:46:03 (permalink)
0
Few years ego I program in MPLAB 8.91 one 18f2520. the simulator and the hardware cabled on a PWB both worked perfecly. now I choose a pic18f25k42 that seems the same chip and gives me the possibility to run whit internal oscillator 64Mhz witch I need. I belleve the soft conversion
aisy... It is not! thank all friends for your help.
#12
Chabb
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2019/11/14 10:16:01
  • Location: 0
  • Status: offline
Re: Timer0 16 bits 2019/11/19 03:52:39 (permalink)
0
Before to buy a chip I look for and test his functionnalities. if I connot program the chip in 
MPLABX simulator using asm I dont buy it. Some basic functions to easily program Pic 18f25k42 does not work. that is not a good point of vue for microchip. they have to accelerate the  needed
corrections. For ten years ego i used MPLAB8 that does not support Pic 18 16 bits; I try MPLABX
v.5.25 then v.5.30 and always the same bugs. What to do ?
#13
ric
Super Member
  • Total Posts : 24608
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Timer0 16 bits 2019/11/19 03:59:50 (permalink)
+1 (1)
Complain to Microchip. You're just talking to other users here.
 

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!
#14
1and0
Access is Denied
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Timer0 16 bits 2019/11/19 04:10:22 (permalink)
+2 (2)
Chabb
that is not a good point of vue for microchip. they have to accelerate the  needed corrections. 

Don't hold your breath. ;) Microchip has known of a bug with the LFSR instruction in relocatable mode for the PIC18F K42 family for over one year and still not a fix in sight. :(  And this is a more serious and urgent issue than any simulator bug, because it basically means one cannot use the LFSR instruction in relocatable mode at all -- it generates the wrong opcode.
#15
GeorgePauley
Moderator
  • Total Posts : 1184
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Timer0 16 bits 2019/11/19 09:29:41 (permalink)
+1 (1)
1and0
Here are what I have observed so far:
  • it does not load the high byte of Timer0, since it takes over 65K cycles to overflow, and
  • TMR0_Internal in the Watches and Variables windows does not reflect the internal Timer0 value (always shown as 0x0000).

 
Haven't investigated this in depth, just pulling from my memory... 
 
As I recall there's a weird bit of interplay between TMR0H and TMR0L.  Something like TMR0H can only be read after TMR0L has been read?  I kind of remember doing some contortions in the code to make it look like this is what's happening.  (Simulator is, of course, keeping track of what's really in TMR0H internally.)

As to TMR0_Internal, these psuedo-16-bit registers  are left-overs from the MPLAB 8 days.  The MPLAB X simulator doesn't really pay any attention to them.

Again, this is from admittedly shaky memory.  So many devices, so many peripherals, there's really no hope of keeping it all straight.
#16
1and0
Access is Denied
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Timer0 16 bits 2019/11/19 10:33:19 (permalink)
+2 (2)
GeorgePauley
Haven't investigated this in depth, just pulling from my memory... 
 
As I recall there's a weird bit of interplay between TMR0H and TMR0L.  Something like TMR0H can only be read after TMR0L has been read?  I kind of remember doing some contortions in the code to make it look like this is what's happening.  (Simulator is, of course, keeping track of what's really in TMR0H internally.)

Refresh your memory by reading the "TimerX 16-Bit Read/Write Mode" section of any 8-bit PIC datasheet.


As to TMR0_Internal, these psuedo-16-bit registers  are left-overs from the MPLAB 8 days.  The MPLAB X simulator doesn't really pay any attention to them.

It should, because these pseudo registers display the internal values of the timer; i.e. it shows all 16 bits of the timer value (and prescaler value) without having to do a read of the low byte.  This is useful in a simulator as these are not directly readable.
 
#17
Chabb
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2019/11/14 10:16:01
  • Location: 0
  • Status: offline
Re: Timer0 16 bits 2019/11/20 07:06:38 (permalink)
0
1and0-George Pauley attractive debat but the main problem is that timer does not count 16bits. it provide an interrupt when timer low runs over 255.That is not only one question of watches in file register window.The problem I think is more profound. No solution from Microchip ? I give up.
#18
1and0
Access is Denied
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Timer0 16 bits 2019/11/20 07:25:45 (permalink)
+1 (1)
Chabb
the main problem is that timer does not count 16bits. it provide an interrupt when timer low runs over 255.

That is not what I'm seeing here. Interrupt occurs at 0xFFFF to 0x0000 here. It takes over 65K cycles to interrupt no matter what is (tried) to load into TMR0H.
 
Ditch the simulator and test on real hardware!!!
post edited by 1and0 - 2019/11/20 08:20:29
#19
Howard Long
Super Member
  • Total Posts : 727
  • Reward points : 0
  • Joined: 2005/04/04 08:50:32
  • Status: offline
Re: Timer0 16 bits 2019/11/20 07:51:47 (permalink)
+1 (1)
1and0
Chabb
so we are waiting for a correction from Microchip.

That might take a while. ;)  Best to test with the real hardware!

 
I agree, it's unusual that I use the simulator, although very occasionally I do if I'm trying to unit test cycle counts or algorithms. 
 
The cost of a handful of test devices is $5, equivalent to a few minutes' consultancy time.
 
#20
Page: 123 > Showing page 1 of 3
Jump to:
© 2019 APG vNext Commercial Version 4.5