Turbo3
Gold Member
Posts: 1821
Joined: Mon Jul 19, 2010 8:34 pm
Delivery Date: 12 May 2011
Leaf Number: 002191
Location: San Jose, CA

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

Thu Apr 12, 2012 12:10 am

(Updated name from "TurboScan" to WattsLeft™ Monitor 7/24)
(Updated to include pricing table 2/23/13)
Here is the current price list.
Image
If you are interested in getting a WattsLeft™ please email to WattsLeft.meter@gmail.com. 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).
Image

Here is the pin list.
Image

Here is a summary of the instruction set.
Image

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.
Image

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.
Image

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).
Image

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.
Image

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.
Image

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.
Last edited by Turbo3 on Sat Feb 23, 2013 4:29 pm, edited 8 times in total.

User avatar
garygid
Gold Member
Posts: 12417
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Re: Parallax SX28AC/DP SOC/CAN Monitor Project

Thu Apr 12, 2012 7:18 am

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
See SOC/GID-Meter and CAN-Do Info
2011 LEAF, sold in 2015
2010 Prius, 2014 silver Tesla S
Nissan EVSE, mod to 240/120v 16A
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
To Sell: X-treme 5000Li EV motorcycle

DurkaDurka
Posts: 100
Joined: Tue Aug 09, 2011 5:07 pm
Delivery Date: 12 Jan 2011

Re: Parallax SX28AC/DP SOC/CAN Monitor Project

Thu Apr 12, 2012 7:24 am

Is it possible someone with technical/soldering skill could build this on the cheap? What are the parts cost?

Turbo3
Gold Member
Posts: 1821
Joined: Mon Jul 19, 2010 8:34 pm
Delivery Date: 12 May 2011
Leaf Number: 002191
Location: San Jose, CA

Re: Parallax SX28AC/DP SOC/CAN Monitor Project

Thu Apr 12, 2012 11:48 am

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.)
Image

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

User avatar
garygid
Gold Member
Posts: 12417
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Re: Parallax SX28AC/DP SOC/CAN Monitor Project

Fri Apr 13, 2012 7:05 am

Time (HH:MM:SS) since Reboot - Very Nice.

Now, let's find the Battery Temperature(s), and the Tire Pressures. :o
See SOC/GID-Meter and CAN-Do Info
2011 LEAF, sold in 2015
2010 Prius, 2014 silver Tesla S
Nissan EVSE, mod to 240/120v 16A
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
To Sell: X-treme 5000Li EV motorcycle

Turbo3
Gold Member
Posts: 1821
Joined: Mon Jul 19, 2010 8:34 pm
Delivery Date: 12 May 2011
Leaf Number: 002191
Location: San Jose, CA

Re: Parallax SX28AC/DP SOC/CAN Monitor Project

Mon May 07, 2012 9:10 pm

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:
Image

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.
Image

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);
Image

Here is what it looks like under regen.
Image

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.
Image

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.
Image

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.
Last edited by Turbo3 on Thu May 10, 2012 11:29 am, edited 1 time in total.

User avatar
garygid
Gold Member
Posts: 12417
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Re: "TurboScan" Parallax SX28AC/DP SOC/CAN Monitor Project

Tue May 08, 2012 8:57 am

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.
See SOC/GID-Meter and CAN-Do Info
2011 LEAF, sold in 2015
2010 Prius, 2014 silver Tesla S
Nissan EVSE, mod to 240/120v 16A
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
To Sell: X-treme 5000Li EV motorcycle

Turbo3
Gold Member
Posts: 1821
Joined: Mon Jul 19, 2010 8:34 pm
Delivery Date: 12 May 2011
Leaf Number: 002191
Location: San Jose, CA

Re: "TurboScan" Parallax SX28AC/DP SOC/CAN Monitor Project

Thu May 10, 2012 11:28 am

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.
Image

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)
Image

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

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
Image

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

Jim

User avatar
Ingineer
Posts: 2735
Joined: Fri Oct 15, 2010 1:09 pm
Delivery Date: 13 Jul 2011
Leaf Number: 6969
Location: Berkeley, California
Contact: Website

Re: "TurboScan" Parallax SX28AC/DP SOC/CAN Monitor Project

Thu May 10, 2012 11:43 am

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
Easily Learn Electricity HERE! - - - - Website: http://evseupgrade.com/ - - - - Like us on Facebook: EVSE Upgrade

Turbo3
Gold Member
Posts: 1821
Joined: Mon Jul 19, 2010 8:34 pm
Delivery Date: 12 May 2011
Leaf Number: 002191
Location: San Jose, CA

Re: "TurboScan" Parallax SX28AC/DP SOC/CAN Monitor Project

Thu May 10, 2012 12:08 pm

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.

Return to “LEAF CANBus”