FREQOUT command for continuous operation


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    166

    Default FREQOUT command for continuous operation

    Hi All,

    I am looking to generate a continuous 50Hz sine wave output using the FREQOUT command.
    From the "good book", the command is FREQOUT, Pin, Onms, Frequency1, {Frequency2}
    My initial idea was to set the Onms equal to zero to achieve continuous operation however this does not work (only operates for ~66 seconds).

    Here is my trial code using PIC12F615:

    Code:
    '****************************************************************
    '*  Name    : 50Hz Sinewave Generator                           *
    '*  Author  : Barry Phillips                                    *
    '*  Notice  : Copyright (c) 2016 DFAD                           *
    '*          : All Rights Reserved                               *
    '*  Date    : 5/09/2016                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : 50Hz Sinewave Generator using PIC12F615           *
    '*          :                                                   *
    '****************************************************************
    
    ;-------------------------------------------------------------------------------
    #CONFIG
    	__config _INTOSCIO & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _IOSCFS8 & _BOREN_OFF
    #ENDCONFIG
    
    ;----[DEFINEs]------------------------------------------------------------------
    DEFINE OSC 8
    
    ;----[Initialize]---------------------------------------------------------------
    ADCON0.0 = 0   	; Disable ADC
    CMCON0.7 = 0    	; Disable comparator
    TRISIO = 0		; All GPIO pins as Outputs
    ANSEL  = 0		; All GPIO pins as digital I/O
    
    
    ;----[Main Program Loop]--------------------------------------------------------
    Main:
        Freqout GPIO.0, 0, 50
    	GPIO.0 = 0       ; Set pin low to capture rollout of command execution
    	PAUSE 2000     ; Pause 2 seconds to accentuate rollout capture period
    GOTO Main
    
    END
    Any suggestions how the FREQOUT command can be structured for continuous operation?

    Cheers
    Barry
    VK2XBP

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,562


    Did you find this post helpful? Yes | No

    Default Re: FREQOUT command for continuous operation

    Sorry, can't help with FREQOUT but if I'm not mistaken the 12F615 has a PWM module, I'd suggest you use that.
    Create a lookup table for a sine function containing say 20 entries. Cycle thru it at 1ms per step and you have your 50Hz output.

    But then generating a 50Hz sinewave may be a job for some analog circuitry instead of a PIC.

    /Henrik.

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: FREQOUT command for continuous operation

    You won’t get it continuous, it makes a call to an assembler routine itself with the arguments passed to it.

    Failing the hardware PWM, DTs Elapsed Timer code is already clocking at 100Hz by default,
    so you could toggle a pin in the ISR and there’s your 50Hz.
    For better accuracy, toggle a bit, and write the bit to the port so you don’t have a timing change depending on the state.

    Code:
    flipflop = flipflop + 1 ‘ if variable is a bit it will flip flop
    portb.x = flipflop

  4. #4
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    166


    Did you find this post helpful? Yes | No

    Default Re: FREQOUT command for continuous operation

    Thanks Henrik and Art for your responses.

    Two things that should have been revealed in my original post:

    1/. The trial code using PIC12F615 was only done because I had that particular chip on hand. The proposed chip for this project is PIC12F1822
    2/. The final design needs to be switch selectable between 50Hz and 60Hz

    Henrik, my original intention was to use a wein bridge oscillator. The fundamentals of this type of circuit are quite straight-forward however the tricky part is the associated circuitry required to ensure a clean signal with constant amplitude. This is why I decided to go with a PIC solution.

    Art, wouldn't your DT's elapsed timer solution result in a square wave output?

    I the event that the FREQOUT approach did not work as expected, my fall back position has always been to use a sine wave lookup table.
    I understand the concept but will need to do some more reading to fully understand the requirements and how to implement it for my application.

    Cheers
    Barry
    VK2XBP

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,488


    Did you find this post helpful? Yes | No

    Default Re: FREQOUT command for continuous operation

    should be easy with a PIC12F1822 @32mhz or reduce the samples to suit,

    my idea would be something like this


    simple halfwave sin lu table [50 points per cycle]


    15,47,77,106,134,160,183,204,221,235,246,252,255,2 54,250,241,229,213,194,172,147,121,92,62,31


    set ccp to say 32khz carrier or whatever [make sure 10 bit resolution is viable]

    cycle through the table every 400uS
    set pulse width(10 bit) to 512+ lu value
    next half
    cycle through the table every 400uS
    set pulse width(10 bit) to 512 - lu value

    rinse repeat


    for 60 hz cycle every 330 uS


    at the o/p filter out carrier
    Warning I'm not a teacher

  6. #6
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    166


    Did you find this post helpful? Yes | No

    Default Re: FREQOUT command for continuous operation

    Thanks Richard.

    Your sine lu table appears non-symmetrical. Have you done this for a reason?

    Cheers
    Barry
    VK2XBP

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,488


    Did you find this post helpful? Yes | No

    Default Re: FREQOUT command for continuous operation

    its a half wave samples are sin(pi*(I+10)/256 )*256 where I=1 to 25
    Attached Images Attached Images   
    Last edited by richard; - 6th September 2016 at 03:44.
    Warning I'm not a teacher

  8. #8
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    166


    Did you find this post helpful? Yes | No

    Default Re: FREQOUT command for continuous operation

    Hi All,

    I am pleased to advise that I now have a very nice sine wave output from my PIC12F1822.
    I dropped the FREQOUT approach and went with the lookup table method instead.

    Thanks to all who assisted me with this project.

    Cheers
    Barry
    VK2XBP

  9. #9
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: FREQOUT command for continuous operation

    That totally went over my head So you open and close a PWM signal to produce a sine?
    On a scope you see the 50Hz at one scale, and then zoomed, you start to see square edges from the pic? because after all, the output is binary.
    Do you then filter the output and get it round?

  10. #10
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    166


    Did you find this post helpful? Yes | No

    Default Re: FREQOUT command for continuous operation

    Hi Art,

    Yes, the PWM output is passed through a second order low pass filter. In my case I used a Sallen-Key LPF.

    Cheers
    Barry
    VK2XBP

Similar Threads

  1. FREQOUT command
    By Art in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th February 2015, 06:21
  2. Freqout ? ? ?
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2009, 00:39
  3. bootloader Freqout problems
    By handgio in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th December 2007, 13:38
  4. RPM Counting Continuous
    By CluckShot in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th May 2007, 12:37
  5. FREQOUT delays
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th December 2003, 23:49

Members who have read this thread : 0

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