I was quite happy earlier this month to get the K9AY Loop Controller working. After using it in the ARRL 160m contest, I decided I needed to make some changes to the firmware.
That presented a problem. You see, while Microchip has made some excellent developer tools available for their PIC series of microcontrollers, like all software, it is updated from time to time, and things change.
When I used MPLAB X three years ago to write the controller firmware, I used the PIC assembly language tool MPASM. That was with version 3 of MPLAB X. I recently updated to version 5 of MPLAB X, and MPASM was no longer supported. Instead the new assembly tool was called pic-as. And, of course, it was syntactically different than the old MPASM.
I made an attempt to edit my existing code into something acceptable to pic-as. While I got it to build, I found it didn't run correctly. Rather than try to debug, I figured it might be easier to start over.
Microchip has a good C compiler. I decided to start there. I'm well experienced with C, but this left open a lot of questions. The PIC has a number of configuration registers that must be set at startup. How does one do that with C?
This actually turned out to be very easy. Microchip has a tool called the MPLAB Code Configurator (MCC). It provides a number of graphical tools and wizards that specify the chip configuration, down to the pin assignments and interrupts. MCC then generates the appropriate C code. This is a good thing. One of the hard parts of working with the PIC is figuring out how to set all the internal registers. MCC does this part for you.
My second question had to do with interrupts. How do we process interrupts in a C program? This also turned out to be easy, because MCC generates code to handle interrupts, too. When properly configured in MCC, one need only write a simple void function to process the interrupt. My controller uses a timer interrupt every 2 ms to check the state of all the buttons and update the LEDs and relays appropriately.
Re-writing the controller program in C ended up taking less time than figuring out the assembler syntax changes between MPASM and pic-as.
And the best part is, it worked!
Sunday, December 27, 2020
Re-writing the K9AY Controller
Labels:
160m,
40m,
80m,
Antennas,
Building,
Computing,
Programming,
Receiving Antennas
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment