Frequency Detector using PIC 12F683 Processor by LargeMouthBass

Step 12: Source Code

****************************************************************************************************
****************************************************************************************************
Important Update Jan 31, 2011.  Please read!

A viewer recently tried to assembly the *.asm file originally  included in this instructable, but receieved many "118" errors from the MPLAB assembler. This issue is due to the fact that I created the code on an older version of MPLAB. While it compiled fine on the older version, I
received the same errors when I tried it on a new version.

It seems like the directives used to set up and reserve space for variables in RAM has changed. I also noted a few other instances where the new version of MPLAB did not like the syntax of expressions that worked fine in older versions.

Also, be sure to select "absolute code" when trying to assemble the *.asm file supplied.

I have updated the *.asm file and attached it here. The only changes made are those required to assemble without errors. The updated file has "NEW" in the file name. I have left the old file attached also, in case anyone needs it, but just be advised that if you are using the latest MPLAB it will generate many errors if you use the original asm file I attached.

The *.hex file generated from the updated code appears to be identical to the one I originally attached, so I have not attached another file. The original *.hex file should work fine for just programming a part with the code as it is configured in the supplied *.asm file.


****************************************************************************************************
****************************************************************************************************

The source code for the *.hex file supplied is attached below. The program was written to use the PIC 12F683 processors built in oscillator as the clock, operating at 8MHz. If you plan to reuse the code in an application where you will be using a different clock frequency, then you will have to account for the difference in the software. The parameters that set the sampling rate will have to be changed.

If you make a change to the sampling frequency (which is 4400Hz for the program as it is written now) then you will have to generate new look up tables for the sine and cosine coefficients, as these are dependant on the sampling frequency.

If you change the number of samples used in the algorithm (which is 200 for the program as it is written now) you will have to generate a new lookup table for the window function.

It is relatively straightforward to port this code to another 8 bit PIC microprocessor. The main things to keep in mind are the oscillator frequency as described above, and the exact setup of registers associated with the peripherals used. These are usually very similar between the 8 bit PIC processors, but they can very a little bit. The processor chosen must have an A/D converter for reading the analog inputs, and a 16 bit timer to set the sampling frequency.
 
Remove these adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!