Shop OBEX P1 Docs P2 Docs Learn Events
Help with simple methods — Parallax Forums

Help with simple methods

Evan in L.A.Evan in L.A. Posts: 6
edited 2006-09-29 16:41 in Propeller 1
With some code I got from very kind people on this board, I'm working on a little project for work, and this program should basically allow 3 buttons (PINS 0-2) to select different output PIN states, and also change the frequency of the sinewave generator on PIN 23.· It doesn't seem to be working right though, it keeps getting stuck and/or resetting my chip, and I thought I'd see if anyone might take a look at it for me.· I am a TOTAL novice at this, so please be kind.· I'm sure there are much better ways to do the button polling.· Thanks.

-Evan


CON
· _CLKMODE = XTAL1 + PLL16X
· _XINFREQ = 5_000_000

·
VAR
· long· stack0[noparse][[/noparse]20]
· long· stack1[noparse][[/noparse]20]
· long· stack2[noparse][[/noparse]20]
· long· stack3[noparse][[/noparse]60]
· long· stack4[noparse][[/noparse]20]
· long· stack5[noparse][[/noparse]20]
· long· stack6[noparse][[/noparse]20]
· long· stack7[noparse][[/noparse]20]
OBJ
PUB start
· coginit (1, sinewave(53,23),@stack0)····················· ' different sine frequencies
'· cognew (sinewave(52,23),@stack1)····················· ' meant for LEDs on the demo board
'· cognew (sinewave(55,24),@stack2)····················· ' frqa of 54 give 1 second period
· coginit (2, ADR,@stack3)····················· ' frqa = 1/80_000_000 * 2^32 = 54· => 1 Hertz

PUB ADR
· dira[noparse][[/noparse]21..0] := %111111_11111111_11000000
· outa[noparse][[/noparse]21..6] := %000000_00000000_00
· Scan
·
PUB Scan
··· Repeat
····· If InA[noparse][[/noparse]0] == 1
······· Rehearse
····· ElseIf InA[noparse][[/noparse]1] == 1
······· Record
····· ElseIf InA[noparse][[/noparse]2] == 1
······· Playback

PUB Rehearse
· coginit(1, sinewave(53,23),@stack0)
· outa[noparse][[/noparse]21..6] := %001000_01100000_01
· Scan
·
PUB Playback
· coginit(1, sinewave(153,23),@stack1)
· outa[noparse][[/noparse]21..6] := %100001_00100001_00
· Scan
·········
PUB Record
· coginit(1, sinewave(253,23),@stack2)
· outa[noparse][[/noparse]21..6] := %010000_10100000_10
··· Repeat
····· If InA[noparse][[/noparse]5] == 1
······· Rec_Start
····· ElseIF InA[noparse][[/noparse]0] == 1
······· Rehearse
····· ElseIF InA[noparse][[/noparse]2] == 1
······· Playback

PUB Rec_Start
· outa[noparse][[/noparse]9]~~
· outa[noparse][[/noparse]17]~~
· waitcnt(2_000_000+cnt)
· outa[noparse][[/noparse]9]~
· outa[noparse][[/noparse]17]~
· REC_TALLY_WAIT
PUB REC_TALLY_WAIT
· Repeat
··· If InA[noparse][[/noparse]3] == 1
····· PT_REC
··· ElseIF InA[noparse][[/noparse]0] == 1
····· Rehearse
··· ElseIF InA[noparse][[/noparse]2] == 1
····· Playback
··· ElseIF InA[noparse][[/noparse]4] == 1
····· Rehearse

PUB PT_REC
· outa[noparse][[/noparse]12]~~
· waitpeq(%10000, %10000, 0)
· waitcnt(2_000_000+cnt)
· outa[noparse][[/noparse]18]~~
· waitcnt(2_000_000+cnt)
· outa[noparse][[/noparse]18]~
· cognew (DAT_STOP,@stack4)
· Rehearse
········
PUB DAT_STOP
· waitcnt(15_000_000+cnt)
· outa[noparse][[/noparse]10]~~
· waitcnt(2_000_000+cnt)
· outa[noparse][[/noparse]10]~


PUB sinewave(fq,pn)
· dira[noparse][[/noparse]pn]~~··········································· ' pin is output
· frqa := fq··········································· ' frequency parameter
· ctra := %0_11111_000_00000000_000000_000_000000······ ' logic always mode
· ctrb := %0_00110_000_00000000_000000_000_000000 | pn· ' duty mode, tiedt to pin pn.
· repeat
··· frqb := fullsine(phsa >> 19) << 15 + $8000_0000···· ' sample phase of counter a, convert to sine for counter b
·
PRI fullsine(x) | y, q································· ' x is 0 to 2^13 (0 to 8191) for 0 to 360 degrees
· q := x >> 11········································· ' quadrant
· y := x & $7ff << 1··································· ' 0 to 90- degrees
· case q··············································· ' by quadrant
··· 0 : result := word[noparse][[/noparse]$E000 + y]······················ '
··· 1 : result := word[noparse][[/noparse]$F001 - y]
··· 2 : result := -word[noparse][[/noparse]$E000 + y]
··· 3 : result := -word[noparse][[/noparse]$F001 - y]
· return

Comments

  • Tracy AllenTracy Allen Posts: 6,656
    edited 2006-09-29 16:41
    Hi Evan,

    Are the buttons pulled low by resistors? Just checking the hardware setup. How far does the program get--Is there one particular spot that it gets stuck?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.