Using an Arduino Due as a mini-QC controller

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

Is the MAC address fixed, so that there can only be one of these
on a local network?
If not, then there is an easy way to set a new MAC address?

If you feel that it will be useful, I will order one, or two.
 
garygid said:
Excellent.

Is the MAC address fixed, so that there can only be one of these
on a local network?
If not, then there is an easy way to set a new MAC address?

If you feel that it will be useful, I will order one, or two.

You can set the MAC address. If you check any of the example scripts for the Ethernet library, they all allow you to set a fixed MAC and IP address (in case DHCP wont assign one).

I think having Ethernet as communication would be quite useful,
a) you could remote control the unit via network
b) its easy to make it wireless via ethernet-2-wifi adapter
c) communication in server-client model is maybe more comfortable than moving stuff along the serial port...(?)

I also have the "cheaper" ENC28J60 based module here ($11.99+free shipping) vs this (the W5100 based, which was $16.00 + $3.82 for shipping). The ENC28J60 needs its own library though and for saving $8 might not be worth the hassle.

Do the CAN proto boards you have allow to attach an SPI device AND the CTE display shield?
 
The CTE display Shield uses the SPI, so one needs
to solder some wires to get the SPI out to use.

I tried to get the datasheet and schematic, but
apparently one need a userid and password.
Does anonymous and "any" password work?

I will try again.
Well, the FTP logs in but then listing the directory
gives a permission denied error.

The trouble with using each additional feature is
that it might inhibit the basic control function
of the Due, controlling the PWM and output of the
power supply.
 
The biggest problem using the Due so far:

Edit: Solved. My programming error, counting the log
messages at the wrong place, made it look like the
timer was not working, but it really is working.

The one (or several) millisecond timer that should be
controlling the output of the power supply must not
be masked, or delayed for any substantial amount of time.
Some microseconds of delay, while another fast interrupt
is finishing execution is OK, but some process, usually
some software I/O, cannot be allowed to hog the CPU.

So far, the simple touch-input buttons that I am using
seem to inhibit the timer whenever the "finger" is actually
pressing the button. Apparently the "wait for un-touch"
function is the likely suspect.
If this cannot be fixed, we cannot use the touch input.

Does someone want to investigate this?

We must make sure that updating the screen does
not hog the CPU, but allows the timer to interrupt.
Some of the Demos that are incorporated in my
Sketch seem to be doing some "hogging" of the CPU.
 
Notes on running my Scripts.
Many details and links in this thresd's 2nd post.
(If anybody needs additional links, I will add them.)

Hardwre:
1. Arduino Due R3, unmodified
2. Proto-board shield for the Due (not yet required)
3. ColdTears Electronics (CTE) display Shield for Due (not Mega)
4. A CTE touch-display (with font chip), see list below.
5. USB cable, A to micro B to fit the Due's Programming port.
6. Host computer (l use a Windows PC) to run the Arduino IDE
(Interactive Development Environment).
7. Host hardware to run my Windows CAN-Do program (NYR).

Software:
1. The latest IDE for the Due (now, 1.5.4r2) from Arduino
2. Three added Libraries, modified by me.
3. Other non-included Libraries.
4. My Script for Mini-QC simulation.
5. My CAN-Do program, not required, for capturing and seeing log data.

Touch Display Boards:
CTE32HR or CTE35 are the most likely candidates,
because of their lower cost. Both are 480X320.
I have also used the larger 4", 5", and 7" displays, all 800x480.

At this point (v29), my Script seems to support all 5 of these
displays, by changing one line of the source code to specify
the display device, CTE32HR, CTE35, CTE40, CTE50, and CTE70.

CAUTION : This hardware and software is not yet suitable or
safe to use for controlling any real-time critical process, like
a power supply used as a charger for car batteries.

But, if you are interested in joining the project, welcome aboard.
Cheers, Gary
 
garygid said:
Does someone want to investigate this?

I will look into it.
Likewise for interference of the ethernet.

SO basically we want to be able to set priorities for timers/interrupts.

I assume that the PWM/voltage sensing functions should have highest priority, followed by the CAN interrupt?
 
The datasheet for this uP is 1467 pages long.

I think timers, interrupts, and other things are handled
differently, at least by the "operating system" that
Arduino has made for the Due. The many embedded
hardware subsystems within the Due appear to have some
subtle interactions.

The PWM just gets set up, and runs forever, with us just
setting the ON duty cycle greater than zero occasionally.
No interrupts there.

There is errata (and a table of contents) at the end of
the datasheet, where they explain that a few things do
not work as intended, including starting to read
analog inputs. But, we should be reading the values
at each timer "interrupt", and then setting them up
to begin reading again.

There is a fail-safe feature that seems to affect several
of the subsystems, and we might need to understand
that "feature" before we are done.

So far, it is not clear that there is a real interrupt
from the Timer, so I am not even sure that real
"traditional" interrupts exist.

You will discover rbi, cbi, and sbi(A, B) that are read,
clear, and set the bits in A that are ON in the B mask.

So far, looking down through the Utouch functions,
I do not understand what seems to be "masking"
the Timer operation.

Edit: Problem Solved. I was counting the log messages
at the wrong spot, but the Timer is working OK.


I can send my latest sketch, if desired.
Thanks for the help.

I tried using my own GgDelay in place of the
delay() used in my WaitForUntouch, but that
did not seem to help.
 
This Arduino Due Forum guy posts his DueTC library (iso, h, and cpp) at
http://forum.arduino.cc//index.php?topic=194568.0" onclick="window.open(this.href);return false;

where he is controlling the Due hardware directly, apparently
using parts of the hardware that the Arduino "OS" is not using.

This is the type of control that we might need to do in order to
make out mini-QC work reliably.

I have copied his code, and I am cleaning it up a bit.
I will then attempt to understand the constraints on each
timer or interrupt. I thought that I had chosen one that
did not connect to any outout pin, but it appears that
his use output pins.

I will extract the code for one timer-interrupt (he supports 4 or 5
by duplicating code) and try it in my Sketch. I will post my results,
hopefully this evening.

Cheers, Gary
 
The DueTC library did nor seem to help, or the interrupt
that I chose to use happens to be the one "clobbered"
by keeping a touch-button pressed.

I will try using a different interrupt, but now I am
guessing that the use of the UTouch functions
is somehow inhibiting the interrupts.

Or, there is something wrong in my interrupt handler.

Still confused, Gary

Edit: Problem Found, see below.
 
Oops,
The interrupt is working, I just made an error :oops: :oops:
in where I was counting the generated log messages,
so it stopped counting when the ring buffer is full.
It was just counting the messages that got inserted
into the ring buffer.

Oh, holy Habib, I am making Great Shame upon my own self! :eek:

So, now, in v31, the log count continues, even when
holding a button down, just the logging output stops,
which I already knew needed to be reprogrammed.

Cheers, Gary :shock:
 
My v33 now has new touch-handling code that allows the
Loop to continue processing even when a touch is held down.
So, now a screen can continue updating even while touch
input is in progress.

In v33 I have applied the new touch handling to only
the Main and Buttons menus, but while playing with the
checkbox and radio Buttons on the Buttons screen, that
screen continues to update (after Start Logging).

Felix, thanks for your Sketches, I will enjoy reading them,
and learning from your experience.

"BOO" to all, Gary
(practice safe treating)
 
Version 34 now has all the menus converted to the new
touch-processing steps. Actions are usually done on Button-Up
but can also be done on Button-Down, like in the Number-Entry
screes's menu and action handling.

Now, I need to get some simulated Manual Mode operation going,
and use this to refine the Logging scheme, both to CAN-Do, and
to the SD card on the back of the display (or possibly the one on the
CTE display Shield for Due). I plan to use the ". alc" file format,
so that the files can be directly read by CAN-Do.

Reading Analog Inputs needs to be done quickly at the beginning
of the Timer interrupt, and re-starting the conversation for the next
interrupt to read (I suspect).

From now, I will use my simulated values.

The logging will be done by creating CAN messages with the
desired data in them. The QC CAN messages 108 and 109 already
hold the charger's own measure of the output current (and voltage,
I believe). We will create a 10C message (if not already used elsewhere
in the car) to leave room for the future expansion of the two
charger-produced CAN messages.

I will include (exact details to be determined):
1. Temperature
2. Perhaps a more precise Voltage or Current
3. Input AC Voltage and current
4. PWM setting
5. Some status bits
 
Logging Details.

Message Structure:

1. Message ID
Eleven bits, normally 7FF max for real CAN messages.
Up to FFF for pseudo-CAN Messages, never sent via CAN.
Represented as HLL, three hex nibbles.

2. Data Length Nibble
A single hex nibble, 0 to 8 for real CAN messages.
The value F is used for pseudo-messages, which
are never transmitted via CAN.
Represented by N, one hex nibble.

3. Data Bytes
Eight bytes, D1 through D8, any values 0 to FF.
When the data Length is less than 8,the unused
data bytes are forced to FF before logging.

4. Sync Byte
One byte, EOR of NH LL 0x53
Represented as one byte SY.

5. Time Stamp
Two byte value = seconds *1024, + milliseconds.
(or, faster, ((sec << 10) + ms)
Seconds = 0 to 59, ms = 0 to 999.
Represented by two bytes SS MM

6. CAN Type
A single byte, usually 1 to 4 for CAN types
EV, CAR, AV, and QC.
The value 0 is used for Date-Time Messages, and
other messages, like Events, that apply to all
the CAN types.
One byte, represented by TY.

7. ALC format Message
A fixed length (14-byte) binary "record", with no delimiter.
SY LL NH D1 D2 D3 D4 D5 D6 D7 D8 SS MM TY

Source of Log Messages:

1. Test Messages
Valid CAN messages, or pseudo-messages, usually with
data fields that include sequence numbers so that
missing messages can be detected.
The Time Stamp tells when they were created.
My Arduino Due Sketch creates these now.

2. Internal Operation Data
Messages, pseudo or CAN that hold data important
to monitoring and evaluating the design and performance
of the mini-QC. Example, temperature, input AC Current, etc.

3. Date-Time Messages
These are special pseudo-messages, with N=F
and MsgID =FFF, where the data first 4 bytes contain
the Date-Time as the number of seconds part the
start of 1970 (I think), and the other 4 bytes...
zero, I think, but I need to check.
These messages are recognized and used by CAN-Do.

4. Status-Event Messages
With N=F, and the MsgID =FFE, and the data is 8 ASCII
characters, these pseudo-messages are recognized
by CAN-Do as Event, or Error, messages to the user.

Using MsgID = FFC to make a "Continuation" message,
one can extend the ASCII message to 16 or 24 characters,
but these messages must precede the FFE message.

A feature of CAN-Do is to insert User-defined Event
messages into the arriving log stream. This is handy
when looking for something like window-control bits
in the CAR-CAN data. Just before running the window
down, insert a Down-Event, etc. to help locate the
desired data in the Log.

5. CAN Input
We want to handle getting the CAN input on an interrupt,
so that the message gets read out of the MOB (CAN
hardware "Mailbox") quickly, the MOB gets prepared to
receive again quickly, and the received message gets
its Time Stamp, is processed as needed, and is put into
the Ring Buffer in proper sequence.

To handle fast-arriving messages, one right on the
tail of another, one usually needs to use two or more
MOBs to avoid missing messages.

So, get the message out of the MOB, check various
error flags to see if it is a "good" message, get a
Seconds-Milliseconds Time Stamp, reset the MOB,
and write the message into the Buffer.
Then, copy the message for use by the Timer.

6. CAN Output
The real CAN Messages, to be sent on the CAN bus,
should also be logged as well as properly sent.
Conflicts with the other interrupts need to be
carefully avoided, and in general, the interrupts
should not interrupt each other. A bit of masking
or checking limits is wise, so check N <= 8 and
MsgID <= 7FF.
 
The Message Ring Buffer:

1. Size of the buffer
Allocated in 14 byte increments, like an array
LogMsg items, one might need an array that
can hold a couple thousand messages, if
there are substantial delays is writing to the
SD card. Writing to the SerialUSB appears to
work rather quickly.

My v34 Sketch has a very simple Ring Buffer now,
and it holds about 255 messages.

2. Location of the buffer
One might need to use the alternate 32k of RAM.

Sketch v34 uses the normal 64k of RAM.

3. Adding Messages
Normally the ring Buffer is not full, and one simply
writes the message into the write-location of the
buffer, and then increments, or wraps around,
the write-location pointer. It helps if the pointer
update is "atomic", but that is not really necessary
since this is always done by an interrupt handler.

4. Buffer Full detection.
Detecting a full buffer requires reading the read-
pointer, and comparing with the write-pointer.
Updating the Read-pointer must be atomic,
or masked by disabling interrupts very briefly.

Is storing a 4-byte integer an atomic instruction
in the Due?

When the pointers are equal, the buffer is empty.
When the write pointer is just one behind the
read pointer (taking pointer-wrapping into account)
the crcular ("ring") buffer is full.

5. Overflow Handling
Although one hopes to avoid buffer-full overflows, it
is important to detect and handle this case.
One generally needs to discard the message, but
over-writing the previous (last stored in the buffer)
message can be used to include a count of the lost
messages in the data log.

The MsgID of the last message is overwrtten to make
it a pseudo message, an Overflow-Event, which can
easily be listed and seen in the log. The Data is over-
written with a message and a count, like "Lost0000".
A lost-message counter is set to 2, and that serves as
a flag the there is an Overflow-in-Progress.

Each time the buffer is full, and another message is
lost, the counter gets incremented. Finally, when the
buffer becomes non-full again, the counter value is
inserted into the 0000 part of the message, the
counter is reset to zero, and the new message
is written into the buffer. Cool, I think.

As of v34, my Sketch just throws overflow
messages away.

Now, in my Sketch v35, this is implemented
and tested. For testing, setting the Log to SD
checkbox On inhibits writing to the SerialUSB
port. Keeping it On for about 4 seconds loses
about 2000 - 255 messages.

6. Removing and Processing Messages
Generally, as each messages is removed, it is
Logged, to the SerialUSB and/or SD Card,
depending upon the User Settings.

My v34 only supports the SerialUSB logging,
but I intend to support SD card logging soon.

In some cases, the logging process might
not return immediately, which could bring
the Loop to a temporary halt. Severe cases
might require adding checks for possible output
delay conditions first, and continuing the Loop
until the condition clears. In some cases the
actual output might need to be interrupt driven.

Logging via USB to CAN-Do:

1. Using SerialUSB.write
Once the Native USB Port connects to the PC
and is properly recognized, a program like CAN-Do
can connect to it, and begin to receive data.

2. Native USB Port reset issues with Due.
Each time the Due is Reset (when a Sketch is uploaded
to the Due, the Serial Monitor is opened, the Reset
button is pressed, or Power is cycled) the Port
disappears, and reappears shortly after the Due gets
going again. Then, it typically takes a few seconds
from the virtual Comm Port to reappear in the PC.

3. Mod to CAN-Do needed.
I need to add a feature to CAN-Do, so that it will
loop waiting for the port to reappear. For now,
I need to wait for the port manually, and then
start Reading the logging data in CAN-Do.
 
Logging to SD card:

0. Of course, figuring out how to address or access
the desired SD card socket is the first issue.
Since the display (and touch) use the SPI port,
I think, and both the CTE display board and the
CTE display shield for Due have an SD card socket,
I need some additional information, it appears.

1. Detecting SD Card

2. Detecting Unlocked condition

3. Log File Name
Use a "unique" and easily sorted file name, like
YYMMDDnn.alc

4. Does a file already Exist?

5. Sequencing file name
If the intended log file already exists,
simply increment the value that represents
the fiile name, and try again, some limited
number of times.

6. Opening the File

7. Writing binary data to the file

8. Closing the File
If power is turned off abruptly, this can
be a problem, perhaps resulting in
an unreadable SD card.

Miscellaneous:

1.
 
Gary,

I sent you an email but I got my 5" touchscreen figured out and the calibration data read off of it for the X,Y,Z... but now I'm having a hard time getting your v34 program to run on the 5"

I can only get it to run if I disable all the touch input stuff pretty much.. (comment out your custom libraries for uTouch and anything for calibration data)

I'm still trying to figure this stuff out but right now it's just running in Demo/display mode...
 
Splendid work.
How did you fix the no-y 5" touch problem?

Using the standard IDE 1.5.4r2 version and the libraries
that I sent (UTFT_Gg, UTFT_CTE_Gg, and UTouch_Gg),
which you should use these instead of the UTFT, UTFT_CTE,
and UTouch libraries... and the DueTC library and...

Selecting CTE50 as the display, and just compiling,
does the compile get any errors?
If so, what?

We got the program to compile ok on my computer,
and uploaded the program to your Due, and saw
the Main Menu on the 5" screen, right?

Are you not getting that now?

Maybe call when you are at your computer.
I will email my latest version in the morning.

And, I will try it on my 5" CTE50 display.

I added a text-entry on-screen keyboard today,
which one can test on my v38 Buttons menu.

Cheers, Gary
 
Yeah.. my issue in compiling is looking through my emails.. I can't find or never got the (UTFT_Gg, UTFT_CTE_Gg, and UTouch_Gg) libs..

but when I comment out the area for the x,y,z calibration it runs fine..

CanDo_Log_Test_Gg34:505: error: 'class UTouch' has no member named 'setCalib'

I'm sure if you sent me your custom libraries again this will work because in looking in the standard uTouch.. there is no "setCalib" :|
 
Back
Top