need some more help!

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

need some more help!

Post by CharlieM » Sat Mar 27, 2010 1:53 am

Hello everyone,

I have these two lines of code:

Dim Timer1 As TMR1L.AsWord <<<<<< see how this one is correct
Dim Timer0 As TMR0L.asword <<<<<< see this one is all lower case.

Does that mean the the var timer0 won't hold the full 16 bit value?

The pic I am using is a 18F1220. Timer0 is selectable as a 16bit or two 8 bit timer/counter. I have it selected as a 16 bit counter. Thanks.
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

rmteo
Posts: 237
Joined: Fri Feb 29, 2008 7:02 pm
Location: Colorado, USA

Post by rmteo » Sat Mar 27, 2010 2:27 am

See if this alternative method works.

Code: Select all

Dim Timer0 as word
Dim Timer1 as word

Timer0 = (TMR0H<<8)+TMR0L
Timer1 = (TMR1H<<8)+TMR1L

AndyO
Registered User
Registered User
Posts: 48
Joined: Sat Oct 27, 2007 7:08 pm
Location: Beijing, China

Post by AndyO » Sat Mar 27, 2010 6:42 am

I've not had a problem with upper / lower case.

Someone corect me if I've got this wrong but I thought there was a problem with Swordfish and using Timer0 in 16bit mode. When writing to TMR0 you need to write the high byte first and when reading from TMR0 you need to read the low byte first. Writing is fine as Swordfish will write the high byte first but if you do this:

Code: Select all

Dim Timer0 As TMR0L.AsWord
Dim WordValue As Word

WordValue = Timer0
Then the generated assembler will read the high byte first which will give the wrong result.

Is this an issue or have I made it up?

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Post by CharlieM » Sat Mar 27, 2010 12:20 pm

Thanks for the replies.
Someone corect me if I've got this wrong but I thought there was a problem with Swordfish and using Timer0 in 16bit mode
Can someone confirm this? I may have to do some test to see.
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Sat Mar 27, 2010 2:19 pm

I think that's true of any of the timers in 16-bit mode.

When you write them, it must be TMRH then TMRL (which SF does), but when they're read you must read TMRL first,
(which latches the state of TMRH) so that when you read it, you don't have to worry about roll-overs

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Post by CharlieM » Sat Mar 27, 2010 2:26 pm

OK Jerry Thanks.
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

Post Reply