Question about cristal 16MHz, with em64 make no difference

alexlopez2612

New Member
Hi,

I have a 40X2 3V and I was hopping that this new (and expensive) chip, could give more speed to my circuit.

I had de 40X2 with a 8MHz cristal and with setfreq em32 and now, when I have the 40X2 3V, 16MHz cristal, and a setfreq em64, I can see any difference...

I don't know if this too much to ask here, so, please, let me know where I can found a solution, because I'm looking and testing for a lot of places.
Do I need to do something else?


This is my code (if it helps to see anything wrong):


Code:
let dirsB = %00000000 'seteamos portB como entradas
let dirsD = %11111111 'seteamos portD como salidas
symbol DIR_FISICA = b6
'variables para trama de transmisión/recepción
symbol DIR_TRAMA = b10
symbol FUNCION = b11
symbol DATA_BYTE_0 = b12
symbol DATA_BYTE_1 = b13
symbol DATA_WORD_0 = w7
symbol DATA_WORD_1 = w8
symbol DATA_WORD_2 = w9
symbol DATA_WORD_3 = w10

symbol DATA_WORD_4 = w11
symbol DATA_WORD_5 = w12
symbol DATA_WORD_6 = w13
symbol DATA_WORD_7 = w14


symbol OK_BYTE = b30
symbol CRC_BYTE = b31
'Var generales
  
setfreq em64 'comando que cuadriplica la freq del cristal de 8MHz a 32MHz
low c.2 'ponemos el 485 en modo escucha

gosub set_485_address
sertxd("la direccion es ",#DIR_FISICA,13,10)

hsersetup B57600_64,%00

main:

	low c.2'si se ha cortado la comunicación, esperamos en modo escucha
	'serin c.0,T38400_32,DIR_TRAMA,FUNCION,DATA_BYTE_0,CRC_BYTE
	hserin [1000,main],0,4
	ptr = 0 ; reset sp pointer
	
'	get 0,DIR_TRAMA
	get 1,FUNCION
	get 2,DATA_BYTE_0
	get 3,CRC_BYTE
	
	

	if @ptr = DIR_FISICA then
		high c.2 'habilitamos el 485 para transmitir
		select case FUNCION 'evaluamos la funcion del 
			case 2 'Leer y enviar a PC entradas y salidas
				gosub memory_read 'leo las entradas
				let OK_BYTE = 255 'OK provisional
				let CRC_BYTE = 0	'CRC provisional
				gosub envio 'envío trama respuesta
				
			case 3
				let pinsD = DATA_BYTE_0 'seteo las salidas
				gosub memory_read 'leo las entradas
				let OK_BYTE = 255 'OK provisional
				let CRC_BYTE = 0	'CRC provisional
				gosub envio 'envio trama respuesta

			endselect

	endif
goto main

envio:
	pause 10
	hserout 0,(DIR_TRAMA,FUNCION,DATA_BYTE_0,DATA_BYTE_1,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,OK_BYTE,CRC_BYTE,10)
	low c.2 'volvemos el 485 para escuchar
	
return

memory_read: 'subrutina que lee todas las DI, DO y AI
	let DATA_BYTE_0 = pinsB 'leemos DI de puerto B y lo metemos al byte de la trama
	let DATA_BYTE_1 = outpinsD 'leemos status de las DO y lo metemos al byte de la trama
	readadc10 a.0,DATA_WORD_0 'metemos la AI0 en el word de la trama.
	readadc10 a.1,DATA_WORD_1 'metemos la AI1en el word de la trama.
	readadc10 a.2,DATA_WORD_2 'metemos la AI2 en el word de la trama.
	readadc10 a.3,DATA_WORD_3 'metemos la AI3 en el word de la trama.
	
	'readadc10 a.4,DATA_WORD_4 'metemos la AI4 en el word de la trama. REASIGNAR A OTRO PIN; ESTE NO ES ADC
	readadc10 a.5,DATA_WORD_5 'metemos la AI5 en el word de la trama.
	readadc10 a.6,DATA_WORD_6 'metemos la AI6 en el word de la trama.
	readadc10 a.7,DATA_WORD_7 'metemos la AI7 en el word de la trama.
return


set_485_address:

	let DIR_FISICA = 0

	if pinC.0 = 1 then
		setbit DIR_FISICA,0
	endif

	if pinC.1 = 1 then
		setbit DIR_FISICA,1
	endif
	
	if pinC.5 = 1 then
		setbit DIR_FISICA,2
	endif
	
	if pinC.4 = 1 then
		setbit DIR_FISICA,3
	endif
return
Thank you for you help
 

nick12ab

Senior Member
Much of the code involves serial communications. Some of them have had their baud rate extensions modified appropriately to _64 but others aren't still _32 so double-check that that's right.

When changing from a 32MHz crystal to a 64MHz crystal, the speed selected in your terminal to use the sertxd/serrxd commands should have doubled. If that was not the case then check that one crystal is 8MHz and the other is 16MHz and that they are not both the same and also check that they are connected properly to the PICAXE as otherwise it goes back to its internal 8MHz resonator.

The following code will diagnose your crystal - connect pin B.0 to the computer and set your terminal to 9600 baud, then turn on the PICAXE with this code on it and you'll see some garbage characters and also a message saying what speed crystal is connected.
Code:
#picaxe 40x2
pause 1000
setfreq em64
pause 1000
serout B.0,N9600_8,(" Crystal 8MHz ")
pause 100
serout B.0,N9600_16,(" Crystal 16MHz ")
pause 100
serout B.0,N9600_32,(" Crystal 32MHz ")
pause 100
serout B.0,N9600_64,(" Crystal 64MHz ")
do : loop
 

westaust55

Moderator
Welcome to the PICAXE forum.

Are you using a 2-pin crystal or a 3-pin resonator.
If a crystal, then do you have the necessary caracitors from each side of the crystal to ground / 0 Volts?

If the external circuit is electrically not working then the PIC reverts to the internal resonator circuit.
 
Last edited:

srnet

Senior Member
If the external circuit is electrically not working then the PIC reverts to the internal resonator circuit.
That feature of a PIC has caught me out on a number of ocaisions, there is the clock failsafe option. You can turn this feature off on a native PIC, but not a PICAXE .....

There is a flag set in one of the PIC PIR registers (OSCFIF of PIR2) if this failover occurs, so you should be able to tell if the external oscillator is being used as intended.
 
Top