Wednesday, January 29, 2014

Inside a WorldSpace satellite radio receiver

WorldSpace is no longer operational. But I had a receiver lying around from when it was active. I opened it up and here is what I found in it:

Antenna Unit

Front Panel

Inside of the front panel

Main Board

Mainboard with the various sections marked out

STA001 – RF Frontend for Digital Radio
  • Single chip receiver for satellite digital transmission
  • Superheterodyne receiver with IF output
  • High input intercept point, low Mixer noise
  • 54db IF VGA gain range
  • Adjustable RF gain
  • Adjustable IF gain 
  • Integrated RF VCO
  • Integrated IF VCO
  • Integrated synthesizer
  • I2C bus compatible programming Interface
  • Unregulated 2.7 volts to 3.3 volts voltage Supply
  • Low cost external components
Block Diagram of STA001 – RF Frontend for Digital Radio

STA002 – Starman Channel Decoder
  • Front end interface
    • IF input carrier frequency: f = 1.84 MHz
    • Single internal 6 bit A/D converter
    • QPSK demodulation
    • Input symbol frequency: Fs = 1.84 Msymbols/s
    • Digital Nyquist root filter:
      • Roll-off value of 0.4
    • Digital carrier loop:
      • On-chip quadrature demodulator and tracking loop
    • lock detector
    • C/N indicator
    • Digital timing recovery:
      • Internal timing error evaluation, filter and correction
    • Digital AGC:
      • Internal signal power estimation and filter
      • Output control signal for AGC (1 bit PWM)
  • Forward error correction
    • Inner decoder
      • Viterbi soft decoder for convolutional codes, constraint length M=7, Rate 1/2
    • Deinterleaver block
    • Outer decoder
      • Reed-Solomon decoder for 32 parity bytes; correction of up to 16 byte errors
      • Block lengths: 255
      • Energy dispersal descrambler
  • Back end Interface
    • Broadcast Channel selection
    • Audio Service Component selection to MPEG decoder
    • Service Component selection
  • Control
    • I2C serial Bus control interface
  • Decryption
    • WES Scheme
Block Diagram of STA002 – Starman Channel Decoder


STA003T – MPEG 2.5 Layer III Audio Decoder
  • Single chip MPEG2 layer 3 decoder
  • Supporting
    •  All features specified for Layer III in ISO/IEC 11172-3 (MPEG 1 Audio) except 44.1KHz Audio
    • All features specified for Layer III 2 channels in ISO/IEC13818-3.2 (MPEG 2 Audio) except 22.05KHz Audio
    • Lower sampling frequencies syntax extension, (not specified by ISO) called MPEG 2.5 except 11.025KHz Audio
  • Decodes layer III stereo channels, dual channel, single channel (mono)
  • Supporting the MPEG 1 & 2 sampling frequencies and the extension to MPEG 2.5:
    48, 32, 24, 16, 12, 8 kHz
  • Accepts MPEG 2.5 layer III elementary compressed bitstream with data rate from 8 kbit/s up to 128 kbit/s
  • Digital volume control
  • Digital bass & treble control
  • Serial bitstream input interface
  • Ancillary data extraction via I2C interface.
  • Serial PCM output interface (I2S and other formats)
  • PLL for internal clock and for output PCM clock generation
  • Low power data elaboration for power consumption optimisation
  • CRC check and synchronisation error detection with software indicators
  • I2C control bus
  • Low power 3.3 volts CMOS technology
  • 14.72 MHz external input clock or built-in crystal oscillator
    Block Diagram of STA003T – MPEG 2.5 Layer III Audio Decoder

PT6524 – LCD Driver IC
  • CMOS Technology 
  • Up to 4 Common and 51 Segment Drivers 
  • Up to 204 LCD Segments 
  • Up to 12 General Purpose Output Ports 
  • 1/4 Duty – 1/2 Bias or 1/4 Duty – 1/3 Bias Drive Technique 
  • No Decoder Intervention Necessary to Display the Data 
  • Power Saving Mode provided 
  • RC Oscillation Circuit
Block Diagram of PT6524 – LCD Driver IC


ST72F321 – Microcontroller
  • Memories
    • 32K to 60K dual voltage High Density Flash (HDFlash) or ROM with read-out protection capability. In-Application Programming and In-Circuit Programming for HDFlash devices
    • 1K to 2K RAM
    • HDFlash endurance: 100 cycles, data retention: 20 years at 55°C
  • Clock, Reset And Supply Management
    • Enhanced low voltage supervisor (LVD) for main supply and auxiliary voltage detector (AVD) with interrupt capability
    • Clock sources: crystal/ceramic resonator oscillators, internal RC oscillator, clock security system and bypass for external clock
    • PLL for 2x frequency multiplication
    • Four Power Saving Modes: Halt, Active-Halt, Wait and Slow
  • Interrupt Management
    • Nested interrupt controller
    • 14 interrupt vectors plus TRAP and RESET
    • Top Level Interrupt (TLI) pin on 64-pin devices
    • 15 external interrupt lines (on 4 vectors)
  • Up to 48 I/O Ports
    • 48/32 multifunctional bidirectional I/O lines
    • 34/22 alternate function lines
    • 16/12 high sink outputs
  • 5 Timers
    • Main Clock Controller with: Real time base,
    • Beep and Clock-out capabilities
    • Configurable watchdog timer
    • Two 16-bit timers with: 2 input captures, 2 output compares, external clock input on one timer,  PWM and pulse generator modes
    • 8-bit PWM Auto-reload timer with: 2 input captures, 4 PWM outputs, output compare and time base interrupt, external clock with event detector
  • 3 Communications Interfaces
    • SPI synchronous serial interface
    • SCI asynchronous serial interface 
    • I2C multimaster interface
  • 1 Analog peripherals
    • 10-bit ADC with up to 16 input ports
  • Instruction Set
    • 8-bit Data Manipulation
    • 63 Basic Instructions
    • 17 main Addressing Modes
    • 8 x 8 Unsigned Multiply Instruction
  • Development Tools
    • Full hardware/software development package
    • In-Circuit Testing capability
Block Diagram of ST72F321 - Microcontroller

Monday, January 27, 2014

Automating web login using OpenWRT

If you are plagued by having to put up with an Internet Service Provider that insists that you login through their webpage everyday before you use the internet, then read on for an solution.

I use Reliance Broadband in Mumbai, India. Whenever you try to use the internet,you need to first login through their portal page - no matter what URL you type, you will be first redirected to their login webpage where you type in your username and password before you can begin surfing the internet. Even Windows will complain with a "Additional log on information may be required" popup. Also Reliance insists that you login again 24 hours later. To overcome this PITA, I flashed my Linksys router with DD-WRT and added a startup command to login automatically. That method wasn't as effective as I desired. Its described here.

Reliance Broadband's Web Login

I thought of writing a script and adding it as a cron job to DD-WRT. The script would ping a known good server like www.google.com regularly and if the ping failed, it would login by passing the username and password via URL using wget. This was a good idea, I wrote up the script and tested it successfully on my xubuntu netbook but it didn't work on my Linksys WRT320N running DD-WRT. This was probably because cron seems to be broken on DD-WRT and I did not feel like spending time figuring our how to fix it.

Instead I switched to using a TP-LINK router, flashed it with OpenWRT (which is much easier to manipulated than DD-WRT), copied the script to it and added it to crontab for execution on every minute.

Here are the steps:

  1. Get a TP-LINK router (TP-LINK routers agree well with OpenWRT) and flash it with OpenWRT. To know how to get that done, refer to ONLY the steps outlined under the heading "Flashing the router with OpenWRT" in the post here.
  2. Create a text file on your computer and copy the following lines to it. Save it as login.sh If you are using a Windows PC, make sure to take care of Line Endings. Also, replace "1234567890" with your own username and "reset123" with your own password.
  3.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    # Send two Ping request packets and 4 seconds timeout
    return_value=$(ping -c 2 -W 4 www.google.com)
    return_value=$?
    # Return code for ping are taken from
    # ./OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/include/sysexits.h
     
        case $return_value in
            0)  #Ping reply received
                logger "Ping result: ONLINE"
                ;;
            1)  #Ping sent but reply was not received
                logger "Ping result: OFFLINE (Ping reply not received), Logging into Reliance..."
                wget 'http://reliancebroadband.co.in/reliance/startportal_isg.do?userId=12345678790&password=reset123&action=doLoginSubmit' -O /dev/null
                ;;
            *)  #Error
                logger "Ping result: OFFLINE (ping return code: $return_value), Logging into Reliance..."
                wget 'http://reliancebroadband.co.in/reliance/startportal_isg.do?userId=12345678790&password=reset123&action=doLoginSubmit' -O /dev/null
                ;;
        esac
    
  4. Copy the file login.sh to /root on the router. On a Windows PC, use WinSCP to do this. On a Linux PC use the command scp login.sh root@10.10.10.10:/root/login.sh to copy the file to the router, replacing 10.10.10.10 with the IP address of your router - Linux will as you for the router password before copying the file.
  5. Access the router's OpenWRT Web GUI and navigate to System>Scheduled Tasks and add the line * * * * * /root/login.sh to the text box. Click Apply and reboot the router.

    Adding the script as a cron job to crontab in OpenWRT
Once rebooted, the router will execute the script every 60 seconds. The script will check for connectivity and login if required. You can look up the System Log of the router to make sure the script is running.

System Log shows that the script is being run every minute successfully

Thursday, January 23, 2014

Using TL-MR3020 as an IoT Node instead of Arduino Yún

After putting up my home weather station (blog post here) using TL-MR3020, I spend some time thinking if I could continue using this pocket router for future projects, here are my thoughts:

In India an Arduino Yún (INR 5903 from rhydoLABZ). But if instead of that if you go for the combination:
TL-MR3020 Pocket Router (INR 1395 from flipkart)
+ Portronics Combo USB and Card Reader (INR 299 from Portronics)
+ SanDisk Cruzer Blade 8 GB Pen Drive (INR 304 from flipkart)
+ Arduino Micro (INR 1820 from rhydoLABZ)
Total come would come to INR 3818 which is 35% cheaper than the Yún.
The combination can do everything the Yún can do and much more:

  • Linux Processor: TL-MR3020 has the same CPU (Atheros AR9331) as Yún and runs the same OS OpenWRT
  • Microcontroller: Arduino Yún has ATmega32u4 on it, same as the one on Arduino Micro
  • SD Card Reader: TL-MR3020 can use the one on the Portronics hub
  • WiFi & Ethernet: Both have that
  • Power Supply: TL-MR3020 comes with a travel charger, Arduino Yún doesn't come with a power supply.
  • USB Host Port: Since the combination has a USB hub, you get two more ports as compared to just the Yún.
  • Flash memory available to OpenWRT: Even though Yún has 16MB of flash whereas MR3020 has only 4MB, but if you mount the rootfs on the USB flash drive, you get to access whooping 8GB worth of memory
  • RAM available to OpenWRT: Yún has 64MB, MR3020 has only 32MB - not a biggie when it comes to running lightweight applications.
Another idea: use FT230X to bit bang.
Use a TL-MR3020 router (INR 1395) with FT230X to interface directly to DHT11 using bitbanging mode.

  1. DHT11 (INR 300) is a cheaper athough less accurate alternative to using SHT11.
  2. FT230X is a newer more inexpensive (more than 1 USD cheaper) variant for FT232RL with a few less RS232 handshake pins, which should be okay for our purposes - we only need a single big banged pin to interface to DHT11.
  3. If we write the code in C and use libFTDI (which is also available for OpenWRT/MIPS), then we will definitely be able to fit the application executable in the 820KB of flash which is available on TL-MR3020 after freshly installing OpenWRT on it - we won't need a USB hub and USB flash drive for expanding the storage space.

I think this can result in a temperature+humidity station for about INR2000


Tuesday, January 14, 2014

Your electronics project: Keeping it together!

Developers working embedded systems have a perpetual woe - they end up wasting a lot of time debugging avoidable hardware issues like loose connections, broken wire, ESD during dry winters, broken pins etc.

Much of the damage is caused because of the perpetual mess our desktop is in - in shuffle around to reach to one thing, you might end up messing something else. Even if you unclutter your table top, there is always a very real chance of your circuit board or power supply adapters or extension boards falling off of it thereby causing loss of multiple days of productivity. And no matter how careful you are, your colleagues might not be as careful as you or worse still, the house keeping staff might disturb your setup during the cleaning hours when you are away . The cleaning staff man handling your equipment (TWHS! hehe) is a very real problem in India. At one of my ex-workplaces, we were out weirded when an unusually high number of keyboards started turning up bad. It seems that the house keeping staff used to upturn the keyboard and bang them on the desk to get rid of the keyboard dandruff!!

During my time at Greenvity, we occupied cabins at Pune IT Park, Bopodi, Pune. Thankfully the staff here is very well behaved and sensible. We never had any issues with our equipment being mishandled in our absence. Although, once, a member of the house keeping team did eat the biryani which we had kept in the fridge, but that's another story - he had thought it belong to one of his colleagues! 

So how can we avoid such issues?
A sturdy platform to hold all the circuit boards together along with extension boards, battery, power supply and other paraphernalia would be awesome. During my time at Laresen & Toubro, we ended up spoiling a lot of circuits and components just by transporting them between our desks - different bugs assigned to different people - different people wanted to use the prototypes at different times of the day at different desks.

At LARE when I conceptualizing UNIBlocks, I thought of board which had regularly spaced holes in it. We could mount various PCBs on it and assemble our prototype during our embedded software development phase. The result was the grid base board. Look here for some of the pictures of how we used that for assembling projects using UNIBlocks. (I got the idea from the red metal base that come supplied as part of the Mechanix kits)

Since then I haven't let go of the concept and have continued using the same for many of my prototype assemblies since then. Here are some of them:


This is an IoT/M2M project. You can see the power supply (230VAC to 12VDC) mounted on the baseboard. The sealed led acid battery is mounted in the center using cable ties. I used blu-tack to insulated the battery and power supply terminals.
The iMX233-OLinuXino-MAXI would easily accept the 12VDC power but, since I had a 3G Dongle attached to it, I had to use a separate 12VDC to 5VDC voltage regulator (shiny metal cuboid mounted using cable ties) to power the dongle. The tiny blue component is the DHT11 Temperature/Humidity sensor. This assembly is meant to upload temperature and humidity readings regularly to a cloud service.


This project is similar to the previous one. This one has a Raspberry Pi mounted on the baseboard. The board installed on top of RPi is AirPi - it has sensors for monitoring air quality. In this project I use a TL-MR3020 pocket router to provide internet connectivity to RPi using a Vodafone 3G dongle.

The base boards are made of 2.0 mm thick FR-4 material. This is the same material which is copper clad on both sides and serves as the raw material for Printed Circuit Boards. The Mechanix kits, the holes are 5/32" and are spaced half inch apart. While designing PCBs, I make sure that the mounting holes on those PCBs match the grid on these baseboards. I would then use metal standoffs to mount the PCBs on to the baseboard. If I have to use a third party component or PCB, I use nylon cable ties to bind them to the PCBs. Once everything was assembled, I would stick rubber feet below the basebaord for support. Jumper cables like the ones available from Rhydolabz (M-F, F-F, M-M) help in making connections between PCBs.

Here are photos of a few more projects:


Development setup  for iMX233-OLinuXino-MAXI with iMX233-SJTAG + ARM-USB-TINY-H
12VDC Power Supply is mounted alongside. Metal studs allow me to store the SD card reader on the board itself.
Here is what I plan to do with this: Debugging the iMX233-OLinuXino via SJTAG with OpenOCD

Cubieboard with a USB to RS485 converter. The RS485 Convertor allows interfacing with
the blue colored C2000 I/O module. This I/O modules digitizes the data from
the Rotronic Hygroflex HF320 humidity+temperature sensor and makes it available over Modbus.
Close up of how I mounted Philips car charger for mobile phones
on my baseboard using metal studs. I used this car charger as a 12VDC to 5VDC regulator.

We got the board made through our regular PCB fabricator. All we did was mark holes at 0.5 inch intervals in Eagle and generate the drill (.drl) file and give it to him. His CNC drill machine did the rest.

Screenshot of the baseboard designed in Eagle's layout editor.
We ran the CAM job to generate the drill file and passed it on to the PCB fabricator.
The PCB fabricator took a sheet of FR-4 plain non-copper clad board and drilled holes
in it using his CNC machine and gave the boards to us. No etching was required.

Initial photos of me trying to mount PCBs on the red metal
baseboard supplied as part of the Mechanix kits.
I used the same pitch (5/32" holes spaced 0.5" apart) for my own baseboards.

Tuesday, January 7, 2014

SHA256 on Texas Instrument's Tiva C Series of Cortex M4 Microcontrollers: Software vs. Hardware

So I wrote code to perform SHA256 hashing on a single block on data using the TM4C129DNCPDT running off a 16 MHz Crystal. I performed the hashing first using software C code and then using the Tivaware Library function which make use of TM4C129x's "Hardware Accelerated Hash (SHA/MD5) advanced hash engine that supports SHA-1, SHA-2 or MD5 Hash computation".

I assigned 2 GPIOs for measuring the time taken for each method (the software one and the hardware one).
I toggled the GPIO before and after hashing for each of the two methods.
The Oscilloscope shows the pulses observed on the two GPIOs.

The results are as below:
Software SHA256: 1.216 milliseconds or 1216 microseconds.
SHA256 using Hardware Acceleration: 28 microseconds (4200% faster)

Amount of time take to perform SHA256 in Software (Channel 2) and
using Hardware Acceleration (Channel 1).



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/shamd5.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "sha256.h"

#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

//Output observable on UART0 115200 8-N-1
//SHA256 Software vs. Hardware comparison on TM4C129DNCPDT
//SHA256 Software Code taken from: http://www.spale.com/download/scrypt/scrypt1.0/
//Input Message (64 bytes): {0x72616e41, 0x696c616b, 0x20616b20, 0x6e6f6870, 0x61682065}
//Software SHA-256 Result: {0x568e2d32, 0x7113821c, 0xa5b5025a, 0xe3335ddd, 0x779bc58c, 0x5d0fc8ed, 0x98f48aef, 0xc0e6db2e}
//Hardware SHA-256 Result: {0x568e2d32, 0x7113821c, 0xa5b5025a, 0xe3335ddd, 0x779bc58c, 0x5d0fc8ed, 0x98f48aef, 0xc0e6db2e}

void ConfigureUART(void) {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 115200, 16000000L);
}

int main(void) {
 uint8_t stringMessage[64] = "Anarkali ka phone hai. Anarkali ka phone hai. Anarkali ka phone.";
 uint32_t * g_ui32Message = (uint32_t *) stringMessage;

 sha256_context SW_ctx;
 unsigned char SW_sha256sumSW[32];
 uint32_t * SW_ui32SHA256Result = (uint32_t *)SW_sha256sumSW;

 uint32_t HW_ui32SHA256Result[8];

 FPULazyStackingEnable();
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_3);
    GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_2);
    GPIOPinWrite( GPIO_PORTD_BASE,GPIO_PIN_3,0);
    GPIOPinWrite( GPIO_PORTD_BASE,GPIO_PIN_2,0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_CCM0); //Enable the CCM module.
 while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0)) {
    } //Wait for the CCM module to be ready.

    ConfigureUART();
    UARTprintf("\nSHA256 Software vs. Hardware comparison on TM4C129DNCPDT\n");
    UARTprintf("SHA256 Software Code taken from: http://www.spale.com/download/scrypt/scrypt1.0/\n");

    UARTprintf("Input Message (64 bytes): {0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x}\n",
          g_ui32Message[0],
          g_ui32Message[1],
          g_ui32Message[2],
          g_ui32Message[3],
          g_ui32Message[4]);

    GPIOPinWrite( GPIO_PORTD_BASE,GPIO_PIN_3,GPIO_PIN_3);
    sha256_starts( &SW_ctx );
    sha256_update( &SW_ctx, (uint8 *) stringMessage, 64);
    sha256_finish( &SW_ctx, SW_sha256sumSW );
    GPIOPinWrite( GPIO_PORTD_BASE,GPIO_PIN_3,0);

    GPIOPinWrite( GPIO_PORTD_BASE,GPIO_PIN_2,GPIO_PIN_2);
 SHAMD5Reset(SHAMD5_BASE); //Reset the SHA/MD5 module before use.
    SHAMD5ConfigSet(SHAMD5_BASE, SHAMD5_ALGO_SHA256); //Configure the SHA/MD5 module.
    SHAMD5DataProcess(SHAMD5_BASE, g_ui32Message, 64, HW_ui32SHA256Result); //Generate the hash from the data.
    GPIOPinWrite( GPIO_PORTD_BASE,GPIO_PIN_2,0);

    UARTprintf("Software SHA-256 Result: {0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x}\n",
      SW_ui32SHA256Result[0],
      SW_ui32SHA256Result[1],
      SW_ui32SHA256Result[2],
      SW_ui32SHA256Result[3],
      SW_ui32SHA256Result[4],
      SW_ui32SHA256Result[5],
      SW_ui32SHA256Result[6],
      SW_ui32SHA256Result[7]);

    UARTprintf("Hardware SHA-256 Result: {0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x}\n",
      HW_ui32SHA256Result[0],
      HW_ui32SHA256Result[1],
      HW_ui32SHA256Result[2],
      HW_ui32SHA256Result[3],
      HW_ui32SHA256Result[4],
      HW_ui32SHA256Result[5],
      HW_ui32SHA256Result[6],
      HW_ui32SHA256Result[7]);
    while(1) {
    }
}


The complete Eclipse Workspace Project (Code Composer Studio 5.5) for this experiment can be downloaded from here.