Hardware Iteration (hardware V00H)

The last time I worked on the electronics was when I got the switching boost circuit working.  The crashes I saw with it is why I did so much code work since then.  This week, I wanted to get back into electronics.  Since it has been a while I started by reviewing the schematic.  First thing I reviewed was the Lithium cell charger circuit.  It matches the reference design in the AAT3672 datasheet and it matches the PCB.  I should test it before I spin another set of boards.  I put a note on the schematic to remind myself to do that.

I then looked at the switched boost circuit. It turns out I don’t need L2, the real problem was in software. I removed L2 from the schematic. The resistor R5 was changed to 47 Ohms. I updated that on the schematic.  Next I looked at the USB to Serial Bridge, I have two cuts with Jumpers on the board, I checked them against the schematic. The schematic matches the patch I had made.

Next I compared the patches I made to the SPI RAM against a pinout of the ESP-12F I found online.  ESP-12F pins 9 – 14 on the schematic matches the PCB with the modifications I have made.  Pin 16 is no longer connected and Pin 18(GPIO0) is connected.  I had made this change back when I was testing the SPI RAM. With this change, D4, Q6, R26, and R27 are unnecessary. I removed them from the schematic and tied GPIO0 to U2 Pin1 and disconnected it from U10 Pin 6. I then tied GPIO15 to U10 Pin6 with a net label called A_SEL.  I have yet to test IO2 and IO3, Which will require running the RAM in QIO mode. In QIO mode, IO2/IO3 shouldn’t matter because when I read them back out of the RAM will come back out on the same pins they went in.

I have yet to test the level shift chip(U3).  I don’t like how hard U3 is to solder so I researched a different part to do the same thing. The new part I found is a TI TXB0108PWR which works very nearly the same as what I already had designed in but comes in a 20 pin TSSOP which is easier to solder.  The Pin order is different. The part is only US $1.88 in singles at Digikey.  I proceeded to change U3 to the new part on the schematic.  The datasheet recommends that OE be held low until both Vcca and Vccb are on.  I put a PNP transistor in to pull OE low anytime Vt is not driven.  As I dug into the datasheet, I found that this chip would not work for I2C.

So I did a little more research and I found another chip from TI.  The TXS0108EPWR works with SPI and I2C.  It has the same pinout as the TI TXB0108PWR so adding it to the schematic was really easy, I changed the name in the schematic.  This part is US $2.00 on Digikey.


I uploaded the updated hardware design to Github. Click on the hardware link in the right column to go get it.

Have you used level shifters before? Have you decided on a chip only to find out that it was missing one crucial component? How did you fix it?

Hantek MSO5202 Mixed Signal Oscilloscope review

mso5202d(Picture taken from Aliexpress.com)

This scope has 2 analog channels and 16 digital channels With Bandwidth up to 200 MHz.
1 Million sample points for the analog channels.
512K sample points for the Logic Analyzer channels
7 inch 800×400 color LCD display
USB Host for flash drives
USB client for PC control

Capture 16 channels digital and 2 channels Analog simultaneously.
Export captured data to CSV file (useful for analysis)
Linux based (hackable!)
Familiar knob/face layout
Bright clear display

No protocol analysis built in. No way to add protocol analysis.
No Linux PC support
Occasionally crashes
D0 is only digital trigger line

My experience with this scope:

The Purchase:
I bought the scope off of Aliexpress.com.  I knew I wanted at least 100MHz Bandwidth. I also didn’t have a lot to spend.   There wasn’t a big cost savings to go to the 100 MHz scope, so I decided to go ahead and get the 200 MHz Version.  Since I have bought the scope, I have seen information on how to hack the 60 or 70 MHz models to get the full 200 MHz performance. Assuming the scope lives up to their specs, I am happy to pay for the Higher bandwidth.  This scope is still a bargain with a price less than $500 US.  The seller shipped it to me for free with DHL shipping. The scope was delivered within 7 days.

The scope came in the manufacturers box inside of another box it just fit inside.  I cut the tape on the outer box and opened it to see a handle on top of the manufacturers box.  I started to lift by that handle and the bottom of the manufacturers box fell out.  I had only lifted it a few inches so the bubble plastic protecting the scope protected it from damage.

First use:
I connected the power cord and nothing else. Turned on the power and it booted up quickly (less than 10 seconds). I then dug out the probes and hooked them up. The probes came with color rings to help identify which channel I was using.  Both probes came with red rings on both ends of the probe.  I looked at the scope and saw that the color for channel 1 is yellow and the color for channel 2 is blue.  I grabbed one of the probes and switched the colored rings to yellow and connected it to channel 1.  I repeated that process with blue rings for channel 2.  I connected the probes to the calibration tang on the front of the scope and did a quick adjustment of each probe.  The knobs have a good feel to them and the waveforms change the way I anticipated for each turn.  This made this scope feel very familiar.  All of this was done without reading the manual. So far so good!

I have a circuit that the LCD got damaged on and I wanted to see how the Logic Analyzer worked.  The LCD is controlled by SPI. I hooked up the data lines, figured out how to trigger off of D0 and it kind of worked.  It wasn’t real clear how to get to the Logic Analyzer to begin with. I found it with playing.  Then I figured the chip select line of the LCD would be a good choice to trigger off of.  There is a short glitch just after power up that meant the scope triggered way too early.  I was disappointed that I couldn’t change the trigger to a different digital channel, I had to move the connections around instead. To make the connections to the LCD, I had to solder several 30 gauge wires to the data lines I was interested in. These wires are fragile so changing the connections to them was difficult.  The scoped locked up or did weird things while I was tinkering.

Data Capture:
I was also disappointed that there was no simple data analysis for the Logic Analyzer system.  I captured a chunk of the LCD SPI data and saved it as CSV file to a flash drive.  I put the flash drive into my computer and opened the CSV file with LibreOffice Calc.  With some complex cell calculations I was able to get Calc to show me the data that was sent for each time chip select was active. The good news is it showed me the circuit wasn’t damaged and a replacement LCD should fix the device.(The scope served it’s purpose)

I found this scope to be very intuitive to use for analog signals.  The Logic Analyzer function is very useful but is not very intuitive and is missing some features.  If I had this when I was testing the SPI on the Uprogrammer board, I would have found my problems much quicker.  I watched a few of the hack videos on YouTube. They connect a USB to Serial bridge to the system and issue a few Linux commands. Linux is a great place to start hacking. On the back is a punch out with a Networking symbol next to it.  If it turns out that there is a chip that supports ethernet on the board, I would like to install the ethernet jack and see what happens.  From the hack videos, I can see there is a place on the PCB for the ethernet Jack.

My Opinion:
This an excellent scope for the price.  I have seen online videos that indicate problems when approaching the higher bandwidth limits of the scope.  I don’t believe these problems will affect me.  If you need high precision in near 200 MHz, I would suggest looking for a better scope.  Otherwise this will make a fine tool on your bench.  Firmware is still being developed for this scope, so I expect it to get better over time with updates. Since it is Linux based I also expect the community to hack it for better features than just a bandwidth upgrade.

Have you used one of these scopes?  Have you worked with one near 200 MHz?  What is your feelings about the lack of digital features? How about the occasional lock up?

Finishing cleanup Firmware V00

I decided that the code that interacts directly with the hardware registers can’t be rewritten to be much clearer to read. There should be a lot of commenting in the code explaining why the registers need to be set that way.  That is a big project and since I didn’t write most of that code, I don’t understand a lot of it.  I am choosing this week to just make sure this code is formatted in the Allman style and leave commenting for later.

I have now worked through all the .c and .h files in the project to made sure they are formatted in the Allman style. I decided to go back through all the names used for variables, functions, constants, and macros and format them all the same.  Since Espressif named all the system calls in lowercase underscore separated, system calls will follow that format.

The rest of the naming I decided as follows:

Macro: All caps with underscore separation followed by ()

Constant: All caps with underscore separation

Variable: Lower camel case

Non System functions: lower camel case with ()

I used Eclipse’ refactor feature to make these changes to all the files at once.

I had a couple of .h files that didn’t refactor correctly, but once i got those fixed, the code compiled and ran just like before.

The firmware is getting easier to maintain and edit.  I hope to move forward with the electronics design again soon.  I bought and received a new mixed signal oscilloscope and received it this last week, I plan on doing a review of it next week. I have uploaded these changes to Github, click the link in the right hand column to get the firmware source.

Have you used Eclipse’ refactor function before?  Did you have similar problems?

Simple Serial Cleanup V00J

Because of the size and complexity of simple_serial.c, I decided I would work on cleaning it up for this week’s post.

To start with, I created two new files for postable events called events.c and events.h.  I moved the function task_handler() from simple_serial.c to events.c and added a //TODO comment to remind me to clean up the task handler code.  This created a bunch of errors because I haven’t included any of the library header files.  So I stepped through the process of adding the necessary header files.  I copied all of the include statements from simple serial.c to events.c and eclipse reported no errors.  Next, I commented out one line at a time of the include statements. When eclipse indicated errors in the file, I uncommented that line and moved on to the next.  I ended up only needing two include statements: uart.h and user_interface.h.   I moved the prototype of task_handler from simple_serial.h to events.h. Then I put an include statement into simple_serial.c for events.h.

I decided this was a good point to build to see if I had broken anything. It failed to build.  The error I got was

In file included from simple_serial.c:22:0:
../include/events.h:14:1: error: 'task_handler' used but never defined [-Werror]
 task_handler(os_event_t *);

The LOCAL keyword was making task handler only available to events.c.  I removed the LOCAL keyword from both events.h and events.c and got a new error.

user/.output/eagle/debug/lib/libuser.a(events.o):(.irom0.text+0x2c): undefined reference to `os_sprintf'

It looks like eclipse did not report an error when I removed one of the include lines.  I went back and added one of them at at time till the error went away.  The missing include was osapi.h  The code built and I tested it on the board. It booted and connected to the wifi as expected.

Next I created some macros that I will use when posting a task for serial events.  Now serial_init() is much easier to understand.

Next, I took on simple_config_ui().  First I started by looking at the biggest case statement which had another switch/case statement enclosed. When menu_stat is equal to IDLE, there is a switch/case for handling received characters;  I created a function called recv_byte(char recvd), copied the code and made a few little changes to make it compile and run.  I continued this process of taking large chunks of code and putting them into functions.

Finally I created a new uart.c and moved the code I originally got from uart.c out of simple_serial.c into uart.c. It took a little fiddling to get it all working again.  I have uploaded this update to Github.  Click the firmware link near the top of the right hand column to download it.

Are you cleaning up code? Did you learn to write “easy to read” code in school? How did you learn to write code? Are you learning to write code now?