'LECTURA DE UN DETECTOR MAGNETICO DE GIRO AS5600
'4096 PASOS POR ROTACION. LECTURA POR I2C. EXISTEN DOS REGISTROS PARA ESTO
'HACE UNA LECTURA DEL SENSOR SIN FILTRAR EN LA POSICION 0X0C
'EN DOS PARTES PRIMERO LA MAS SIGNIFICATIVA Y A CONTINUACION LA MENOS SIGNIFICATIVA
'ESTE ORDEN ES COMO CONSECUENCIA DE LA ARQUITECTURA DE REGISTROS EN EL CHIP
chip mega328p,16
option Explicit
#DEFINE USART_BAUD_RATE 9600
#DEFINE USART_TX_BLOCKING
#DEFINE USART_DELAY 0
#define hI2C_BAUD_RATE 100
#define hI2C_DATA PORTC.4
#define hI2C_CLOCK PORTC.5
#define hI2C_DISABLE_INTERRUPTS ON
#define hI2C_MODE Master
Dir hI2C_DATA in
Dir hI2C_CLOCK in
dim valorL as byte
dim valorH as byte
dim valorW as word
' dim contA as byte
HSerPrint "inicio"
HSerPrintCRLF
wait 100 ms
do forever
'el dispositivo tiene la direccion 0x36 pero
'para que sea reconocido hay que desplazarlo
'1 bit a la izquierda
' hI2CStop 'usando hi2CStop se para tras el primer ciclo
'******
valorw =valorL
valorw_H =valorH
HSerPrint valorW
HSerPrintCRLF
wait300ms
loop
End
esta version funciona siempre, aunque apague el arduino y lo vueva a encender , pero he tenido que cambiar la instruccion hi2cstop por hi2CStopped ¿Suerte ?
Last edit: Manuel 2022-03-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Estas experiencias son interesantes si se actualizan en el manual . Algunos ejemplos son demasiado escuetos. Existe un metodo escrito para poder crear librerias en GCB ?. Terminé el programa para escribir en un display max7219 de 8 digitos 7 segmentos.
The issue is resolved. Manuel sent me a device and after a quick look at the Datasheet the problem was resolved.
The I2C protocol requires a NACK after the last byte of data is requested. Failure to do this causes the slave AMS 5600 to lock up. I also determined that it is required to power cycle the AMS 5600 to ensure any previous lock up is cleared done.
The library is in the release packs and in GCStudio.
Help
' Method: AMS_5600_setOutPut
' mode = 0, output PWM, mode = 1 output analog (full range from 0% to 100% between GND and VDD
Sub AMS_5600_setOutPut( AMS_5600_setOutPut_mode )
' *******
' Method: AMS_5600
' In: none
' Out: i2c address of AMS 5600
' Description: returns i2c address of AMS 5600
' *******
Function AMS_5600_getAddress
' ********
' Method: setMaxAngle
' In: new maximum angle to set OR none
' Out: value of max angle register
' Description: sets a value in maximum angle register.
' If no value is provided, method will read position of
' magnet. Setting this register zeros out max position
' register.
' **********
Function AMS_5600_setMaxAngle( AMS_5600_newMaxAngle as Word ) as Word
' ********
' Method: getMaxAngle
' In: none
' Out: value of max angle register
' Description: gets value of maximum angle register.
' **********
Function AMS_5600_getMaxAngle() as Word
' ********
' Method: setStartPosition
' In: new start angle position
' Out: value of start position register
' Description: sets a value in start position register.
' If no value is provided, method will read position of
' magnet.
' *******
Function AMS_5600_setStartPosition( AMS_5600_startAngle as Word ) as Word
' *******
' Method: getStartPosition
' In: none
' Out: value of start position register
' Description: gets value of start position register.
' *******
Function AMS_5600_getStartPosition() AS Word
' *******
' Method: setEndtPosition
' In: new end angle position
' Out: value of end position register
' Description: sets a value in end position register.
' If no value is provided, method will read position of
' magnet.
' *******
Function AMS_5600_setEndPosition( AMS_5600_endAngle As Integer ) as Word
' *******
' Method: getEndPosition
' In: none
' Out: value of end position register
' Description: gets value of end position register.
' *******
Function AMS_5600_getEndPosition() As Word
' *******
' Method: getRawAngle
' In: none
' Out: value of raw angle register
' Description: gets raw value of magnet position.
' start, end, and max angle settings do not apply
' *******
Function AMS_5600_getRawAngle() As Word
' *******
' Method: getScaledAngle
' In: none
' Out: value of scaled angle register
' Description: gets scaled value of magnet position.
' start, end, or max angle settings are used to
' determine value
' *******
Function AMS_5600_getScaledAngle() As Word
' *******
' Method: detectMagnet
' In: none
' Out: 1 if magnet is detected, 0 if not
' Description: reads status register and examines the
' MH bit
' *******
Function AMS_5600_detectMagnet() as Byte
' *******
' Method: getMagnetStrength
' In: none
' Out: 0 if no magnet is detected
' 1 if magnet is to weak
' 2 if magnet is just right
' 3 if magnet is to strong
' Description: reads status register andexamins the MH,ML,MD bits
' *******
Function AMS_5600_getMagnetStrength()
' *******
' Method: get Agc
' In: none
' Out: value of AGC register
' Description: gets value of AGC register.
' *******
Function AMS_5600_getAgc()
' *******
' Method: getMagnitude
' In: none
' Out: value of magnitude register
' Description: gets value of magnitude register.
' *******
Function AMS_5600_getMagnitude() as Word
' *******
' Method: getConf
' In: none
' Out: value of CONF register
' Description: gets value of CONF register.
' *******
Function AMS_5600_getConf() As Word
' *******
' Method: setConf
' In: value of CONF register
' Out: none
' Description: sets value of CONF register.
' *******
Sub AMS_5600_setConf( in AMS_5600_conf as Word )
' *******
' Method: getBurnCount
' In: none
' Out: value of zmco register
' Description: determines how many times chip has been
' permanently written to.
' *******
Function AMS_5600_getBurnCount()
' *******
' Method: burnAngle
' In: none
' Out: 1 success
' -1 no magnet
' -2 burn limit exceeded
' -3 start and end positions not set (useless burn)
' Description: burns start and end positions to chip.
' THIS CAN ONLY BE DONE 3 TIMES
' *******
Function AMS_5600_burnAngle()
' *******
' Method: burnMaxAngleAndConfig
' In: none
' Out: 1 success
' -1 burn limit exceeded
' -2 max angle is to small, must be at or above 18 degrees
' Description: burns max angle and config data to chip.
' THIS CAN ONLY BE DONE 1 TIME
' **********
Function AMS_5600_burnMaxAngleAndConfig()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
La libreria funciona genial, hubo problemas con la fluctuacion de datos pero eran como consecuencia de una mala conexion entre el chasis y GND. del arduino.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Looking at the datasheet - this should work.
I2CStart
I2CSend(0x6e +1)
I2CReceive(valorH) 'lee el byte mas significativo
I2CReceive(valorL) 'a continuacion el byte bajo
I2CStop
Como puedo enviar un dispositivo a usted ?
Send me a personal message for my details.
Evan
'LECTURA DE UN DETECTOR MAGNETICO DE GIRO AS5600
'4096 PASOS POR ROTACION. LECTURA POR I2C. EXISTEN DOS REGISTROS PARA ESTO
'HACE UNA LECTURA DEL SENSOR SIN FILTRAR EN LA POSICION 0X0C
'EN DOS PARTES PRIMERO LA MAS SIGNIFICATIVA Y A CONTINUACION LA MENOS SIGNIFICATIVA
'ESTE ORDEN ES COMO CONSECUENCIA DE LA ARQUITECTURA DE REGISTROS EN EL CHIP
chip mega328p,16
option Explicit
' dim contA as byte
HSerPrint "inicio"
HSerPrintCRLF
wait 100 ms
do forever
'el dispositivo tiene la direccion 0x36 pero
'para que sea reconocido hay que desplazarlo
'1 bit a la izquierda
' hI2CStop 'usando hi2CStop se para tras el primer ciclo
'******
valorw =valorL
valorw_H =valorH
HSerPrint valorW
HSerPrintCRLF
loop
End
esta version funciona siempre, aunque apague el arduino y lo vueva a encender , pero he tenido que cambiar la instruccion hi2cstop por hi2CStopped ¿Suerte ?
Last edit: Manuel 2022-03-15
No, not luck. An oversight. :-)
HI2C2 is a command that is valid but that is intended for I2C2
Sorry.
Estas experiencias son interesantes si se actualizan en el manual . Algunos ejemplos son demasiado escuetos. Existe un metodo escrito para poder crear librerias en GCB ?. Terminé el programa para escribir en un display max7219 de 8 digitos 7 segmentos.
A good idea. Create a Help page as a regular text file, in English Then, we can import into the Help ( see https://github.com/GreatCowBASIC/Help/find/main )
You do the context, and, we can import.
The issue is resolved. Manuel sent me a device and after a quick look at the Datasheet the problem was resolved.
The I2C protocol requires a NACK after the last byte of data is requested. Failure to do this causes the slave AMS 5600 to lock up. I also determined that it is required to power cycle the AMS 5600 to ensure any previous lock up is cleared done.
I have posted demonstration code to https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/ams_5600_solutions
The demo shows lots of key information about the device then is shows the angular value and direction of the rotation, as follows:
The library is in the release packs and in GCStudio.
Help
' Method: AMS_5600_setOutPut
' mode = 0, output PWM, mode = 1 output analog (full range from 0% to 100% between GND and VDD
Sub AMS_5600_setOutPut( AMS_5600_setOutPut_mode )
' *******
' Method: AMS_5600
' In: none
' Out: i2c address of AMS 5600
' Description: returns i2c address of AMS 5600
' *******
Function AMS_5600_getAddress
' ********
' Method: setMaxAngle
' In: new maximum angle to set OR none
' Out: value of max angle register
' Description: sets a value in maximum angle register.
' If no value is provided, method will read position of
' magnet. Setting this register zeros out max position
' register.
' **********
Function AMS_5600_setMaxAngle( AMS_5600_newMaxAngle as Word ) as Word
' ********
' Method: getMaxAngle
' In: none
' Out: value of max angle register
' Description: gets value of maximum angle register.
' **********
Function AMS_5600_getMaxAngle() as Word
' ********
' Method: setStartPosition
' In: new start angle position
' Out: value of start position register
' Description: sets a value in start position register.
' If no value is provided, method will read position of
' magnet.
' *******
Function AMS_5600_setStartPosition( AMS_5600_startAngle as Word ) as Word
' *******
' Method: getStartPosition
' In: none
' Out: value of start position register
' Description: gets value of start position register.
' *******
Function AMS_5600_getStartPosition() AS Word
' *******
' Method: setEndtPosition
' In: new end angle position
' Out: value of end position register
' Description: sets a value in end position register.
' If no value is provided, method will read position of
' magnet.
' *******
Function AMS_5600_setEndPosition( AMS_5600_endAngle As Integer ) as Word
' *******
' Method: getEndPosition
' In: none
' Out: value of end position register
' Description: gets value of end position register.
' *******
Function AMS_5600_getEndPosition() As Word
' *******
' Method: getRawAngle
' In: none
' Out: value of raw angle register
' Description: gets raw value of magnet position.
' start, end, and max angle settings do not apply
' *******
Function AMS_5600_getRawAngle() As Word
' *******
' Method: getScaledAngle
' In: none
' Out: value of scaled angle register
' Description: gets scaled value of magnet position.
' start, end, or max angle settings are used to
' determine value
' *******
Function AMS_5600_getScaledAngle() As Word
' *******
' Method: detectMagnet
' In: none
' Out: 1 if magnet is detected, 0 if not
' Description: reads status register and examines the
' MH bit
' *******
Function AMS_5600_detectMagnet() as Byte
' *******
' Method: getMagnetStrength
' In: none
' Out: 0 if no magnet is detected
' 1 if magnet is to weak
' 2 if magnet is just right
' 3 if magnet is to strong
' Description: reads status register andexamins the MH,ML,MD bits
' *******
Function AMS_5600_getMagnetStrength()
' *******
' Method: get Agc
' In: none
' Out: value of AGC register
' Description: gets value of AGC register.
' *******
Function AMS_5600_getAgc()
' *******
' Method: getMagnitude
' In: none
' Out: value of magnitude register
' Description: gets value of magnitude register.
' *******
Function AMS_5600_getMagnitude() as Word
' *******
' Method: getConf
' In: none
' Out: value of CONF register
' Description: gets value of CONF register.
' *******
Function AMS_5600_getConf() As Word
' *******
' Method: setConf
' In: value of CONF register
' Out: none
' Description: sets value of CONF register.
' *******
Sub AMS_5600_setConf( in AMS_5600_conf as Word )
' *******
' Method: getBurnCount
' In: none
' Out: value of zmco register
' Description: determines how many times chip has been
' permanently written to.
' *******
Function AMS_5600_getBurnCount()
' *******
' Method: burnAngle
' In: none
' Out: 1 success
' -1 no magnet
' -2 burn limit exceeded
' -3 start and end positions not set (useless burn)
' Description: burns start and end positions to chip.
' THIS CAN ONLY BE DONE 3 TIMES
' *******
Function AMS_5600_burnAngle()
' *******
' Method: burnMaxAngleAndConfig
' In: none
' Out: 1 success
' -1 burn limit exceeded
' -2 max angle is to small, must be at or above 18 degrees
' Description: burns max angle and config data to chip.
' THIS CAN ONLY BE DONE 1 TIME
' **********
Function AMS_5600_burnMaxAngleAndConfig()
La libreria funciona genial, hubo problemas con la fluctuacion de datos pero eran como consecuencia de una mala conexion entre el chasis y GND. del arduino.