TMR3SETUP TIMER3 28X2/40X2 Firmware B.3

tarzan

Senior Member
TMR3SETUP TIMER3 28X2/40X2

Not functional on firmware B.3

Code:
	'#COM 8 'AXE027 CABLE
	#TERMINAL 9600		
	#PICAXE 28X2
	
	TMR3SETUP %10000001	
DO
	PAUSE 1000
	SERTXD ("TIMER3 = ",#TIMER3,CR,LF)
LOOP
 

Technical

Technical Support
Staff member
This is a documentation error, we forgot to include in the new 28X2 updated manual that Microchip have played around with the bit mapping on TMR3SETUP. The documentation for this command should now include this:

For the 28X2 (PIC18F25K22) part:

config is defined as
Bit 7 Must be clear (0)
Bit 6 Must be clear (0)
Bit 5, 4
1 : 8 Prescale (11)
1 : 4 Prescale (10)
1 : 2 Prescale (01)
1 : 1 Prescale (00)
Bit 3 Must be clear (0)
Bit 2 Must be clear (0)
Bit 1 Must be set (1)
Bit 0 Timer 3 Enable (1= on, 0 = off)
 

Technical

Technical Support
Staff member
There are only two known upgrade issues from 28X2-5V to 28X2, new improved style adcsetup and this tmr3setup (tmr3setup is not used by that many people). adcsetup is already mentioned in the www.rev-ed.co.uk/docs/picaxex2.pdf datasheet, we will amend it to include tmr3setup aswell.
 
Last edited:

BeanieBots

Moderator
tmr3setup is not used by that many people.
I'm surprised as it's one of the few timers that doesn't have issues with other commands (with the exception of long serial transmissions).
I use it for all critical loops (esp PID) that require consistent execution times.
 

rmtucker

Member
I can not simulate this on the 28x2.
I now get an error saying Bit1 has to be 0
So has the simulation been altered to take care of this?
If i program the chip it works fine?
 
Last edited:

BeanieBots

Moderator
Is it possible (via peek or something else) for the PICAXE to know which silicon or firmware revision it's running on?
The intention being to have one program that can run on either chip variant.
 

tarzan

Senior Member
Is it possible (via peek or something else) for the PICAXE to know which silicon or firmware revision it's running on?
The intention being to have one program that can run on either chip variant.
Readfirmware
Readrevision
Readsilicon

Code:
	SYMBOL LS_NIBBLE 			= B2
	SYMBOL MS_NIBBLE 			= B3

	'#COM 8 'AXE027 CABLE
	#TERMINAL 9600
	'#PICAXE 20X2		
	#PICAXE 28X2
	
	#SLOT 0
	#NO_DATA
	#NO_TABLE
	
	#REVISION 255

	PAUSE 100

	READFIRMWARE B0
	
	GOSUB DEC_to_ASCII_HEX

	SERTXD ("FIRMWARE: ",MS_NIBBLE,".",LS_NIBBLE,CR,LF)

	READSILICON B0

	SERTXD ("PICAXE ")
	
	B0 = B0 & %11100000
	
	IF B0 = %00100000 THEN
	
	SERTXD ("20X2 PIC18F14K22")

	ELSEIF B0 = %01000000 THEN
	
	SERTXD ("28X2-5V PIC18F2520")

	ELSEIF B0 = %01100000 THEN
	
	SERTXD ("40X2-5V PIC18F4520")

	ELSEIF B0 = %11000000 THEN
	
	SERTXD ("28X2-3V PIC18F25K20")

	ELSEIF B0 = %11100000 THEN
	
	SERTXD ("40X2-3V PIC18F45K20")
	
	ELSEIF B0 = %10000000 THEN
	
	SERTXD ("28X2 PIC18F25K22")

	ELSEIF B0 = %10100000 THEN
	
	SERTXD ("40X2 PIC18F45K22")	
	
	ENDIF
	
	READSILICON B0
	
	SERTXD (CR,LF,"Microchip Silicon Die Version = %",#BIT4,#BIT3,#BIT2,#BIT1,#BIT0,CR,LF)

	READREVISION B0
	
	GOSUB DEC_to_ASCII_HEX

	SERTXD ("REVISION: $",MS_NIBBLE,LS_NIBBLE,CR,LF)
	
	END

DEC_to_ASCII_HEX:

	LS_NIBBLE = B0 & %00001111
	MS_NIBBLE = B0 & %11110000 / 16

	LOOKUP LS_NIBBLE,("0123456789ABCDEF"),LS_NIBBLE
	LOOKUP MS_NIBBLE,("0123456789ABCDEF"),MS_NIBBLE
	
RETURN
 
Last edited:

BeanieBots

Moderator
Thanks tarzan.
Though thinking a little more about it, I guess the issue is more with the PE and how it can 'predict' what the target is!
 

Technical

Technical Support
Staff member
All you probably need is something like this, which works for all 3 28X2 variants:

Code:
readsilicon b1
b1 = b1 & %11100000
 
select case b1
 
case %01000000 ; 28X2-5V
 tmr3setup %10000001
 
case %11000000 ; 28X2-3V
 tmr3setup %10000001
 
case %10000000 ; 28X2
 tmr3setup %00000011
 
end select
 

BeanieBots

Moderator
Thanks for providing the details.
I was thinking it should be something simple like that but on PE 3.5.0 in simulation it throws an error
"case %01000000 ; 28X2-5V
tmr3setup %10000001
" Bit 7 must be 1

Haven't tried to download to a real chip yet.
Will PE 3.5.2 get upset with code that tries to set the wrong bit (even if that code will never run)?
 

Technical

Technical Support
Staff member
We have already fixed this simulation issue, it will work fine in the next release with either bit setting.
 
Top