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
Because the memory capacity is very much limited for this application, and does not allow the debug mode without program limitation, I selected a larger processor. See the following table:
Original
New
PIC24HJ12GP201
PIC24FJ64GA002
18 pin SO
28 pin SO
PGM 12K
PGM 64K
RAM 1K
RAM 8K
2,75 EUR
3,55 EUR
Reference Data for PIC24FJ64GA002 are available at http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en026374#1
- A radio transceiver (RF12B, 869.3 MHz) was added to allow transmitting the vario signal to a portable ground station.
- A LED was added to allow for easier debugging.
- With a RC clock of 8 MHz and scaling of factor 4, FCY = 1 MHz. The SPI clock is 1 MHz / 512 = 2 KHz, without prescaling.
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 Solution: http://www.microchip.com/forums/tm.aspx?high=&m=250151&mpage=1 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:
//Define: void _ISR _CNInterrupt (void); //main loop: if (gpioSpiDrdy == 1) { // NIRQ was set active low sprintf(gszBuf,"RA4 change notify\r\n"); uart_Print(gszBuf); 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.
Documentation:
Chipset Si4420 of module RFM12B from company Hope (sale in Germany from company http://www.pollin.de)
Family name is EZLink - http://www.silabs.com/products/wireless/EZRadio/Pages/Si442021.aspx
Si4420 Data sheet Si4420.pdf, version 1.7 from 2008-12-12
EZLink User Guide A board with a 4420 chip for application testing. The paper explains also some principles of data transmission.
WDS Wireless Development Suite User Guide. This Win32 programm helps the hobbyist to calculate quickly the chip register values.
RFM12B Module from Hope does the packaging of the Si4420 chip.
Data Sheet and Coding Example for AVR and PIC microprocessors.From Hope comes also an Antenna Guide for RF modules ANTENNAS_MODULE.pdf.
Knowledge Base for Si 4420 chip, following there are some important topics:
How do I monitor the EZRadio Si432x/Si442x FFIT signal on the SDO output? #301484, modified 2010-03-10
In order to save a pin, the FFIT can be monitored from the SDO pin since it is latched on to the first bit of the SDO line when a Status Read is called.
The FFIT is the first bit of the status word, perform a Status Read: pull nSEL low then set SDI to logic 0. FFIT will appear on the SDO pin. By continuously polling on the first bit of the SDO line, you can detect if the FIFO is full, FFIT bit set high.
Once the FFIT has been detected, read out all 16 bits of the Status Word and the FIFO content will be available after the 16th bits on the SDO line.
In what scenarios can I use the FFIT bit in EZRadio Si4x2x's receive mode? #301500, modified 2010-03-10
There are three basic scenarios:
- FFIT in Status Register: Pin 4: When there is an interrupt, you can read the Status Read Command and the first bit of the SDO is the FFIT interrupt bit. Essentially, you can read this pin without using the clock and you can find out if the interrupt was an FFIT interrupt.
- FFIT related to nIRQ: Pin 5: When nIRQ has an interrupt request, it could be any of the 4 interrupts: FFIT, FFOV, wake_up timer, or low battery detection. So you need to read the first 4 bits of the Status Read Register to find out which interrupt it was.
- FFIT in FIFO mode: Pin 7: When FIFO mode is use, pin7 is used as a FFIT interrupt.
Can nSEL and nFFS be grounded for FIFO access? #301217, modified 2009-04-09
- The nSEL and nFFS can not be permanently pulled high or low because they are edge triggered logic pins. The nSEL needs to go low to signal the start of a command and it needs to be pulled high to signal the end of the command sequence; whereas nFFS needs to go low to access the FIFO directly and go back to high to release the FIFO access.
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:
When one “transmits” data, the incoming data must be read before attempting to transmit again. If the incoming data is not read, then the data will be lost and the SPI module may become disabled as a result. Always read the data after a transfer has taken place, even if the data has no use in your application.
- The Chip Select signal is used in this application. It is used to improve noise immunity of the system. Its function is to reset the SPI slave so that it is ready to receive the next byte.
Data Bit Handover - Data is only output during the falling edge of SCK. Data is latched during the rising edge of SCK. That is SPI Mode 0,0. The opposite edge is used to ensure data is valid at the time of reading. Maximum SPI Frequency: 2,5MHz (10MHz Quarz / 4) http://www.mikrocontroller.net/articles/RFM12.
Overflow - An overflow error occurs whenever an SPI transfer finishes, but the previous data had not been read from the SSPBUF. If SSPOV is set, it must be cleared by the user program. The user program should check to ensure SSPOV remains clear. This is part of good error checking in program design.
Note, data in the SSPBUF will not be updated until the overflow condition is cleared.
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: https://www.silabs.com/support/pages/support.aspx?ProductFamily=EZRadio (si4420.pdf = RFM12B chip). First select Part Number Si4420 then check out the WDS3-Setup.zip (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:
TAB Configuration - It can calculate the Basic settings parameter of the RF module.
TAB CW TX/RX - It can calculate the Continues Wave operation parameter, without data packet modulation.
TAB Transmit/Receive - It can calculate the Data Packet modulation parameter.
Also helpful could be the battery life calculator (.xls spreadsheet, works also with OpenOffice).
A few comments (German) from http://www.mikrocontroller.net/topic/67273#1807007 will show some difficulties:
nIRQ use - Solder a 22 uF Tantal capacitor between VDD and Vss.
Power glitch reset - FIFO and Reset Mode Command 0xCA80, Bit 0 (dr): Disables the highly sensitive RESET mode. If this bit is cleared, a 600 mV glitch in the power supply may cause a system reset. For a more detailed description see the Reset modes section. In case of a problem with nIRQ set this bit to "1" (low sensitive mode).
FFIT - A good method for checking via oscilloscope or logic analyzer if data bits are arrived in the receive FIFO is to look at signal FFIT (FIFO Interrupt, pin 4).
This is a workaround if you have a problem with nIRQ. But for using the wakeup function the nIRQ is needed.
Another thread (German) concerning difficulties: http://www.mikrocontroller.net/topic/73560#605528
Transmit - Before starting to transmit, read out the Status Register.
A good FAQ page is: http://www.mikrocontroller.net/articles/RFM12
nIRQ problem at 868 MHz - Change the FIFO IT Level in "Register FIFO and Reset Mode Command" (0xCA80) from 8 Bit (0xCA83) to 16 Bit (0xCAF3).
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
PIC24FJ64GA002 - CLKO Clock Output on pin RA3: If in Configuration Bits register _CONFIG2 once the bit OSCIOFCN was once set to 0, you no longer get a clock signal output on pin RA3. Setting it to "1" in the software, Pogramming or Erase Flash Device will not help.
The only possibility to set this bit again to "1" is in MPLAB menu Configure/Configure Bits to remove the mark on "Configuration Bits set in code" and set manually this bit to 1, and then set back the mark on "Configuration Bits set in code".PIC24FJ64GA002 - Release Build does not work: In Debug Build my program works, but not in Release Build with PICkit3 programming. The Configuration Bits on address 0xABFE must read 0x3Axx, bit 0x0800 is the Release Mode bit. It must have to do with the configuration bits, because the programming of the PIC24FJ64GA002 with an ICD2 programmer clone does work with the "Release Mode" program. Lets see how does it come:
Configuration Bits as in C30 program: // from p24FJ64GA002.h _CONFIG1 ( JTAGEN_OFF & GWRP_OFF & ICS_PGx2 & FWDTEN_OFF ) // CONFIG2 = no settings used = 0xFFFF //_CONFIG2 ( ) MPLAB menu Configure/Configuration Bits ... Address Value 0xABFC 0xFFFF 0xABFE 0x3E7F The program HEX file shows for the Configuration Bits: :0457fc007f3e0000ec (address 0x57fc) The data sheet 39881D.pdf tells in chapter 24.1 Configuration Bits TABLE 24-1: Device Configuration Word Address PIC24FJ32GA 0057FCh PIC24FJ64GA 00ABFCh So, it looks like that the wrong Configuration Bits address was placed in the HEX file. Defines for C30 Linker: mplabc30\v3.25\support\PIC24F\gld\p24FJ64GA002.gld __CONFIG2 = 0xABFC; __CONFIG1 = 0xABFE; In MPLAB menu Configure/Select Device the Device is: PIC24FJ64GA002 - OK Changing the HEX file line for the Configuration Bits to: :04abfc007f3e000098 (address 0xabfc) and reprogramming with the PICkit3 programmer shows a working program - OK Reprogramming with the original HEX file (Configuration Bits address = 0x57fc) also shows a working program. So, it looks like, that programming the PIC24FJ64GA002 Configuration Bits once at the right address 0xab7c will stay in the future. As a result it looks like a bug in the HEX file generation. The ICD2 programmer shows the following programming info in the output window: MPLAB ICD 2 ready for next operation Programming Target... ...Validating configuration fields ...Erasing Part ...Programming Program Memory (0x0 - 0x14FF) Verifying... ...Program Memory ...Verify Succeeded ...Programming Configuration Bits .. Config Memory ...Programming succeeded 13-Jun-2011, 14:13:15
RFM12B - Test of communication: In order to test the success of communication to the RFM12B module issuing the Status Read Command will not help. You get back zeros only. The only possibility to check I found was the Clock Output on pin 5. As a default a 1 MHz clock is output after Power On Reset. If you issue a command "Power Management Command" 0x8239 and set bit 0 to a "1" (DC = Disable Clock output), the clock output must stop.
RFM12B - 10 MHz crystal oscillator accuracy measured:
RX module: 9.99980 MHz @ 12.0 pF load capacitor
RX module: 9.99997 MHz @ 11.0 pF - OK
TX module: 9.99981 MHz @ 12.0 pF
TX module: 9.99999 MHz @ 11.0 pF - OK
List of pages in this category:
-- RudolfReuter 2011-05-28 12:57:30
Go back to CategoryPIC or FrontPage ; KontaktEmail (ContactEmail)