WattsLeft™ Monitor (Parallax SX28AC/DP SOC/CAN Project)

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.

Turbo3

Well-known member
Leaf Supporting Member
Joined
Jul 19, 2010
Messages
2,014
Location
San Jose, CA
(Updated name from "TurboScan" to WattsLeft™ Monitor 7/24)
(Updated to include pricing table 2/23/13)
Here is the current price list.
pricelist2232013.jpg

If you are interested in getting a WattsLeft™ please email to [email protected]. I can send you a copy of the Quick Guide to show you what information can be displayed on the 15 selectable screens. Jump to bottom of Page 8 for lastest information.


I recently acquired some surplus Parallax SX28AC chips in DIP packages. After looking at the datasheet it seemed likely I could design an entire SOC meter around this single chip processor. As a result I took the leap and purchased an SX Key (USB) board which allows programming and in-circuit source-level debugging as well as some 50 MHz three pin resonators all from Parallax.

The SX28AC is a very basic single chip system with 2K words (12 bits) of EEPROM program storage, 136 bytes of RAM all inside a 28 pin package with 20 general purpose I/O pins. The instruction set is similar to the PIC16C5x series but with a few more instructions. It can run at up to 75 MHz with one instruction executed each cycle (except for jumps/calls, of course).
sx28blockdiagram.jpg


Here is the pin list.
pinso.jpg


Here is a summary of the instruction set.
instructionset.jpg


The clock rate for this project was selected to be 50 MHz so there would be 100 instructions executed per CAN bus bit (2 usec per bit). This seemed like it would give enough time to handle all the processing plus support a 57,600 baud serial out link to dump CAN frames to a PC.

There are no peripheral functions built-in like a CAN processor or Serial ports. It has only an 8-bit Real Time counter and a single Analog Comparator that can be selected to take over two of the 20 available I/O pins.

The original plan was to use only the SX28AC and a display. To do this I planned on using the Analog Comparator with one side connected to the CANH line and the other to a resistor divider set at a 3 volt level. I was not sure how well this would work since the idle level is 2.5 volts and dominant level is 3.5 volts. So for initial development I decided to remove this variable and just go with a standard MCP2551 CAN Transceiver. Once all the code is debugged and working I may go back and remove the MCP2551 and add the resistor divider.

Below is what the first test board looked like. The 5 volt power is from an old car cell phone charger I had laying around. The black and orange wires are the Serial out lines which go to a 9 pin D connector. Most serial ports accept TTL level so you don’t need a converter to give +/- 12 volt levels. I am using a Serial to USB adapter with my laptop. The connector on the right with three pins is from the CAN cable. The blue dot is the 50 MHz resonator and the single button is for reset. Decoupling caps are under the ICs. The four pins on the left go to the SX-Key for programming/debugging.
cantestboard.jpg


Here is a dump from the serial port of the raw SOC CAN messages including CRC. The code handles all the CAN bit processing (de-stuff, Serial to Byte, and CRC checking). Only messages with good CRC are passed on for processing. The code has two CAN Frame buffers so one can be processed by the main code loop for display/serial dump while the other is being filled in by the interrupt driven receive routine. Flags prevent overrunning the buffers. CAN frames that come in while both buffer are full are skipped.
hexdump.jpg


A 2 line by 16 character LCD display was selected to display the data to the user. The displays only cost $3.99 each including shipping.

Here is the test board connected to the LCD display. There is a 10k pot sticking up to adjust contrast. With two lines of 16 characters there is room to show lots of information. This code version is showing SOC Percent, Gids number (my daughter wanted the 281 added to indicate the max value. The second line starts with the CAN Frame ID for SOC 0x5BC. Next I added trip/charge gauge. In this case it is showing the number of Gids that it took today to charge our Leaf back up to 80% (actually 82.2%, Blink said 3181 watts were used). While driving the number will be negative and show Gids used since the meter was powered on (car turned on).
80percentcharge.jpg


The hardware I have built so far is just for testing to allow debugging of the code. Here is the box that will hold the final version of the hardware which will plug directly into the display pins (no orange jumper wires). The cover has already been cut and display mounted. The 5 volt switching supply is shown laying in the bottom of the box. The box is 4 3/8 by 2 7/16 by 1 1/8.
boxlxg.jpg


Here is the mounted display being tested to see what it will look like. It is still driven by the small test board. Note the attached SX-Key to the right of the test board.
displayincover.jpg


Here is a little overview of the Code.
The interrupt routine runs every 2 usec or every time a CAN falling edge is detected. The falling edges are used to resync the 2 usec timer to keep it locked to the CAN Frames. The interrupt routine first looks to see what caused the interrupt. If it was a clock edge it resyncs the 2 usec timer and exits. If it was the 2 usec timer then it checks to see if it is time to shift a bit out the serial port. At 57,600 baud a bit is shifted out every 26 usec so every 13 timer interrupts (13 x 2 usec) a bit could be shifted out if there are any waiting. After that the code handles the CAN bit. The serial port plus CAN bit code must total less than 100 instructions for this to all work and fortunately it fits.

The main code handles processing the next completed and good (CRC ok) CAN Frame that is waiting in one of the two buffers. It first filters based on Frame IDs which to dump to the serial port (5BC for now) and loads each byte into a send buffer and waits for it to be sent. After all the data is dumped the main code updates the 2x16 display based on what is in the CAN Frame buffer and when done marks the CAN Frame buffer empty and start over again when the next frame buffer is full.

Over the next few days I plan to build the final version of the board that plugs into the display and mount it and the switching power supply in the project box and wire in the CAN Cable. (Or it might be delayed a week or two due to an upcoming trip to Ireland.)

The CAN Cable is the most expensive part followed by the display, SX28AC and MCP2551 Transceiver. I don’t have a cost for 12v to 5v power supply since they came with some old phones.

With the switcher power supply I measure only 60 milliamp at 12 volts used to run the logic and drive the display. The SX28AC also supports a sleep function that may have some use do reduce the power rather than turn it off. If I can get the hardware to sleep rather than power off I could save data from one power/charge cycle to another. That could be of some use to display summary type information.
 
Very nice work, we look forward to more details.
Have a safe trip to Ireland.

Code to handle all the CAN-message decoding, impressive.

Perhaps I can add your logging format to CAN-Do,
or you can adopt my 11-byte binary format.

Thanks for sharing your good work.
Cheers, Gary
 
Is it possible someone with technical/soldering skill could build this on the cheap? What are the parts cost?
 
Gary,
I can easily change my format to match what CAN-DO wants. My current dump format has all the frame data including the CRC bytes so I could check on the PC side to see if I was getting good frames. I also used it to debug my built-in CRC checker code. My format can be displayed with HyperTerminal where yours is an 11 byte binary format which needs a program to sync with and decode. I may even provide an option to change the format on the fly between the two. Yours is more compact and takes less cycles to send and is great for logging lots of data. Mine is good for a quick look to see that everything is still working.

I have added a timer to the display (not the black one the one on the screen) which counts up when the chip is powered on. This way you can easily see how long it takes to get some where or how long you have been driving/charging. (It has been running for 90 minutes now and is still in sync with the black reference clock.)
timerm.jpg


As for costs it is not much (not including the SX-Key which is $60 and only needed by the developer and to program the chip). The OBD2 CAN cable is the same one Gary uses in his kits and is $11.95 plus shipping. The SX28AC/DP is $2.95 p/s, resonator $1.10 p/s both from Parallax. I bought 2 MCP2551 chips (DIP package) on ebay for $5.50 free shipping. The display is $3.99 free shipping on ebay. So that totals about $22.74 plus some shipping for one unit parts with the cable being over half that amount.

Jim
 
Since returning from my trip to Ireland I have spent the last ten days adding a few new features to what I am now calling TurboScan. Here’s a quick summary.

1. Auto Sleep mode in x seconds if no EV CAN activity (power use drops to less than 150 uamps for the logic )
2. Support for up to 8 screens of information
3. Screen selection made with a single externally mounted potentiometer
4. Added KW reading to Home screen
5. Added Power Screen with Horizontal Bar gauge similar to LeafScan
6. Added Motor Amps and RPM screen

The Auto Sleep mode is intended to be used when I switch over to powering the TurboScan from the always hot 12 volt power line in the OBDII cable. This means the TurboScan will always be powered, ready to wake from sleep whenever EV CAN activity is detected.

To support sleep mode I used two output pins and a pull-up resistor. The LCD plus the backlight LED only draws 12 milliamps total. Well within the 45 milliamp limit of the SX28 output drivers. So I only needed to move the LCD power from the 5 volt rail to an output pin and drive the pin active to power up the display. Before I enter Sleep mode all the I/O pins are placed into input mode which drops power to the display.

The MCP2551 CAN also supports a standby mode while still monitoring the CAN lines. Pulling the Rs pin high places the chip into standby so I used another output pin to pull the pin low during normal operation and added a pull-up resistor to pull the line high when all the SX28 I/O pins switch to inputs during sleep.

There are two parts to the total power draw. One is the logic chips which I now have down to less than 150 uamps. The other is the idle power of the switching regulator used to go from +12 down to +5. The one I am currently using draws about 4.39 ma. Still this is not too bad. Total is less than 4.5 ma or 1.3 whrs per day or 40 whrs per month. I have several more switching power supplies coming from China so I still may be able to lower this even more.

One advantage of keeping the processor powered all the time will be the ability to save data over Leaf driving/charging cycles. This is what I am planning to do with the bank of unused registers I have left in the SX28.

I had been looking for an easy way for the user to control the screen selection and after Phil gave me a demo of LeafScan at our last BayLeaf meeting he mentioned he was thinking of a rotary encoder for his design. That stuck in my mind and I noticed a sample program in the SX28 programming books on how to read a Potentiometer with just a resistor, pot and small cap. I added the code to my interrupt routine and had a workable selection method. I found a volume control Pot at Radio Shack that has 37 detents which give a nice bump feel as you turn it. It was however 500K ohms and I needed around 180K so I placed a fixed resistor in parallel. Not linear anymore but not too bad.

The code to control the Pot and convert it to a number from 0-7 has hysteresis to keep the number from bouncing between two values. I am able to get 180 degrees of rotation to cover the 0-7 screen selection range.

The advantage of the Pot is it can be mounted away from the display at a location easier for the driver to reach. For now I have it Velcro’ed to the side of the center console near the seat. The final location might be on the left side in one of the blank switch caps for the Steering Wheel/Side mirror heaters. This way the display can be mounted above the rearview mirror but the control mounted much closer to the drivers hand.

For testing here is what I have now:
potj.jpg


The Home screen has been updated to include the power in the upper right corner where I previously had the max gid number displayed.

In this display 11.1 KW are being draw from the battery.
home1u.jpg


The next screen I added was to display the battery voltage and amps with a horizontal power bar display on the top row. Again this was inspired (copied) from seeing Phil’s LeafScan. Since this is a character not graphics display there is always a space between characters. This turned out to be of use as it makes reading the actual value very easy. Each column of dots represents 1024 watts and there are 5 dots per character. So just count the characters and multiply by 5. One custom edge character is generated on the fly with a variable number of columns of dots.

For those who have not seen Phil’s LeafScan power graphic the bar grows from the left for power out of the battery and from the right for power into the battery. My gauge tops out at 16 x 5 = 80KW.

Here is what it looks like under moderately heavy acceleration (58KW);
power58kw.jpg


Here is what it looks like under regen.
powerregen.jpg


The third screen I added today shows Motor RPM and Amps. The current documentation for Frame 1DA seems to show RPMs in ½ units but I can’t see that. The low order bit is always active so I just shift the RPM value right one and display it. Can any expert comment on this?

Here is the Motor screen.
screen3motor.jpg


The current code supports selection of 8 screens (0-7) although only the first three currently have data. The other 5 screens just show the screen number in the upper left corner for testing the Pot selection code.
futurescreen7.jpg


I am still using my original test hardware with a few resistors and a cap added for the new features. The next step is to build a smaller unit that will fit above the rearview mirror. In that one the logic board will mount directly to the LDC display board. I have the parts just need to solder it up.

Almost forgot, I will also be adding a second CAN Transceiver so I can monitor the CAR-CAN too. So selecting a screen can also software switch to the correct CAN interface for the data to be displayed.
 
Excellent work on your "TurboScan".

Yes, RPM (I think) in EV:1DA D5 and D6 (of D1 to D8)
as 2-byte signed integer,
seems to be RPM * 2
with low bit always "1".
Positive for forward, negative for reverse.

What is the Radio Shack part number for the pot with detents?

I an trying the white characters on black background LCD,
for slightly better contrast.
However, I do not know its current draw.

The AVR-CAN board uses too much power to leave ON, I think.
Also, the much brighter LED display (only four 7-segment digits)
uses a substantial amount of power.

Suggestion:
People forget what the +/- means, so using PwrO (Out)
and PwrI (In), Amps, etc. might be better.
Or, "D" = Driving / "R" = Regen / "C" = Charging.

The CAR-CAN bus seems to produce a flood of messages while
driving, and I am currently trying to determine why some characters
are (infrequently) getting "lost".

The lost characters cause a re-sync to the 11-char messages,
which occasionally re-syncs to data in the middle of a message,
producing "funny" some messages.

The missing characters can introduce "bad" data into the
message, and a message can be lost.

The EV-CAN logging does not seem to lose characters, so far.

I need to do more testing to find out what is causing the loss.

Is AVR-CAN losing the chars?
The 115,200 baud rate occasionally just too slow?
The RS232-to-USB adapter and driver losing them?
Windows virtual CommPort problem?
Visual Basic 6 (VB6) problem?
CAN-Do problem?

Suggestions or insights welcome.
 
A quick update as I am trying to get a full test version packed to go above the rearview mirror built/tested by Saturday for the Hybrds2Hotrods Show.

The Pot from Radio Shack is #271-0002. For me the negative sign always means energy coming from the battery (bad) and plus sign means charging so that is good (for amps or kw).

I was asked whether I plan on selling these. For now I can say I will at least be making the programmed SX28AC chip available. I will think about it more once I have a full prototype working. A custom PC board would eliminate all the hand wiring and make it much more buildable by others (or for me to mass produce).

Yesterday was ‘build a DC-DC converter’ day and here are the results. It went quite well with the idle current down to 1.72 ma. So this is what I am going to use for now.
dcdctest.jpg


I made a stop by Radio Shack the previous day and picked up a small blank PC board that looked like it would fit all the parts and fit behind the LCD with just a single cut. I also was looking for a multi colored LED to use as a power level indicator instead of having to keep looking down at the Power Meter circles.

Have not written the code yet but the plan is
• no light below 10kw
• Green 10kw to below 15kw
• Blue 15kw to below 20kw
• Red 20kw and above

You should be able to see the color in your peripheral vision the way the LED is positioned to the left above the rearview mirror. Will have to see what it looks like at night. I may need to lower the intensity/filter.

Here is a full layout of the parts on the small PC board. The top of the board still needs to be cut down to just above the row of 100 mil I/O pins for the Display and CAN cable. Along the left edge is the pot to control LCD contrast, reset switch and RGB LED. Along the right edge is the four pin program/debug port, three pin connector the for the 50 MHz resonator and two pin serial port. The top has the 16 pin connector to the LCD display and eight pin connector to the CAN cable. The plan is to use Cat-5 cable (4 twisted pair, EV-CAN(2), Selector Pot(2), +12 volts, Ground, and future CAR-CAN(2)). There is room for one more MCP2551 CAN Transceiver if I decide to monitor the CAR-CAN too (not too likely as I need to externally select between CAN buses)
overview1.jpg


Here is what it looks like with the display on top.
overview2i.jpg


These two pictures also include a display on the mounting bracket that will be Velcro’ed above the rearview mirror and the OBD2 connector (very low profile).

Here is a shot of me holding the bracket in place. I will be making a black bezel so only the display shows through
mirrorz.jpg


Here is a close-up of just the logic board.
logicbd.jpg


Jim
 
Great job!

Why not control LCD contrast with PWM from the micro? For that matter, you can also control LED brightness the same way.

For me, I consider the battery to be an energy source, so positive numbers mean it's doing it's normal job, negative numbers mean charge. LEAFSCAN is calibrated this way, and if you look at almost all other battery management systems, they are done this way was well.

Since most of the time you are behind the wheel you are causing loads, it's easier to not have to think about the negative. (except during regen)

It also cleans up the display to not have the negative sign there on the large discharge numbers. There is more room for it during charge/regen. :)

-Phil
 
Phil

From what I have seen on my test unit once the contrast is set it does not need to be changed. It should be a one time adjustment after build.

The sign is easy to change if that is the standard meaning.
 
Turbo3 said:
Phil

From what I have seen on my test unit once the contrast is set it does not need to be changed. It should be a one time adjustment after build.

The sign is easy to change if that is the standard meaning.
Most LCD's need a temperature compensation for the contrast. Try it on a cold/hot day.

-Phil
 
Everyone seems to want to mount their Torboscan/Leafscan above the rear-view mirror. I'd much rather have it mounted above the upper left corner of the center display. This puts it a lot closer to the instrument cluster.

I'd lie to see an arrangement where you could pop out the center console, slip in some sort of a thin L bracket and reseat the console to hold it.
 
Here are a couple of pictures of the finish prototype from yesterday at the Hybrids 2Hotrods show. I left the car on during the show which is why there is almost 7 hours on the run-time timer.

I did not have time to make and route a cable up to the mirror so I just temporarily mounted it above the center console.
consoleh.jpg


Here is a close-up as I was entering the Mercury News parking lot.
enterlot.jpg
 
DoxyLover said:
Everyone seems to want to mount their Torboscan/Leafscan above the rear-view mirror. I'd much rather have it mounted above the upper left corner of the center display. This puts it a lot closer to the instrument cluster.

I'd lie to see an arrangement where you could pop out the center console, slip in some sort of a thin L bracket and reseat the console to hold it.

You could use a MTU Dashmount, usually used for mobile phones.

http://shop.mtutelecom.de/default.a...WREC=-1998698853&WKEY=[2:003002019][1:701228]

Edit: The URL is correct, I do not know why it's not clickable. Copy/paste works.
 
Since the name "TurboScan” does not describe the functions of this device I have changed the name to something more meaningful. Thanks to my wife the new name is now WattsLeft™ Monitor.

Here is the presentation I gave at the last BayLeafs meeting in July.
wattsleftv05.jpg

wattsleftv05b.jpg

wattsleftv05c.jpg


A couple of weeks ago I ordered and received one batch of three prototype PCBs and built up one board for testing and to work out how to package it with the display.

Packaging of the hardware is now complete. It all fits in a nice small case (smaller than Gary’s SOC meter case). The custom PCB is the same size as the display board and connects to it through a single 1x16 pin header. External connections to the OBCII connector and remote rotary controller are made through a 1x8 connector on the back.

The reset button on the back of the case is used to access the startup configuration screen and display software version. This is not finalized yet but currently is used to select when the serial port is enabled to send data. Reset does not clear any saved history data. Only unplugging the OBDII clears the saved data.

One major addition is support for a small external Bluetooth module connected to the serial port and located between the PCB and the back of the case. A MOSFET has been added to the next version of the PCB to cut power to the Bluetooth module during sleep mode. This BT module allows wireless monitoring of EV or CAN frames with a notebook or Android device (app needed). The current serial format for testing is Gary’s CANDO format.

The updated PCB has been finalized and a production batch of boards has been ordered with an Aug 8th delivery date.

How much interest is there in the Bluetooth feature? I estimate it to add $20-25 to the final cost.
 
Here are some additional pictures.

Back of case with cable attached.
backcable.jpg


Prototype hanger I just made to allow placement of monitor just above rearview mirror.
hanger.jpg


Outside view with cable hidden in headlining.
outsideviewi.jpg


Finally the inside view.
insideview.jpg


Jim
 
Turbo3 said:
Here are some additional pictures:
Back of case with cable attached...
Prototype hanger I just made to allow placement of monitor just above rearview mirror...
Outside view with cable hidden in headlining...
Finally the inside view...
Looking good, Jim!! :D
 
Here is a close-up view of first prototype PCB. It was design for either pin-in-hole or surface mount parts for most of the resistors and capacitors.
pcbv10.jpg


The final PCB has a custom connector for the Bluetooth module plus other minor improvements in function and component placement. All surface mount parts are now on the back side. There is also the option to connect the BT receiver to the CPU or either CAN bus driver to the CPU. A jumper has been added to disable the RGB LED.

The DC-DC filter caps are way over spec and rated at 105c so there should be no issue handling the high temps in the car. (I also just happen to have a lot of them on hand.)

Jim
 
Back
Top