Model Glider Variometer

Research the Internet for a sample Application

From all was I found the design from Hari Nair looks the most professional.

So, it should be a PIC processor PIC24HJ12GP201, programmed in C30 from Microchip, and the MPLAB IDE version 8.66, for Windows .

In order to program the processor and debug it in the circuit, it needs a proper tool with an USB interface. While searching in the internet, I found a good documentation of an ICD2-USB clone from Harald Sattler. Later I found, that I had to modify the design, in order to adopt to the 3 V power supply of the PIC24HJ12GP201. The programmer works, but the in circuit debugging is dog slow.

After having a look to the new MPLAB version X for Linux, Mac OS X and Linux, I knew it must be a PICkit3 clone. Fortunately you can buy a cheap (about 25 EUR) clone via Ebay.

So, my learning curve is very steep.

Because I got a PIC chip error, which the hotline from Microchip could not solve, I replaced the PIC chip by an Arduino Nano3 module, price 15 EUR. The benefit is also, that you get a lot of already debugged libraries.

This project is now working, but to test the application is not so easy. It still needs more time.

Design changes

Debugging the Vario Program

Because the PIC24HJ12GP201 has very limited resources (12KB flash Programm, 1 KB RAM), the original vario program just fits it.

In order to allow debugging with the UART output (9600 baud, 8N1, 3 V), I had to limit two array variables.

How to connect the 3 V UART output to a RS232 or USB port to the PC is described in DockStarSerialLink.

Saving RAM bytes:
// 45 samples => ~3 second measurement window
//#define SNS_NUM_Z_SAMPLES             45
#define SNS_NUM_Z_SAMPLES             5

String output buffer for the UART:
   char gszBuf[40]; // before 80

The Debug mode also needs some Heap space:

Debug enabled, Build All:
  Error: A heap is required, but has not been specified

If you use any standard I/O function, such as printf() in this case, you'll need to specify the heap size
 even if the size is zero (go to Build Options/Project --> MPLAB LINK30).

Heap: set to 80 bytes

Stack: 154 bytes left (Linker info)

PICkit3 for Programming and Debugging

Because I am developing the vario program with MPLAB IDE Version 8.66 under Windows in a virtual machine (VirtualBox 4.06), I had a problem connecting the PICkit3. The PICkit3 was seen from the USB interface, but not accessible. Because an USB filter was set for PICkit3, all parameter fields are set.

The solution was to edit the USB filter and clear out the parameters fields after the first three.

My PICkit3 came with firmware version 01.26.05 (actual 01.26.52). Because at this time I could not use Win7 because of an USB problem, I did a firmware upgrade under Win XP. There is rumor in the Microchip forum, that a firmware upgrade does not work under Win 7 64 bit.

The debug connection with the PICkit3 to the target PIC24FJ64GA002 looks in the output window like:

PICkit 3 detected
Connecting to PICkit 3...
Running self test...
Self test completed
Firmware Suite Version...... 01.26.56
Firmware type......................dsPIC33F/24F/24H
PICkit 3 Connected.
Target Detected
Device ID Revision = 00003043

Using pin RA4 for NIRQ signal from RFM12B

In order to use the NIRQ signal from the RFM12B module, I had to setup an interrupt source. Because all programmable I/O pins (RPx) are already used, the only possibility was to use the pin RA4 with change notification. I will sketch the most important statements for that use:

   void _ISR _CNInterrupt (void);

//main loop:
      if (gpioSpiDrdy == 1) {  // NIRQ was set active low
         sprintf(gszBuf,"RA4 change notify\r\n");
         gpioSpiDrdy = 0;

// Interrupt Service Routine
void _ISR _CNInterrupt (void)
// NIRQ from RFM12B, INT by change notification
   gpioSpiDrdy = 1;     // mark signal NIRQ was there
   IFS1bits.CNIF = 0;   // Clear CN interrupt

// Config:
   CONFIG_RA4_AS_DIG_INPUT();  // NIRQ from RFM12B, INT by change notification
   ENABLE_RA4_PULLUP();        // for test purpose, without RFM12b module
   ENABLE_RA4_CN_INTERRUPT();  // Enable CN0 pin RA4 for CN interrupt
   IEC1bits.CNIE = 1;          // Enable CN interrupts
   IFS1bits.CNIF = 0;          // Reset CN interrupt
   gpioSpiDrdy = 0;            // initialize : data is not ready

If the RFM12B module is not plugged in, a jumper from pin 2 (NIRQ) to GND will generate the Cange Notification interrupt, and outputs a text "RA4 change notify" on the UART TxD (9600 baud, 8N1, 3 V).

RFM12B Tranceiver, 869,3 MHz

The frequency 869,3 MHz was selected, because it should be less frequented than 433 MHz.

The variometer will send the climbrate as a digital value periodically down to the receiver.

The receiver will convert the climbrate value to an audio signal.

Because of the bidirectional link, it offers the possibility to change variometer parameters from the ground station.

Concerning the link range you can find a statement in RF12B.pdf "AC Characteristics (Transmitter)", page 11 Note 6: Supposing identical antenna with RF12B in RX mode, the outdoor RF link range will be approximately 120 meters indoor and 450 meters outdoor. There is an interesting paper analyzing the "link range" depending transmission speed and antenna form AN422.pdf from Silicon Labs.


Knowledge Base for Si 4420 chip, following there are some important topics:

PIC SPI Interface for RFM12B Modul

The PIC included SPI Interface (Serial Peripheral Interface) with interrupt will be used. There are a few points to consider:

Initializing the RFM12B Modul

The RFM12B tranceiver modul must be initialized before use. This is not so easy.

The most actual, detailed datasheet for the RFM12B module you get from here: (si4420.pdf = RFM12B chip). First select Part Number Si4420 then check out the (Wireless Development Suite 3.1.3 Parameter Calculator, C-Header Generator, Win32 only) for getting the proper configuration commands. For the use of WDS3 please read WDS_Chip_Config_UG.pdf.
Because the explanation is not very application specific here are some hints:

Also helpful could be the battery life calculator (.xls spreadsheet, works also with OpenOffice).

A few comments (German) from will show some difficulties:

Another thread (German) concerning difficulties:

A good FAQ page is:

PIC Software SPI to RFM12B

If the SPI readout transfer from the RFM12B module is done via Software SPI, it takes about 550 us per 16 bit word. Hence, a data rate of 9600 baud for a data telegram should be achievable in this mode. The first 8 bits show the signal FFIT=1, the last 8 bits are the data byte.

Problems and Solutions

List of pages in this category:

-- RudolfReuter 2011-05-28 12:57:30

Go back to CategoryPIC or FrontPage ; KontaktEmail (ContactEmail)

ModelGliderVario (last edited 2012-03-05 11:09:35 by dslb-084-058-144-220)