Monthly Archives: May 2014

Electronics Hardware Hacking UART / Weekend Tinkering

We did it, is live. Our first post is a very detailed look into the PIC UART. This article is a stepping stone for other projects we have lined up. Tell us what you think!

Sunday Morning Tinkering

In other bits I haven’t had a lot of time to do other things, I have been busy building two dev boards and write code for the above mentioned article but my Saturday was spent helping my sister and wife at their yard sale. It came away with a surprise for my daughter and an old Pelco dome camera. Video is a lot more interesting to look at on a scope than it is on an SA.

I also hacked up a super simple camping nightlight for my daughter. We are going camping the weekend after father’s day. I tore a cheap-o handheld temperature gun apart to get the thermopile and had a bunch of spare parts. The battery case and backlighting for the LCD will make a nice nightlight. No switch but she kills the batteries anyways as  her flashlights never get shut off. I’ll have to grab some rechargeables..


I hope you all have a pleasant memorial day weekend. I thank all my fallen military service family, and their families for their service and their sacrifice.

Analog Electronics

W0PCE ESR Meter Kit Build

In the Sept – Oct 13 ARRL publication of QEX, W0PCE has a nice article on ESR (Equivalent Series Resistance) meters. I won’t go into details because I did on a blog post I have saved in drafts for when I finish my own ESR meter but the one sentence version; An ESR meter tests electrolytic capacitors. This meter is a nice analog ESR meter that works well if you are just looking for a good/no-good meter reading.

A friend of mine when in on a buy from FAR circuits to get the board. I believe I reviewed this earlier? If not it’s in my ESR post.. so that’ll come.  The board was dirt cheap but if you’re particular you might be better off using protoboard. I don’t know where they got the parts package, but it all worked and came with everything except the connector, meter and battery pack.


ESR Meter

Shown is a 33 Ohm resistor for testing to see that 33 Ohms is nearly-full scale which is about perfect for me. I went with a BNC connector and cable… just because I have a ton of them. It’ll be hard to finish my updated ESR meter now that I have this but I’ll find the inspiration some time. 😀

C Electronics GPS Microcontrollers PIC Programming

Project: GPS2 Click with the PIC Clicker

I’m working on a GPS-based WWVB simulator and I’m pretty close to finished. I wanted to share up to the point where I add on the WWVB circuits and have it stripped down to just the PIC development board and GPS module.

This is on a Mikrelektronika PIC Clicker 18F47J53 development board and a QUECTEL L30 “GPS2” Click board (Mikroe’s module boards built for MikroeBus).

The code is below, I’ll leave the rest of the explanation in the video.

NMEA stream from this module
NMEA stream from this module



The good stuff..

* File: main.c
* Author: Charles M Douvier
* Contact at: / / @chasxmd
* Created on April 4th, 2014
* Target Device: PIC Click / 18F47J53
* Project: GPS2 test
* Using a PIC Click Dev board and GPS2 click module I am reading the NMEA
* string and declaring a "lock" by turning on the LED on RA1
* Version:
* 0.1 First build I could prove I had GPS lock
#ifndef _XTAL_FREQ //blah blah not the right way I don't care
#define _XTAL_FREQ 8000000 //8Mhz FRC internal osc
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))


//config bits
#pragma config OSC=INTOSC, WDTEN=OFF, CP0=OFF //Internal OSC, No WDT and No code protect
#pragma config IESO=OFF, FCMEN=OFF
#pragma config XINST = OFF
#pragma config PLLDIV = 1 //Divide by 1
#pragma config STVREN = ON //stack overflow/underflow reset enabled
#pragma config XINST = OFF //Extended instruction set disabled
#pragma config CPUDIV = OSC1 //No CPU system clock divide

#define _XTAL_FREQ 8000000 //defined for delay

char ctxt[120]; //buff NMEA string
volatile unsigned int ping, isrcall, index, reading, new_rx;
int ready, gpgga, gprmc; //gps associated vars
//char *rxdata;
//volatile unsigned int uart_data; // use ‘volatile’ qualifer as this is changed in ISR

* Interrupt Service
void interrupt ISR() {

if (PIR3bits.RC2IF) // see if interrupt caused by incoming data
isrcall = 0x01;
char temp;
temp = RCREG2; // read the incoming data
if(temp==’$’ && new_rx==0) //if first char of a GPS string..
index = 0; //reset index
reading = 1; //from now on go to else if
else if(reading == 1) //in middle of GPS sentence
ctxt[index] = temp; //load it up
index++; //increment index
ping = 1; //this is for debugging
if(index > 50) //thats more than enough data
index = 0; //reset index
reading = 0; //no longer storing the string
new_rx = 1; //”ding”
//PIR3bits.RC2IF = 0; // clear interrupt flag
//RCSTA2bits.FERR = 0; //Clear errors
//RCSTA2bits.OERR = 0;

* Set up my ports
void init_io(void) {
// This code before the TRIS setup is for switching the RX2/TX2 to proper pins for the dev board
INTCONbits.GIE = 0; //no interruptions please
EECON2 = 0x55;
EECON2 = 0xAA;
PPSCONbits.IOLOCK = 0; //turn off PPS write protect

//PPS Info:
//RX2DT2R: EUSART2 Synchronous/Asynchronous Receive (RX2/DT2) to the Corresponding RPn Pin bits
//RP22 000[RX2DT2R4 RX2DT2R3 RX2DT2R2 RX2DT2R1 RX2DT2R0]
//TX2/CK2 6 EUSART2 Asynchronous Transmit/Asynchronous Clock Output
//RP23 000 [RP6R4 RP6R3 RP6R2 RP6R1 RP6R0]
//RD5 RX
//RD6 TX
// Assign RX2 To Pin RP0
// Assign TX2 To Pin RP1

RPINR16 = 0x16; //Pin 22 / RD5
RPOR23 = 0x06; //Pin 23 / RD6

EECON2 = 0x55;
EECON2 = 0xAA;
PPSCONbits.IOLOCK = 1; //write protect PPS

LATA = 0x00;

TRISAbits.TRISA0 = 0; //LED1
TRISAbits.TRISA1 = 0; //LED2

TRISBbits.TRISB2 = 0; // RST
TRISBbits.TRISB3 = 0; // CS
TRISBbits.TRISB4 = 0; // SCK
TRISBbits.TRISB5 = 1; // MISO

LATC = 0x00;

TRISCbits.TRISC3 = 0; // output
TRISCbits.TRISC6 = 1; // PWM (WAKE UP)
TRISCbits.TRISC7 = 1; // MOSI

TRISDbits.TRISD0 = 1; // SCL
TRISDbits.TRISD1 = 1; // SCA
TRISDbits.TRISD4 = 1; // INT
TRISDbits.TRISD5 = 1; // RX
TRISDbits.TRISD6 = 0; // TX

void uart_xmit(unsigned int mydata_byte) {
while(!TXSTA2bits.TRMT); // make sure buffer full bit is high before transmitting
TXREG2 = mydata_byte; // transmit data

void serial_init(void)
//4800 8N1
// calculate values of SPBRGL and SPBRGH based on the desired baud rate
//- SPEN bit (RCSTA2) must be set (= 1)
//- TRIS bit for RPn2/RX2/DT2 = 1
//- TRIS bit for RPn1/TX2/CK2 = 0 for
//Asynchronous and Synchronous Master modes

PIR3bits.RC2IF=0; // make sure receive interrupt flag is clear

TXSTA2bits.BRGH=1; // select low speed Baud Rate (see baud rate calcs below)
TXSTA2bits.TX9=0; // select 8 data bits
TXSTA2bits.TXEN = 1; // enable transmit
RCSTA2bits.SPEN=1; // serial port is enabled
RCSTA2bits.RX9=0; // select 8 data bits
RCSTA2bits.CREN=1; // receive enabled
SPBRG2=104; // here is calculated value of SPBRGH and SPBRGL

__delay_ms(50); // give time for voltage levels on board to settle
uart_xmit(‘R’); // transmit some data for testing

int main(void) {
ping = 0;
new_rx = 0;
isrcall = 0;
ready = 0;
gpgga = 0;


// set up oscillator control register, using internal OSC at 8MHz.
OSCCONbits.IRCF = 0x07; //set OSCCON IRCF bits to select OSC frequency 8MHz
OSCCONbits.SCS = 0x02; //set the SCS bits to select internal oscillator block
__delay_ms(50); //lets think about life a bit before proceeding..

RCONbits.IPEN = 0;
PIE3bits.RC2IE = 1; //Enable RX2 Interrupt
INTCONbits.PEIE = 1; // Enable peripheral interrupt
INTCONbits.GIE = 1; // enable global interrupt

LATBbits.LATB2 = 0; //GPS Reset
LATBbits.LATB2 = 1; //pull out of reset

LATAbits.LATA0 = 1; //startup heartbeat LED
LATAbits.LATA0 = 0;

LATCbits.LATC1 = 1; //proves my ISR RC1 output works
LATCbits.LATC1 = 0;

LATCbits.LATC2 = 1; //proves my New Byte RC2 output works
LATCbits.LATC2 = 0;

ADCON0 = 0b00000000; //don’t need any ADC
ADCON1 = 0b00000000; //speed Vref=AVdd, VssRef=AVss

/* Disable for the time being
* This is TIMER code, untested.
INTCONbits.TMR0IE = 0;
T0CONbits.T08BIT = 1;
T0CONbits.T0CS = 0;
T0CONbits.PSA = 0;
T0CONbits.T0PS = 0x04;
INTCONbits.TMR0IF = 0;
T0CONbits.TMR0ON = 1;

while (!PORTCbits.RC6) { //in warmup?
LATAbits.LA2 = 0;
LATAbits.LA2 = 1; //Turn GPS On

LATAbits.LA2 = 1; //Ensure GPS is On

while (1) {
isrcall = 0;
ping = 0;
gpgga = 0;

if (RCSTA2bits.OERR)
RCSTA2bits.CREN=0; //DS39964B-page 347
RCSTA2bits.CREN=1; //Overrun error (can be cleared by clearing bit, CREN)

if (new_rx == 1) //got our string…
if (strstr(ctxt, “GPGGA”))
gpgga = 1;
new_rx=0; //finished with GPS string
// uart_xmit(‘x’); // this was a test, it works.
if (isrcall) { //testing bits
LATAbits.LATA0 = 1; // $ Detect!
__delay_us(10); //
LATAbits.LATA0 = 0;

if (gpgga) {
LATCbits.LATC2 = 1; //GPGGA detect
__delay_us(1); //
LATCbits.LATC2 = 0;
if(ctxt[42] == ‘1’) //this is the 43rd bit but we didn’t drop the $ into the buffer
{ //If “$GPGGA” NMEA message has ‘1’ sign in the 43rd
//position it means that tha GPS receiver has a position fix
ready = 1; //This is my “locked” variable for future code
LATAbits.LATA1 = 1; //LOCK LED
__delay_us(1); //
LATCbits.LATC1 = 0;
else if (ctxt[42] != ‘1’) //this is the 43rd bit but we didn’t drop the $ into the buffer
ready = 0; //
LATAbits.LATA1 = 0; //LOCK LED



PIC-based Dumb Terminal

Okay before you start; I know.. I know.. Because I’m shooting for a VT-100-ish emulation my project is technically an “intelligent” terminal but not in a sense that it runs an embedded OS/IP-based, but in the sense that it decodes ANSI ESC codes.. it’s still a freakn’ dumb terminal in my book.

I’m just about finished with the PC board for this and in the photo below is my proof of concept. All the key’s don’t work yet as I don’t have enough IO without some encoding; the keyboard is an old row/column keyboard  I scored off eBay.  Because I want to stick with a smaller PIC I’m going to use 74HC series logic to accomplish this, but I was considering switching to CPLD in a version 2.

My PIC 18F14K22  Dumb Terminal
My PIC 18F14K22 Dumb Terminal

Target Features: Baud change (to terminal) via a config screen on the fly (likely limited it to 1200, 2400, 4800, 9600, 115k). Switching the “retro” color from green, amber, or if you’re boring/have been playing too much telehack, white. Half/Full duplex… no color decoding (or VT220 emulation) but perhaps in the future.

Once my PC board is finished and back from the fab I’ll finish the code and make a proper post… the code isn’t presentable besides at least being decently commented. When will you see my next post on this?….. read on.

I have collaborated with Francesco of GarageTech to create a new site. Francesco had some really good ideas, so I pushed off to its own site. We’re just ironing out a few details and starting our first articles… look for some good stuff soon! will be ALL PIC-based… I’m pushing all my PIC based projects over there. I’ll co-post and maintain my blog for all non-PIC based stuff .. but if I’m dropping code and it’s not snippets, I’ll post a generic tidbit and a description here and link in over to 0xEE.

If you’re curious: it’s also not lost on me that you could use RealTerm or PuTTY on your PC… I just think this is nifty if you have the bench space.

Electronics Test Equipment

A new bench-friend!

Who needs more kids when there’s spectrum analyzers to be had!

My new Toy! The Rigol DSA 815 Spectrum Analyzer
My new Toy! The Rigol DSA 815 Spectrum Analyzer

I haven’t had a lot of time to play with this because well, I just got it. I will sit down and really tear it up … I have filters-galore to design and tune now!


Someone said they needed to take photos of the screen but there is a USB port and it does a find job of taking a snap shot to a drive.. maybe I have a new revision?

.. Next up.. Thursday night I picked up another VFD.. I have been looking for a smaller drive.. well unfortunately this one was really dead. After I pulled this board I looks like there was massive arcing to the ground plane. I also noticed the main inductor was cooked and the IGBT pack looked toasted.. this must have made a little noise went it went! At least I got a nice heat sink with fans out of the deal.


New-used VFD is nearly worthless...

Back to this last weekend: I am not going into what I’m working on because that’s a post for another day. I am working on something with my PIC Clicker… I accidentally toasted the boot loader  because I was throwing caution into the wind and felt like using my PICKit3 to program it… no need for any Mikroe C stuff… but in good faith of trying this out I reloaded the boot-loader from the hex file they provide online (thanks guys), downloaded Mikroe C, and have been writing code with it. I don’t like the change, meh. I can say if I was starting all over it would have been easier starting with one of the EasyPics or PIC Clicker and MikroeC. Lets see how it goes. Below is my first “hellow world” program blinking the LEDs..


.. so if you feel like hooking your Clicker up to the PIC kit.. here is how I did it. The colors are in order there.. just pulled off the clicker.

PICKit3+PIC Clicker

I have hope of finishing up one project “mostly-enough” to post it mid week..