Monday, April 14, 2014

LPC812 RC5 IR Remote Control Codec

 
 
Since LPC812MiniKit is application oriented, we will publish a series of applications available now. 
  
LPC812 has an advanced peripheral SCT, which is suitable for timing related algorithm. NXP has offered comprehensive application notes and demo codes for SCT in LPC812. 

Although SCT in LPC812 has only two state variables, its counterpart in LPC18XX/43XX has much more variables. It is still very handy for most simple timing applications, such as infrared remote control used in consumer electronics.

You can donwload cookbook of LPC812 SCT from LPCware.com. There are serveral demo projects for Keil inside the zip file, which has rc5_send and rc5_receive.

RC5 is widely used in many devices from Philips electronics, including TV, DVD, lighting and others. Philips has introduces RC6 standard to replace it, but RC5 is still popular.

Labs on LPC812 Mini Kit

The rc5_send and rc5_receive are straigh forward. You can test them on LPC812MiniKit easily.

RC5_RECEIVE Lab Setup

 
 
 
 
You can use LPC812MiniKit with following configuration:

  • Main clock and PLL sources from IRC 12MHz
  • SCT is used for decoding with interrupt
  • Connects LPC812MiniKit to PC via USB, which RX/TX connects to P0_0/P0_4
  • Connects P0_7 to an used infrared decode module from TV set

You can use any Philips remote to send command, and check the result from termianl software 
The footprint of this project is 1920KB ROM and 536B RAM. So it can be programmed into the smallest LPC810, which has 6 I/O, 4KROM and 1KRAM.

RC5_SEND Lab Setup

 
 
Since LPC812 can drive LED directly, so the configuration for RC5_Send is even simpler:

  • Main clock and PLL sources from IRC 12MHz
  • SCT is used for encoding with interrupt
  • Connects infraread LED to P0_7/VSS. (no transistor is required)
  • Connects P0_1 to GND as user button. (you can use push button or wire)

The code can only transmit a fix code. I am going to use UART to transmit user defined command.

Migrate to Univeral Remote Control

Obviously, RC5 is only our starting point, not our target. I will try to build an universal remote control codec based upon open source projects which has different algorithms.

However, when I tested the Arduino library, I found many decoding error. Either the hardware has interferences, or the algorithm has to be fine tuned.

Firmata for LPC812 is available now


 
 

pyFirmata and Firmata for LPC812

As mentioned in previous blog, I ported Firmata from Arduino to my LPC812MiniKit in order to instantiate MCU on board. 


I used pyFirmata as the starting point for my demo testing code. And it can be used a baseline for future desktop applications in Windows/Linux/OSX.

 

In microcontroller side, Firmata for LPC812's footprint is 9KB ROM and 1KB RAM, including serial driver, ring buffer management, printf, system timers, SCT, PWM and firmata protocol parsers.

 

Quick testing for analog channels

I have learnt a testing trick from Sparkfun, print analog bar in console. By this way, we can quick check analog channels such as PWM, ADC, DAC or sensor raw data. It works like a osilloscope, excepts vertial scanning.

 

SCT PWM library

During my development, I found some problemes and bugs. Among them, SCT based PWM takes longer time than my expectation. I have to say, NXP's SCT is a great and flexible pheripheral. And they have offered related tutorials and source code. However, they still have to do more. Otherwise, the great part will only popular in fans. They must make a library for SCT, or PWM on SCT. As least a PWM sweep demo. I know different applications demand different restrictions for PWM, including pulse frequencies, ration, dead zone, phases relationship. But please make it as a library, including source code.


SCT is great, is flexiable, can do this, do that. Do with my SCT drawing tool. We still need user friendly libraries, configured for popular 4xPWM, 2xPWM, RC5 codec, LED drivers. Yes, please do it. NXP.


Actually I ported mbed SCT/PWM library back to Keil's C library. It drives up to 4 channels PWM on 1KHz, which is good enough for LED strip and quad UAV.

 

It is a pity that LPC812 has no on board ADC. Although we can have external I2C/SPI ADC/DAC or using sensors with bus interface. SCT+COMP can made up a slow delta-sigma ADC, but if we need a decent ADC, we have to use LPC1114 or STM32F030.


After testing firmata firmware in LPC812 as well as pyFirmata application in desktop, now we can move to Android platform. Here we come. Keep tuned.

Firmata, a legacy protocol demands more patches

 
 


During my development of Firmata for LPC812MiniKit, I found a serious issue. The current Firmata protocol only supports up to 16 channels of PWM/ADC

 

Cause

Since Firmata originates from the legacy MIDI protocol. It heritates many things from last century (too old). 


The MIDI devices have common features. For example, the musical keyboard has many keys and a few analog control, including volume, pitch. As a result, MIDI protocol defines up to 128 channels digital I/O and up to 16 channels analog I/O.  On the other hand, MIDI is kind of ASCII protocol. It reserved MSB as command, all 8bit value has to be split into two byte, one byte carries 7bit, the other carries 1 bit. That's stupid ever.

 

When Firmata was designed for Arduino, it follows MIDI. So we can believe the designer should have background of music. Here comes the bottleneck. Although in morden microcontrollers, analog channels are still limited against to digital pins.  Usually we can find 4/6/8 PWM/ADC on chip. But they can mapped to any digital pins. For example, D17 may share PWM0 in same pin. Of course we can defined analog pins in different domains, but an extra translation/abstraction layer may be very confused.


Solution 

In order to solve this issue, Firmata offers various solutions. The most simplest way is using SysEx command. 


My setup for testing is Firmata on LPC812 and pyFirmata running on Windows. I changed my code in both sides to met that changes. Basically I dropped the original analog message, replace with SysEx command for all analog write.


I haven't implemented and tested the analog read, since LPC812 has no ADC on board.

Sunday, April 13, 2014

Python Firmata libraries


 
 

In order to abstract the hardware with Firmata, I must build up a test loop. First I will use a mature desktop firmata host application to test the firmware, then using the tested firmware to speed up the development for Android class libraries and APK.


I am used to use Python to setup a rapid application to test the LPC812MiniKit. Simplest approach ever.

 

Firmata for Python

 

There are two Python libraies available for Firmata applications:


 

By manually inspecting the source code, I found pyduino is older than pyfirmata. pyduino's main file pyduino.py is only 10KB, the latest update timestamp is 2009. The coding style is quite close to mine, who has background of embedded systems like microcontroller firmware development.

 

On the other hand, pyFirmata is more complete and up to date, the latest update is taken in 2013. pyFirmata also has more advanced software skills including test suite. Additionally, it allows custom boards to be added to the project. Since LPC812MiniKit can be configured as multiple profiles, pyFirmata is much suitable for our cases.

 

Both libraries defined Arduino class. I refer to pyFirmata implementation to define GAPmini class or LPC812 class. Although Firmata was defined for Arduino, I want a seperate class namte to identify different platforms.

 

pyFirmata

 

I added some board profiles in boards.py and __init__.py files, including LPC812Min/LPC812Max/LPC812MixMin.

 

Thanks Tino (the author of pyFirmata from Dutch) for its contributions and orientations for demo Python scripts.

 

LPC812_Firmata_Blink.py (Basic test):

 

from pyfirmata import LPC812Min, util
from pyfirmata import BOARDS
import time

print '>>>> 5 second delay for firmata initial'
print '>>>> Press reset to go'
board = LPC812Min('COM27', baudrate=115200)
print '>>>>',str(board)

board.sp.setDTR(1) # set LOW
time.sleep(0.1)
board.sp.setDTR(0) # set HIGH, LOW to High to reset

layout = BOARDS['lpc812_min']
print ">>>> Board layout"
print str(layout)
board.setup_layout(layout)
(major,minor) = board.get_firmata_version()
print ">>>> Version: %d.%d"%(major,minor)
print ">>>> Firmware name: %s"%(board.firmware)

pin17 = board.get_pin('d:17:o')

while True:
    try:
        pin17.write(1)
        board.pass_time(2)
        pin17.write(0)
        board.pass_time(2)
       
    except KeyboardInterrupt:
        print ">>>> User interrupt."

board.exit()
print 'Exit it.'

 

The basic Firmata has been tested and some modifications have been made. I will propose a pull request to Tino to merge the changes in pyFirmata.

 

UPDATE

Now I have offered more demos for LPC812MiniKit, including Digital In (as keypad), Digital Out (as LED blink), Fade (as LED fade in fade out). 


Since PWM is implemented by SCT (State Configurated Timer) in LPC812, now we can have 4 PWM assigned to any digital pins to drive multiple LEDs or a quad UAV.


In LPC812, we can only have 4bit ADC by comparator, or 10bit slow sigma-delta ADC with SCT/Comp, or external I2C ADC. If I release LPC1114 mini board for Firmata, we can have ADC as analog input.


Friday, March 21, 2014

General Android Peripheral (KL25Z) tested

 
 
Last year I started to develop a General Android Peripheral platform with Freescale's first Kinetis L micro MKL25Z128VLK4.  When I present it on Design Shanghai 2013, its hardware is under development, which you can reveal on above picture.

History
It was inspirited from IOIO design and ADK for its ADB/ADK/AOA conception. However, since MKL25Z is quite different from Microchip and Atmel's micro, I developed the code on FSL's USB stack, and reference some code from Arduino UHS (USB host shield).

Roadblock
As a software engineer, the roadblock for this project is hardware design and assembly. 

The code runs well on FRDM-KL25Z with my custom host port. (Yep, I modified the port hardware to enable its host feature on board.) However, I can not solder the samples since 0.5mm pitch QFP80 is difficult to me.

I got them soldered with my friends, but all of these boards can not be accessed by any of my debuggers. And I found 125 KHz output from its reset pin. Check these two links for details.


After visiting Freescale Shanghai office and digging with search engine, I found a solution, which adding an extra series resistor to SWD_CLK pin. Now, three boards are working now. 

Here comes the Star for this blog!
 
 


Looks ugly? Yes, it is manually soldered by my friend (for MCU) and me (for rest).

However, I have to revise my hardware, since they are not good enough for public and hobbyists. I wrote this because I want someone who might be interested to know its planned features.

Features Planned
  • ADB (USB host on MCU, available now for firmware and demo)
  • ADK (USB host on MCU, not available)
  • CDC (USB host on Android, firmware done, host driver in development)
  • CDC (USB host on Android, via CP2102, as same as my LPC812MiniKit)
  • Audio Jack (ADC/DAC/GPIO on MCU for FSK modem)
  • Bluetooth 2.0 module (tested on LPC812MiniKit)

Feedbacks are welcome
Although I wrote blog via email, you can still reach me by email. (allankliu#ymail.com). It is painful to be isolated from my friends worldwide.

You can support my development by visiting my web shop on http://www.aliexpress.com/store/1149436

Up to now only LPC812MiniKit is available, which is also Android oriented design. I will put more items on, including GAP (KL25Z) and open source debugger SDA+ as soon as I get back the hardware.

All items are open source. 

Sunday, March 16, 2014

LPC812MiniKit is available worldwide

Web Store

LPC812MiniKit is available from my web store of http://www.aliexpress.com/store/1149436.

Currently there are three major products for DIYer:

 
 

LPC812MiniKit, on board CP2102, SWD/ISP, connects to PC/Android/Linux/Mac

 
 

Bare PCB for LPC812, it is easy to solder LPC812M101JD20 (SO20) on board

 
 

SWD/JTAG 50/100mil, 1.27/2.54mm converter (only 10 pieces available)

Additional Items
You can order samples for LPC1114/LPC812/STM32030 from my store as well.

Another LPC812 Image

Now maybe we can embedded image into email body?

 
 
Check our LPC812MiniKit in detail.