Archive for the ‘electronic’ Category
Move to 32 bits ARM core
Recently I moved my projects to 32 bits ARM way. After some time thinking about various platforms, I’ve decide to abandon any Windows based tool, and trying to work only with Mac, without Parallels Desktop. For small 8 or 16 bits PIC projects, I still use MPLABX. For ARM core I’ve decide to use STM32 series.
As development tool I’ve chosen Rowley CrossWorks. They have a reasonably price for non-commercial use ($150) and the most important, a Mac Os Lion version. I’ve also bought some STM32 boards, and in that post I’ll show my steps with one of them: STM32L-DISCOVERY. The other boards I also have are STM32F4-DISCOVERY and WaveShare Port103R (great board! post more later).
STM32L-DISCOVERY Development Board
The STM32L-DISCOVERY helps you to discover the STM32L ultra low power features and to develop and share your applications.
It is based on an STM32L152RBT6 and includes an ST-Link/V2 embedded debugging tool interface, a LCD (24 segments, 4 commons), LEDs, push buttons, a linear touch sensor or touch keys.
Recent version of Rowley CrossWorks for ARM added support for ST-Link/V2 programmers, so you can connect STM32L-DISCOVERY board directly to your Mac and start ARM developing.
Environment preparation steps
To work with STM32L-DISCOVERY board in CrossWorks, we’ll need to do some preparations:
- Install CrossWorks “STMicroelectronics STM32 CPU Support Package”:
- Choose “Tools” menu, then “Package Manager…“
- In search box, write “STM32 CPU Support”
- Double click to change action to “Install”
- Install the “STM32L-DISCOVERY firmware package” (version 1.0.2):
- You’ll need to download it from the ST website;
- Unfortunately, ST doesn’t have a Mac friendly package. You will see that it’s a Windows “.exe” that install it under Program Files/STMicroelectronics directory.
- But you’re lucky. I’ve already unpack it and share over my dropbox account. Click here and unpack it on your CrossWorks projects directory.
CrossWorks project creation steps
- Creating a new STM32 project:
- Select menu “File“, then “New Project” menu item.
- Select the “STMicroelectronics” from the Categories list.
- Select the executable for STMicroelectronics STM32 from the Templates list.
- Enter the name of your project: AN3413-Current_consumption_touch_sensing
- Enter the location of your project. Create a new folder under “STM32L_Discovery_Firmware_Pack_V1.0.2/Projects/AN3413-Current_consumption_touch_sensing/CrossWorks/“
- Select the Target Processor as STM32L152RB. You can finish it from here.
- Next. Uncheck “main.c” (you don’t need that auto-generated file)
- Include Preprocessor Definitions
- Select menu “Project“, then “Properties…” menu item. The Project Manager window appears.
- Select View: Properties, Properties: All, Grouping: Categorize, Configuration: Common
- Navigating on “Settings:” and find “Preprocessor Options“
- In “Preprocessor Definitions“, include the following:
- Don’t close Project Manager window, yet.
- The “User Include Directories” uses project directory in path reference. Now we are going to include the various library include paths (.h):
- In “User Include Directories”, include the following:
- $(TargetsDir)/CMSIS_3/CMSIS/Include (necessary after after STM32 Support Package 2.14, see release notes)
- In “User Include Directories”, include the following:
- Go to Project Explorer to add the project source files (.c):
- Expand the Project
- Tap with two fingers in “Source Files”, chose “Add Existing file…”
- Add the files:
- Create a “Utilities” folder under Project ‘AN3413-Current_consumption_touch_sensing’ (Tap with two fingers and “New folder…”)
- Make it a Dynamic folder (Tap with two fingers on “Utilities” folder, then “Dynamic folder…”)
- In Directory, use “../../../Utilities/STM32L-DISCOVERY” (or navigate and find it on you STM32L_Discovery_Firmware_Pack_V1.0.2 folder)
- Create a “STM32L1xx_StdPeriph_Driver” folder, make it Dynamic, point it to “../../../Libraries/STM32L1xx_StdPeriph_Driver/src/“
- Create a “STM32_TouchSensing_Driver” folder, make it Dynamic, point it to “../../../Libraries/STM32_TouchSensing_Driver/src/“
- Your project Items need to look like this (“System Files” folder is automatically added):
At this point we can build that solution. Click on “Build” menu, then “Build AN3413-Current…” . You’ll see a little devil error like that:
Well, one fix at time. Let’s start with the message:
– THUMB Debug/AN3413-Current_consumption_touch_sensing.elf section `.DataFlash’ will not fit in region `UNPLACED_SECTIONS’
— region `UNPLACED_SECTIONS’ overflowed by 2 bytes
There’s nothing about “UNPLACED_SECTIONS” under CrossWorks for ARM Reference manual, so I’ve been opened a trouble ticket for CrossWorks support team. They are very smart and always catch what you need (if you provide them all the details).
According to support, the variable is being placed in a “.DataFlash” section which needs to be allocated into the EEPROM segment. “UNPLACED_SECTIONS” exists to catch errors when sections haven’t been placed. (Thank’s Michael Johnson from Rowley!).
And, if you look at Symbol Browser (“Tools” menu) you’ll find the “.DataFlash” 2 bytes section on the range:
Reading STM32L152RB datasheet, in the memory map section it confirms it’s the EEPROM region, so they are right. But that ugly name “.DataFlash” makes me believe that it’s Flash Memory related. Bad name, bad name…
They told me how to initialize it:
- Tap two fingers in Project ‘AN3413-Current_consumption_touch_sensing’ and select “Import Section Placement” to get a project local copy of the section placement file “flash_placement.xml“.
- Tap two fingers on file “flash_placement.xml” and select “Open With” then “Code Editor“.
Add a new segment:
<MemorySegment name="EEPROM" > <ProgramSection alignment="4" load="No" name=".DataFlash" /> </MemorySegment>
After that, your file looks like that:
Let’s work on the rest errors:
– THUMB Debug/stm32l15x_tsl_ct_acquisition.o: In function `TSL_IO_Acquisition_P1′:
— undefined reference to `__TSL_wait_CLWHTA’
— undefined reference to `__TSL_wait_CLWLTA’
A double click in that lines let you go to “stm32l15x_tsl_ct_acquisition.c” source file, from STM32_TouchSensing_Driver. Let’s do a search on it, looking for “__TSL_wait_CLWHTA“, and you’ll find the follow piece of code:
So, your problem is here: “__INLINE” isn’t supported by CrossWorks. Remove only the “__INLINE” and repeat it for “__TSL_wait_CLWLTA” function. Now, Clean and Rebuild the entire solution. That’s it! Compile Ok!
Running it on board!
Connect the STM32L-DISCOVERY board to your Mac.
- Select “Target“, “Connect…“, then select ST/LINK-V2;
- In Properties Window, select “Target Interface Type: SWD“;
- Target, Download it to board and see… it’s works!
If you want my entire project files, you download it on my downloads page. Unpack it under your CrossWorks project directory. These files contains all my entire folder.
Next post I’ll show how to compiling the other example, AN3964-Temperature_sensor.
Well, I can’t finish the PCB for this project yet (I’m planning make it with a Transformerless Power Supply), but I’m posting the Microchip C18 code for all that want work with this protocol.
Please, visit my download page.
The of the year is coming, and a lot of ideas bring to my head. During this year I change my work line from Microchip PIC 18F Family MCUs (like PIC18LF2520, PIC18LF2620 and PIC18LF14K50) to PIC24F Family (PIC24FJ32GA002, PIC24FJ64GA002, PIC24FJ256GB106). It’s a lot easer work on 16bit cores. My list of benefits:
- More portable code;
- Better code optimization;
- Free compiler, without restrictions;
- PIC24F Family is pin compatible with other family devices, so if you need more flash only you need is change the MCU;
2010 was the year of Arduino for most hobbyists. I’ve to confess that I don’t like much Arduino, but I’ve some Arduino’s and some shields too. I don’t understand very well what happens, but I’m not very comfortably with libraries. I think that is because Arduino try to be “much” friendly to non-electronic people. That’s “friendly” you can see on libraries: SD card access, OLED access, RFID access, all stuf very very very easy and directly, but don’t made by you. I don’t like to “rediscover the wheel”, but I like some control about what happen.
But even with this opinion, I’ve a project with Arduino for next year.
In this week I receive a lot of new devices, like:
- new OLEDs (SSD1339 controller, very smart, with graphic accelerated functions);
- new TFT LCDs (SSD1289 controller, not so smart);
- new 16bits MCUs (PIC24HJ64GP502, PIC24HJ128GP502 and PIC24FJ64GA102);
- new 32bits MCUS (ARM STM32);
I’ve doing great goals in this projects, but all of them still very young yet. But see the photos above and conclude that they are very nice:
For who need SH1101A OLED driver, I’m posting here my code (written in Microchip C18, but easly to port to other platform) to help more people on get use this great OLED display. It’s not finished, yet, but it’s very useful.
The code has geometric draw functions to draw single pixel, lines, rectangles and circles with fill option. There’s characters output functions too, with 8×6 pixel font.
The icons for Battery (animated), Bluetooth, WiFi, Sound (animated), etc are on the code too.
Some example of available functions are:
- SetPixel(), GetPixel();
- Character output functions, PutROMString(), PutString();
In the code you’ll find a DS18B20 Dallas OneWire Digital Temperature sensor driver too. That’s a limited version (only work for one sensor in OneWire bus) but works great. You get a float reading plus a string with temperature value (in Celsius Degrees). More improvements coming soon.
Well, let’s go to download link:
If you have any trouble with that code, email-me or let me a comment.
Some people ask me about how to do hand soldering on smaller parts, like on my OLED Display Board. It uses a “TAB” (tape automated bonding) or “COF” (chip on flex) style flex tail mated with a “COG” (chip on glass) display. Normally, TAB connector is soldered directly to corresponding pads on your PCB using a hot-bar soldering machine.
I don’t have that hot-bar soldering machine, so my hand’s can make the job. The first time I’ve done this soldering, I was a bit scare about damage the connector. My only tip is “don’t spend much time over the fragile contacts.”
For help us, I’ve recorded my last OLED soldering. Maybe can help some people about SMD soldering (as some internet videos help me some years ago).
Someone send to me a question, about how much current my OLED board consumes at all. Well, after measure with a multimeter the answer is: 660μA (aprox.) with display all ON and contrast at 0xFF (max). But this question make me thinking about how measure that current myself, without a multimeter.
When I’m in graduation (some good years ago) I made a little circuit to measure how much current my power supply project output. The circuit is based on “high-side current-sense” methodology. See my hand-drawn circuit above:
This circuit is a classic high-side current-sense, where the voltage drop across Rs resistor is isolated by a operational amplifier (op amp) in a differential configuration with unitary gain. The many implementations of technic were based on discrete components or semidiscrete circuitry. In their simplest form, such high-side monitors require a precision op amp and a handful of high precision resistors.
The resistor value should be low (like mΩ scale), to minimize power losses, but don’t be too low, because stability problems. And don’t forget about power dissipation across the resistor.
One common approach for high-side measurements has been the use of the classic differential amplifier, which is employed as a gain amplifier.
So, after reading a lot of theory, I’ve going to search my integrated differential amplifier.
Integrated Differential Amplifier
- Tiny SOT23-5 package;
- Low cost;
- 3 gain options (20V/V, 50V/V and 100V/V);
- +2.7V to 28V range of operation;
- Consumes only 30μA;
- 0.18% full-scale accuracy with 100mV Vsense input (This is equivalent to only 0.18mV input offset voltage);
The MAX4372, in a tiny SOT23-5 package is a very good device to make a current sense device. You can set the full-scale current reading by choosing the device:
- MAX4372T: 20V/V Gain;
- MAX4372F: 50V/V Gain;
- MAX4372H: 100V/V Gain;
What means 20V/V Gain? If you have 1A current flow through a 100mΩ Rs resistor, you gave only 0.1V drop. But with 20V/V, you multiply this and obtain 2V. Obviously? The design goal with Gain is thinking in terms of full scale design. If your A/D converter uses 3.3V was reference, you can consider this to check what the max current value you can measure with determined gain value.
A test circuit
I’ve designed a test circuit to test my idea. Basically is a MAX4372T with a 100mΩ Rs. I’ve mounted it in universal board, and my idea is connect it to my USB Low Pin Kit:
To test them, I’ve used a PIC18LF2520 and a great character LCD from Electronic Assembly. See my test circuit working:
The pictures show that the global idea works great. Now I need some work to improve stability and other features.
The next step is create a USB device for read, store and show the current measurements:
Some mounts ago I’ve bought a PIC24F Starter Kit. It’s a very nice development kit from Microchip for who wants know about USB OTG, Capacitive Touch Sensor and more. But I really like is the OLED display it comes.
The OLED is very small but with a good resolution (128×64 pixel). It’s monochrome black and white and, believe or not, very bright but without backlight! Well, I’m very impressed and obviously imagine what I can do if I have a small OLED like that.
So I’ve started to find the manufacture of OLED. I find some information at Microchip driver code and with some Google research:
- It’s use a Sino Wealth SH1101A controller;
- Parallel or SPI interface. Very nice feature for a display;
- The controller logics operates with 2.4V – 3.5V, but OLED requires 7.0V – 16V. It’s have a internal simple DC/DC Booster for that;
- The display is constructed with COG (Chip-On-Glass) technology;
- There’s a version where 128×16 pixels being yellow OLED, and 128×48 pixels as blue OLED;
- Crystalfontz sells this Yellow/Blue with code CFAL12864N-A-B1;
- Univision has the Black/White and Yellow/Blue version;
After that, I’ve started design a board to this OLED. Oh, if you don’t know what OLED means visit Wikipedia page. My design concentrates in a breadboard friendly board. The circuit is little variation of the circuit founded in Microchip PIC24F Starter Kit schematics. I’ve substituted some components for more flat and foundable items. Basically I change the inductor, the N-Channel MOSFET and the diode. You can see the design bellow:
- 0.1″ pin space and breadboard friendly;
- It comes with SPI interface preseted. If you want use 8080 parallel interface, simply pull-up “P/S” pin;
- Very flat design with only SMD parts;
- Clear pin identification;
- Small size (don’t increase OLED size too much);
- Can be hand soldered (whitout hot-bar or even hot-air station);
That’s my board finished:
I really like this board because it’s work at first time, and it’s not so common in electronics word with your first board design. After some tests, I’ve learning some useful information about the OLED displays in general:
Most of OLED displays have SPI interface. But most of them don’t let you read the display RAM data with SPI interface, because it’s a SPI 3-Wire interface. When you cannot read display RAM, should be impossible make functions that read display RAM and alter only one pixel (for example). So, some simple functions (like line creation) became very complex if you like to use it without modify some graphics already displayed. Example: if you have a picture and draw a line, you will change some blocks of RAM, don’t only the line pixels. I’m working on that problem.
If you like this board, email-me at firstname.lastname@example.org. I’ve five empty boards and five OLED yet.