Glad to hear you got this working. I'll throw out a quick start I've been trying lately when interfacing to new chips for a basic frame work that gets me down the road quickly. I've been trying out OpenAi's Free chat bot.
This is what I entered in for your pic and the AS5600.
ChatBot Query: Write a PicBasic Pro program to read/write data from AS5600L-ASOM with the PIC18F4550 .
Output: To interface the AS5600L-ASOM magnetic rotary position sensor with the PIC18F4550 microcontroller using PICBASIC PRO, you need to set up I2C communication. The AS5600L-ASOM uses the I2C protocol to communicate with the microcontroller.
Here’s a sample program to read the angle data from the AS5600L-ASOM and write it to an output.
PICBASIC PRO Code
ExplanationCode:' Define I2C pins DEFINE I2C_SDA PORTC.4 DEFINE I2C_SCL PORTC.3 ' AS5600L-ASOM I2C address (default 0x36 shifted for 7-bit addressing) AS5600_ADDR CON $36 ' AS5600L-ASOM registers AS5600_ANGLE_H CON $0E AS5600_ANGLE_L CON $0F ' Variables angleH VAR BYTE angleL VAR BYTE angle VAR WORD ' Initialize I2C I2CINIT ' Main Program main: ' Read the high byte of the angle register I2CREAD AS5600_ADDR, AS5600_ANGLE_H, [angleH] PAUSE 10 ' Read the low byte of the angle register I2CREAD AS5600_ADDR, AS5600_ANGLE_L, [angleL] PAUSE 10 ' Combine high and low bytes to get the full angle value angle = angleH << 8 angle = angle | angleL ' Convert angle to degrees (angle is 0-4095 representing 0-360 degrees) angle = (angle * 360) / 4096 ' Add your code here to use the angle value (e.g., display on an LCD, send via serial, etc.) ' For example, send angle via UART SEROUT2 PORTC.6, 84, ["Angle: ", DEC angle, 13, 10] PAUSE 1000 ' Delay 1 second before next read GOTO main END
Define I2C Pins: Set the SDA and SCL pins for I2C communication.
AS5600L-ASOM I2C Address: The I2C address for the AS5600L-ASOM is 0x36. Note that some libraries expect the 7-bit address shifted for 8-bit communication.
AS5600L-ASOM Registers: Define the registers for reading the angle.
Variables: Declare variables to store the high and low bytes of the angle, and the combined angle value.
Initialize I2C: Use I2CINIT to initialize the I2C communication.
Main Program Loop:
Read the high byte and low byte of the angle register.
Combine the high and low bytes to get the full 12-bit angle value.
Convert the angle value to degrees.
Use the angle value as needed (e.g., send via UART for display).
Notes
Ensure pull-up resistors (typically 4.7k ohms) are connected to the SDA and SCL lines.
Adjust the SEROUT2 command for your specific UART configuration if needed.
The angle value from the AS5600L-ASOM is 12 bits, representing a range of 0-4095, which maps to 0-360 degrees.
This code provides a basic framework for interfacing the AS5600L-ASOM with a PIC18F4550 microcontroller using PICBASIC PRO. You can expand and modify it based on your specific requirements.
It's not perfect but can get some project started quickly as a reference.




Bookmarks