Remove Text Formatting
Loading...

+ Reply to Thread
Results 1 to 5 of 5

Thread: NCO Calculator

  1. #1
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    79

    Default NCO Calculator

    NCO_Calc.zip

    I'm building a project that requires calculating numerous frequencies with the Numerically Controlled Oscillator (NCO) function in Fixed Duty Cycle Mode. Realizing that it would take me way too much time punching numbers into a calculator, I developed a simple app that does all the math work for me. I'm relatively new to the whole PC programming thing (Visual Studio 2015), but it works. Unzip the attached file, double click the .exe, and viola. If you right-click the .exe and select "Create shortcut", then drag the shortcut to your desktop (or selected folder), it will open from there. You must open/install it first, though.

    How it works;
    - Select your Fosc, either by typing it in, or using the arrows up/down. It increments in 4 MHz chunks, so non-realistic Fosc settings are possible.
    - Enter the desired frequency
    - Click the "Calculate" button
    - It displays the decimal NCO1INCx value
    - It displays the hex NCO1INCx value
    - It displays the frequency when the value is rounded down
    - It displays the frequency when the value is rounded up
    - The Clear button resets for the next entry.

    It also tracks if the frequency you enter is too large for the 20-Bit NCO1INC register and gives you a pop-up warning. If you are targeting a relatively low frequency like 60 Hz, the calculated NCO value (@ 4 MHz) is 31.45725, the HEX value is 1F, the frequency generated by using the rounded up 32 (hex 20) is 61.0352 Hz, the frequency generated by using the (rounded down) 31 (hex 1F) is 59.1279 Hz. With this information:
    - NCO1INCL = $1F
    - NCO1INCH = $00
    - NCO1INCU = $00

    If you wanted a frequency of 11,780,000 and entered that in the "Enter Frequency" box, it would give you a pop-up that reads, "Frequency Too High for Fosc, Press Clear Button and Try Again". However, if you change Fosc to 32 (MHz), you get:
    - NCO Decimal = 772013.34375
    - NCO Hex = BC7AD
    - Result Rounded Up = 11780010.0136
    - Result Rounded Down = 11779994.7548

    With that in mind, you would set your registers:
    - NCO1INCL = $AD
    - NCO1INCH = $C7
    - NCO1INCU = $0B

    Have fun.
    Last edited by mpgmike; - 20th November 2017 at 00:28.

  2. #2
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    79

    Default Re: NCO Calculator

    I should also mention that your NCO registers must be:

    NCO1CON = %10000000
    NCO1CLK = 1

    This puts it into Fixed Duty Cycle Mode with Fosc as your Clock Source.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,546

    Default Re: NCO Calculator

    Nice tool! Thanks for sharing.

    Ioannis

  4. #4
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    79

    Default Re: NCO Calculator

    NCOa.zip

    I'm a bit new to this whole PC programming thing. I spent some time with the NCO Calculator and realized it really needed a bit of refinement. Attached is a cleaner version. Old one still works, but the new one has a few filters that make it more user friendly. The new one expands the Fosc range to include more options.

  5. #5
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    79

    Default Re: NCO Calculator

    Using Mr. E-Calc, I wanted to calculate values for a PWM frequency using LFINTOSC, which is 32 kHz. I entered 0.031 where it asks for Fosc (MHz) and wouldn't you know it, IT WORKED! Got me thinking about the NCO Calc. I had limited Fosc to 1 MHz on the low end. This updated Version 1.02 lowered the minimum to 1 kHz (0.001 in the Fosc box).

    Nco Calc1_02.zip

Similar Threads

  1. help with calculator
    By minssss in forum General
    Replies: 3
    Last Post: - 10th November 2009, 01:12
  2. Calculator LCD
    By menze in forum General
    Replies: 0
    Last Post: - 26th June 2006, 21:31
  3. help with my calculator project
    By loayaouad in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th May 2005, 07:42
  4. Calculatorīs LCD
    By srspinho in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 4th May 2005, 10:27
  5. Calculator
    By neiron21 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2005, 01:53

Members who have read this thread : 16

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts