About this Tutorial: ams OSRAM created a single-Zone Time of Flight Sensor and developed an Arduino Library with it. I created a port to Renesas eval kits. This port was created on E2 Studio using an example project provided by Renesas. This port uses USB instead of UART, so that other software/hardware is not needed.
About EK-RA4M2: The board used in the port was an EK-RA4M2. All Renesas eval kits that have USB(in addition to the debug USB), Arduino form factor, and I2C should be able to use the code.
For more information: EK-RA4M2 Product Page
About TMF8806: TMF8806 comes in an Arduino-style form factor that plugs into a Renesas Eval kit. The TMF8806 is a time-of-flight (TOF) sensor in a single modular package with associated VCSEL. The TOF device is based on SPAD, TDC, and histogram technology. The device achieves a 500cm detection range, which may be extended to 1000cm with a small firmware download.
The TMF8806_EVM_EB_SHIELD is designed to operate standalone (with the integrated FTDI controller chip) or attached to an Arduino Uno R3*. In our case, a Rensas eval board.
For more information: TMF8806 Prudoct Page
Installing the board: Place the TMF8806 Shield in the Arduino-style headers. The board should look like this:
Once in place, turn the FTDI switch to the OFF position. If this is left on, it can mess with the communication to the board.
E2 Studio:
1) Import a project. As this port uses an existing project from Renesas, the first step will be to import the USBPCDC project. You can find the example project here. This is what it looks like in E2 Studio:
2) Configure the pins:
A) Find the pins that relate to the Arduino Connectors. Here's an example:
For my board, I2C_SDA and I2C_SCL are Pins P112/P113, Enable Pin is P103, and finally, my Interrupt pin is P304.
B) In the pin tab, find and name the pins to ENABLE_PIN and INTERRUPT_PIN. The SDA and SCL pins should already be named something along the line ARDUINO_SCL_MICROBUS_SCL. No need to change the names for those.
C) Configure the enable pin as in the picture. Output mode(Initial High), No pull-up, High Drive capacity.
D) Configure the Interrupt pin like in the picture. IRQ mode, input pull-up, IRQ#(the number will be dependent on the eval board, but shouldn't matter).
E) Configure the I2C_SCL and I2C_SDA like in the picture. Both will be configured the same. Peripheral mode, input pull-up, n-ch open drain
3) Configure the stacks
A) In the Stacks tab, click New Stack and add the r_sci_i2c stack. Note this stack is for simple I2C. If your pins are true I2C, then some functions will need to be changed for this port to work.
Click on the Properties tab, and configure the stack like in the picture. Note that the channel will change the pins at the bottom. Change the channel to match the pins. Slave address is set here, at 0x41.
Once the stack is configured, go back to the Pins tab. Navigate to the peripherals and connectivity. Open up SCI, and find the channel that corresponds to the pins. Make sure that the pins and stacks are all the same. A picture is included to show.
B) Go back to the Stacks tab, add another stack. This time, external irq. Click on the stack and then Properties. Change the channel to match the pin to the Interrupt pin. The name should be g_external_irq0. Go back to the pins tab and navigate to input:ICU. Find the IRQ and make sure it matches the stack and the interrupt pin.
C) Go back to the stacks and add a new stack. This stack will be r_gpt. Change the mode to periodic, period to 0xFFFFFFFF, unit to Millisecond.
D) After this, you should have 12 different stacks, including the ones that were there from the example project.
4) Code
A) In the project explorer, right-click the src folder, click on system explorer, and this will bring up the source folder. Copy files into the folder and replace the old ones.
B) Clean and build the project. You should get no errors at this time. If you do, check board_cfg.h the #define KIT_NAME_MACRO should be your board. e.g "EK-RA4M2"
C) Debug and click resume
D) Open Tera term. The normal settings will be fine.
E) Success
D) To take a measurement, press '1', 'E', 'M', 'S', 'E', 'M'
E)Some quarks that I know of: When plugged into a USB port, make sure that it is USB 2.0. Other USB ports may be too fast and mess up the timing.
Results printing: #Obj,<i2c-addr>,<result_number>,<confidence>,<distance_mm>,<clk_corrected_distance_mm>,<systick>,<temperature>,<ref_cnt>,<target_cnt>,<xtalk>







Comments