Hello, my english is not so good but I will try to post for the first time....
I am trying to make a very stabile frequency generator from 10 Hz to 100 Hz
and in increments of maximum 0.1 Hz but 0.05 Hz would be great.
My first idea was to use the 16F872 and it's HPWM output witch
is from about 1200Hz to 32767 Hz , and divide the output by 300 [lot's of D-Flip Flops].
The problem is that the PWM output is working in increments of about 100 Hz,
and 100 Hz / 300 = 0.3Hz resolution......no good.
Is there a way to get a better resolution by using Asembler, or is using the DDS like
AD9833 or AD9850 my only option?
The mesurements from very good frequency meter taken from the HPWM output are :
.....
9708 Hz
9803 Hz
9900 Hz
10000 Hz
10100 Hz
10203 Hz
10308 Hz
10415 Hz
10526 Hz
10638 Hz
.....
and the code is:
---------------------------------------------------------
device=16F872
DECLARE XTAL=4
CONFIG xt_OSC , WDT_OFF , PWRTE_ON , BODEN_ON , LVP_OFF , WRTE_OFF , CP_OFF , DEBUG_OFF
DECLARE BOOTLOADER = OFF
DECLARE PORTB_PULLUPS = OFF ' Disable PORTB pullup resistors
DECLARE WATCHDOG = ON
DECLARE REMARKS ON
DECLARE ICD = OFF
DECLARE LCD_DTPIN = PORTA.0
DECLARE LCD_RSPIN = PORTA.5
DECLARE LCD_ENPIN = PORTa.4
DECLARE LCD_INTERFACE = 4 ' 4-bit Interface
DECLARE LCD_LINES = 2
ALL_DIGITAL = TRUE
SYMBOL PressUp = PORTB.7
SYMBOL PressDOWN = PORTB.6
DIM freq AS word
Dim freq_OUT as word
dim freq_in_END as word
DECLARE CCP1_PIN PORTC.2 ' Select HPWM port and bit for CCP1
'debounce
DIM UP AS BYTE '
DIM DN AS BYTE '
UP = 0
DN = 0
freq_in_END=10000
freq_OUT = 10000
freq=10000
TRISA = %00000000
TRISB = %11000000
TRISC = %00000000
HELLO: PRINT AT 1,1,"Freq. generator"
DELAYMS 1000
CLS
BEGINING:
Button PressUp,1,255,0,UP,1,A_freq_UP
Button PressDOWN,1,255,0,DN,1,A_freq_DOWN
If freq > freq_in_END then
freq_OUT = freq-1
endif
If freq < freq_in_END then
freq_OUT = freq+1
endif
HPWM 1,127,freq_OUT
PRINT AT 1,1,"Freq. is:",dec freq,"Hz"
delayms 100
freq = freq_OUT
GOTO BEGINING
A_freq_UP: freq_in_END = freq+10
GOTO BEGINING
A_freq_DOWN: freq_in_END = freq-10
GOTO BEGINING
END
---------------------------------------------------------
Thank You
ExYu
Bookmarks