PropBasic - COUNTERA
camelot2
Posts: 54
hi, when I run this .spin program my cheap freq meter reads 2.093 Hz. Which
agrees with the calculation frqa = freq x (2^32/clkfreq).
'**********************************************************************
CON
··
· _clkmode = xtal1 + pll16x··········· ' Set up clkfreq = 80 MHz.
· _xinfreq = 5_000_000
PUB TestFrequency
· 'Configure ctra module
· ctra[noparse][[/noparse]30..26] := %00100·············· ' Set ctra for "NCO single-ended"
· ctra[noparse][[/noparse]5..0] := 0···················· ' Set APIN to P0
· frqa := 112_367····················· ' Set frqa for 2093 Hz (C7 note) using:
······································ ' FRQA/B = frequency × (232 ÷ clkfreq)
· 'Broadcast the signal for 1 s
· dira[noparse][[/noparse]0]~~·························· ' Set P0 to output
· repeat
'**********************************************************************
I then try to translate the above .spin program to .pbas and the freq meter
reads 1046 Hz with either FREQ 80_000_000 or XIN 5_000_000 !!!! I am using
BST ver 0.19.3 and PropBasic ver 00.00.87.
'**********************************************************************
DEVICE P8X32A, XTAL1, PLL16X
'FREQ 80_000_000
XIN 5_000_000
' Main program
PROGRAM Start
Start:
· ' Main code loop
···· do
·'· COUNTERA mode{, apin {, bpin{, frqx{, phsx}}}}
······ COUNTERA 32, 0
········ frqa = 112367
········ ctra = %00100
········ dira = 1
···· loop
END
'**********************************************************************
Can someone please tell me what I am doing wrong in setting up the .pbas file?
What I eventually want to do is have a .pbas file that generates a 20MHz signal and also a 20KHz signal using separate cogs from the main. ALL HELP WILL BE GREATLY APPRECIATED. thanks
·
agrees with the calculation frqa = freq x (2^32/clkfreq).
'**********************************************************************
CON
··
· _clkmode = xtal1 + pll16x··········· ' Set up clkfreq = 80 MHz.
· _xinfreq = 5_000_000
PUB TestFrequency
· 'Configure ctra module
· ctra[noparse][[/noparse]30..26] := %00100·············· ' Set ctra for "NCO single-ended"
· ctra[noparse][[/noparse]5..0] := 0···················· ' Set APIN to P0
· frqa := 112_367····················· ' Set frqa for 2093 Hz (C7 note) using:
······································ ' FRQA/B = frequency × (232 ÷ clkfreq)
· 'Broadcast the signal for 1 s
· dira[noparse][[/noparse]0]~~·························· ' Set P0 to output
· repeat
'**********************************************************************
I then try to translate the above .spin program to .pbas and the freq meter
reads 1046 Hz with either FREQ 80_000_000 or XIN 5_000_000 !!!! I am using
BST ver 0.19.3 and PropBasic ver 00.00.87.
'**********************************************************************
DEVICE P8X32A, XTAL1, PLL16X
'FREQ 80_000_000
XIN 5_000_000
' Main program
PROGRAM Start
Start:
· ' Main code loop
···· do
·'· COUNTERA mode{, apin {, bpin{, frqx{, phsx}}}}
······ COUNTERA 32, 0
········ frqa = 112367
········ ctra = %00100
········ dira = 1
···· loop
END
'**********************************************************************
Can someone please tell me what I am doing wrong in setting up the .pbas file?
What I eventually want to do is have a .pbas file that generates a 20MHz signal and also a 20KHz signal using separate cogs from the main. ALL HELP WILL BE GREATLY APPRECIATED. thanks
·
Comments
BTW, looking at the compiler output would have told you all that [noparse]:)[/noparse]
There is a problem with your use of P0 in the COUNTERA line. PropBASIC converts defined pin numbers to bit mask. To use it as the number, which is what you need here, put a # sign in front of P0.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA