PDA

View Full Version : FREQOUT command for continuous operation



Aussie Barry
- 5th September 2016, 12:47
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:



'************************************************* ***************
'* 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

HenrikOlsson
- 5th September 2016, 16:59
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.

Art
- 5th September 2016, 18:14
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.



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

Aussie Barry
- 5th September 2016, 23:40
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

richard
- 6th September 2016, 02:08
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

Aussie Barry
- 6th September 2016, 02:51
Thanks Richard.

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

Cheers
Barry
VK2XBP

richard
- 6th September 2016, 03:37
its a half wave samples are sin(pi*(I+10)/256 )*256 where I=1 to 25

Aussie Barry
- 9th September 2016, 07:14
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

Art
- 20th September 2016, 13:34
That totally went over my head :D 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?

Aussie Barry
- 22nd September 2016, 06:27
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