PIC18F45K22 Multi-Purpose System
This post will introduce the 8-bit PIC18F series microcontroller I am currently using in my project.
The product can be found here including the datasheet, and various application notes.
As far as packaging go, there are various options, but for my project the 40-Lead Plastic Dual In-Line Package (or better known as PDIP/DIP40) is suitable for breadboarding purpose. In addition to that, the 44-Lead Plastic Thin Quad Flatpack (TQFP 44) will be valuable when we go into PCB layout.
(Pictures from Microchip.com website)
The focus of the project is to create a single functional unit capable of checking for frequency, voltage, and do some switching (which will employ, for the sake of simplicity, some BJT/MOSFET switched relay).
Peripheral that we are focusing on are these:
- Capture Compare PWM (CCP)
- 10-bit ADC
- GPIO (General Purpose Input Output)
- 8-bit/16-bit Timers
The microcontroller have a built in, 1% tuned, 4x PLL capable Oscillator, able to go up to 64MHz for its FOSC which means the basic single-cycle executions will take FOSC/4 = 16 MHz, a mere 62.5 ns time taken from instruction fetching to full execution (depending on the opcodes, of course).
CCP and ECCP (Enhanced CCP) module works in either Capture, Compare, or PWM mode. For this project we’re interested in the Capture module as it allows frequency counting with some precision. The precision point of course depends solely on the accuracy and precision of the internal oscillator.
The surprisingly good news is that newer PIC allows for oscillator tuning in the form of OSCTUNE register. Accordingly, we can make use of that and do a basic calibration against a reference frequency.
Capture module works in the following modes :
- Every falling edge
- Every rising edge
- 4th rising edge (Pre-scaler ÷4)
- 16th rising edge (Pre-scaler ÷16)
Method 3 and 4 is just basically “every rising edge” with the input pre-scaled down by a factor of 4 and 16 respectively. The calculation precision, however, dramatically improves and we can account for error-factor easier.
Next post, we shall look into more detail on the frequency calculation and the decimal point precision, also what method we are going to use for the frequency counting.