Using Mbed for 2-Channel SOC-Meter

My Nissan Leaf Forum

Help Support My Nissan Leaf Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

garygid

Well-known member
Joined
Apr 21, 2010
Messages
12,469
Location
Laguna Hills, Orange Co, CA
I am investigating using the Mbed board (100 MHz, 32-bit) as
a controller for the SOC-Meter because it apparently has two
CAN controllers built in, and includes a USB port that can
look like a virtual Comm Port (or a FlashDrive) to the PC.

Adding the LED display or a serial-bit interface LCD should be
easy, but one does need to add two CAN transceiver chips.

The Mbed programming environment is web-based, with the
source code is C-like syntax. There are extensive libraries
available, and loading the program is just a file copy to the
Mbed's USB "FlashDrive".

Those interested in the Mbed, with experience or not, might
wish to participate. The first step is to read some of the
"HandBook at http://www.mbed.org/" onclick="window.open(this.href);return false; about getting started.

Apparently this Mbed is used extensively, especially by
student groups. One Mbed can even be "shared".

The second step is to buy an Mbed board (about $60) to get access
to the on-line programming environment, and try to compile and run
a few of the many samples. The first just flashes one of the LEDs.
 
The 2-Port SOC-Meter Project:

To Do:
1. Receiving LEAF CAN messages from one CAN port.
2. Sending the Messages to CAN-Do on the PC. - done.
3. Receiving LEAF CAN messages from the 2nd CAN port
4. Modify Log-Message format to include the CAN-Source.
5. Modify CAN-Do to accept the Multi-CAN log format.
6. Attach a 2x16 LCD and write to it. - done.
 
CAN-Message Generator
(for testing CAN-Do)

1. Blink the 4 LEDs, with various delays - done
2. Exchange text with PC via a 9600 baud virtual Com Port - done.
3. Manufacture a binary CAN-Log Message, send once per second - done.
4. send message to PC at 115,200 baud - done.
5. Send message at 200 per second (5 ms intervals) - done.
6. Send a variety of messages
7. Send at 500 and 1000 per second - done.
8. Invent Multi-CAN Log Message
9. Send 2-CAN Log messages
10. Send 2-CAN messages at 1000 per second
11. try using 230,400 baud
12. Use jumpers on Mbed pins to select Test-Mode.
 
Log-to-SD-Card version of SOC-Meter

1. Write a file to the 2 MB Mbed Flash - done.
2. Possibly log just Changes in message values
3. Try adding a Log file to an SD Card
4. Get seconds and milli-seconds from a timer. - done.
5. Get Date and Time to log once each minute.
 
1. The Mbed's Real Time Clock needs a backup "coin" battery, and holder.

2. I need a solder-in right-angle USB connector to try writing to a Flash Drive.

3. I need an SD-Card "socket" to try writing to an SD Card.

4. As suggested by Chris, I will try to use an RJ45 (Ethernet) connector
to attach the OBD cable, so I need the crimp plug and right-angle
PCB-pin socket.

5. I will also look for a right-angle PCB-pin DB9 male connector
(like the AVR-CAN board uses for "CAN" input).

6. I have (from Mouser) the 7-pin CAN transceiver chip like the AVR-CAN board uses.

7. I will want to get the 5v Regulator chip that Chris used on his ver-1 SOC-LCD-Meter board.

Then, return and ...
try to write to the USB Flash Drive.
 
Writing to USB Flash Drive:

The Mbed wrote 200,000 records of about 30 bytes each to a 4 GB Flash drive, in about 85 seconds.

Every 10th record or so, it takes maybe 3 ms instead of 0.14 ms.

Then about once each 15 seconds, it takes about 600 ms!

But, a good success ...
that might be useful for a 2nd generation SOC-Meter's Logging, directly to a USB Flash Drive (no PC required to collect the data). :) :D
 
The next test is to hook up one of the Mbed's two CAN ports,
receive data, and Log to the Flash Drive.

Then add a time stamp on each record, and a Date/Time record each minute.

I might need to deal with the occasional 0.6 second "slow-write".
 
I hooked up each of Mbed's two CAN ports to transceiver chips,
connected the two with a (very) short CAN bus, wrote CAN
Messages from one, and received the Messages on the other.

Looks like I will have to connect to the LEAF soon, and
read and Log real CAN messages to a USB Flash Drive.

I have the time-stamping worked out, using the Mbed's Real-Time
Clock (RTC) and an interrupt to sync the Mbed's millisecond timer.

First, log one CAN bus (EV), then log both buses together (EV and CAR).

At 13 bytes per CAN Message, buffering about 2000 messages
would use 26k of the Mbed's memory for a circular FIFO buffer.
 
With the Mbed progremmed to:
1. use a 1000-message circular buffer,
2. have CAN-1 sending to CAN-2, and CAN-2 sending to CAN-1,
3. write to a 4GB USB Flash Drive,

The firmware can handle:
1. bursts of at least 4 messages per ms
2. an average of 1.3 ms per message

I am writing a multi-CAN Log file:
1. with 13 bytes per message
2. of type ".alc" (compatible with CAN-Do)
3. with Second and Milli-second Time Stamps on each message
4. with a Date-and-Time pseudo-message at the start of each minute
5.

In one test, I wrote 2,000,000 messages to a file.

I am adding:
1. Continuous-Record mode,
2. Auto-Record, whenever the car is ON,
3. Manual-Record mode

I need to:
1. detect existing files, and auto-number new log files.
2. fine tune interrupt handling
3. consider packaging into a box
4. consider using an "oled" display
5. add SOC-Meter functions
6. create, read, and write an "ini" file
7. ... and more
 
I got a tiny USB Reader (from SparkFun) for Micro SD/SDHC cards
yesterday, and hope to try writing a Log to it (in place of the
USB Flash Drive) today.

Hopefully it will "just work"! :D
Edit: It worked! :D :D
 
An 8GB Micro SD/SDHC card in the SparkFun (COM-09433
for $6.95) tiny (very small) USB Reader (for Micro SD/SDHC cards)
appeared to work perfectly as a substitute for a USB Flash Drive.

The Mbed wrote 60,000 13-byte time-stamped CAN-Log messages
in under two minutes, and I read the file with CAN-Do on my Vista PC.

No special drivers required.

With this success writing a (Micro) SDHC card, I am no longer
going to try to write directly to SD cards.

The USB Reader/Writer adapter seems to work well. However,
when I get more time, I will try using a full-size SDHC card
in a full-size USB Reader.
 
Here is the configuration I am working toward for a new GID-Meter:
(No, not Promises, but current Goals.)

1. Oled, LED, or LCD display, but not decided yet, possibly some options. From 1x4 to 2x16 characters.

2. Power Switch: Auto-On, Off, Always On.

3. GID-Meter Modes, and Logging Modes, maybe Combo Modes.

4. An easy-to-edit User-Preferences file.

5. Easy Firmware update from PC, via simple USB cable (A to Mini)

6. Logging of EV-CAN, CAR-CAN, or both CAN buses.

7. Real Time Clock, with (CR2032 ?) coin battery backup.

8. Logging Time Stamps to milli-second, synchronized with the RTC.

9. Logging to a USB Flash Drive, or equivalent USB "SD/SDHC Card Reader/Writer".

10. Real-Time logging to PC via simplebUSB cable.

11. Auto-Logging Mode, logging to USB Flash whenever CAN activity is detected.

12. Probably packaged in the same conveniently-sized box as the SOC-Meter.

13. User Input: At least two push-buttons, or equivalent.

14. 6-foot OBD cable, right angle connector.

15. Other ... ?
 
That's great progress Gary. Nice work.
Do you have all the parts etc posted somewhere? Do you plan to post on your SOC meter site?

As for suggestions; you've covered more than my current wish list.
One thing, since the mbed processor is quite a bit more powerful than the AVR or Arduino, I was entertaining the idea of making the mbed provide an output format like a USB music stick. So, CAN-bus input through mbed to USB music files output through USB cable into the Aux connector.
Then I could, in real-time, update "song titles" etc with the CAN-bus info I wanted, 'Gids', Volts, etc.
Perhaps you or someone else has already looked into this and found it un-workable?
It would be nice to get access to the big center console display.
 
The Mbed, through its mini-USB connector,
looks like a 2MB Flash Drive to the PC, so:

1. Connect the supplied USB cable to the PC
2. Copy two short music files onto the "MBED" drive.
3. Plug it into the LEAF's USB port and see if the songs are recognized.
4. Report Back, please!

Edit:
I tried a .mp3 and a .wav file, and it recognized the drive and
the two files. It played the short .mp3 file fine, but could not
play the .wav file.
 
Back
Top