Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic - COUNTERA — Parallax Forums

PropBasic - COUNTERA

camelot2camelot2 Posts: 54
edited 2010-04-03 02:09 in Propeller 1
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

·

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-04-03 00:51
    There are two obvious issues here. The first is that you keep re-initialising the counter inside the loop (move that before the do). Secondly, why do you initialise the counter twice or rather set it to NCO then switch it off again (ctra = %00100)? I.e. either use countera or ctra but not both.

    BTW, looking at the compiler output would have told you all that [noparse]:)[/noparse]
  • caskazcaskaz Posts: 957
    edited 2010-04-03 01:05
    DEVICE P8X32A, XTAL1, PLL16X
    XIN 5_000_000
    
    P0 PIN 0 LOW
    
    ' Main program
    PROGRAM Start
    Start:
      ' Main code loop
           COUNTERA 32, P0
           frqa = 112367
    Main:
           ' Main Program
    
         GOTO Main
         END
    
    
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-04-03 01:48
    @caskaz

    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
  • kuronekokuroneko Posts: 3,623
    edited 2010-04-03 02:01
    @Jon: It seems that the generated code is OK, while P0 is indeed defined as a mask, countera does use the pin number (e.g. movs ctra, #0).
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-04-03 02:09
    Thanks, I should have looked -- I guess Bean automated that process so we wouldn't have to think about it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
Sign In or Register to comment.