SPIN CODE EXAMPLES FOR THE BEGINNER (Public Version)

123457

Comments

  • SSteveSSteve Posts: 808
    edited 2006-06-18 - 21:53:35
    I haven't looked at the rest of the code, but I'm sure that removing [noparse][[/noparse]Index++] is the culprit. You are displaying the first value in the array every time this line of code is executed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
    OS-X: because making Unix user-friendly was easier than debugging Windows

    My band's website
    Our first album on the iTunes Store
    Ryer Island: our second album...
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-06-18 - 21:55:00
    Sid,

    Use this statement.

    VideoDisplay.bin(RX_Data[noparse][[/noparse]Index++], 8) 'Displays full RFID in Binary



    Your code only picks up the first position in the array, which is a·Line·Feed.








    Newzed said...

    I wanted to display the ASCII numbers in binary so I changed:

    VideoDisplay.dec(RX_Data[noparse][[/noparse]Index++])

    to read

    VideoDisplay.bin(RX_Data,8)

    All I got was·twelve 0000 1010 binaries.· What am I not doing?

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··
  • NewzedNewzed Posts: 2,503
    edited 2006-06-18 - 23:00:18
    Thanks very much for the help.· I tried just about every statement except
    that one.· I played around with the code a bit and finally came up with:

    Repeat 12
    ····· VideoDisplay.dec(RX_Data[noparse][[/noparse]Index++]) 'Displays full RFID in ASCII
    ····· VideoDisplay.out(" ")
    ··· Index:=0
    ··· VideoDisplay.Out(Cr)
    ··· VideoDisplay.Out(Cr)
    Repeat 12
    ····· VideoDisplay.bin(RX_Data[noparse][[/noparse]Index++],6) 'Displays full RFID in·Binary
    ······VideoDisplay.out(" ")
    ····· VideoDisplay.Out(Cr)

    Now it displays both ASCII and binary.· The 6-bit binary makes
    the spacing work out perfectly for the 40-column wide screen.

    I'm learning [noparse]:)[/noparse])

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2006-06-18 - 23:54:15
    There is an error in Exmple 04:

    PRI DisplayTextOnMonitor | Count
    · VideoDisplay.start
    · SetScreenWhiteOnDarkBlue

    VideoDisplay.start does not call a pin.· Should be the pin the 1.1K resistor is
    connected to, i.e.:

    VideoDisplay.start(12)

    Sid·
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-06-19 - 04:38:26
    Hi Sid,

    The TV_Terminal·object used in Example 4 was the first version of that object.· Example 4 worked fine with that object.·"Start" did not have a pin parameter.· In fact, if you try to use a pin paramenter (Start(12)), you get an error.

    Looks as if I will need to modify·my code·for the latest version of TV_Terminal, and put a note in the code telling others to use the latest version.

    Thanks,

    Dave








    Newzed said...

    There is an error in Exmple 04:

    PRI DisplayTextOnMonitor | Count
    · VideoDisplay.start
    · SetScreenWhiteOnDarkBlue

    VideoDisplay.start does not call a pin.· Should be the pin the 1.1K resistor is
    connected to, i.e.:

    VideoDisplay.start(12)

    Sid·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··

    Post Edited (Dave Scanlan) : 6/19/2006 4:42:16 AM GMT
  • NewzedNewzed Posts: 2,503
    edited 2006-06-19 - 15:20:51
    I have modified Dave Scanlan's Example 04 to display the
    decimal equivalent of a HEX or binary number.· The only problem is that the
    number must be entered in the program each time.· If I had a keyboard
    attached to my Propeller board, how would I change the code so I could
    select Hex or Bin and enter the number from the keyboad.· Here is the code
    for converting a Hex humber:
    '·········································· EXAMPLE 04A
    '
    '······························ CONVERTS HEX OR BINARY NUMBER TO DECIMAL····························
    '*************************************************************************************************
    'PURPOSE:
    '· -- Demonstrates how to convert a Hex or binary number to decimal and sends
    '···· the result to a video monitor, and how to set the foreground and
    '···· background colors of a video monitor to white-on-blue.
    '
    'ADDITIONAL INFORMATION:
    '· -- The video signal output is a composite signal.
    '· -- TV_Terminal is an object call TV_Terminal.spin found in the "Propeller Tool" subdirectory.
    '· -- Any name could have been used instead of "VideoDisplay"
    '· -- This examples requires an elementary knowledge of OOP.
    '· -- This example assumes you have the development kit or a schematic of it.·
    '···· You will need one of these to generate a composite video out.
    '
    'Submitted by Sid Weaver, June 19, 2006·········
    'File: Example04A_VideoOutput.spin
    '**************************************************************************************************
    'CORRECT OUTPUT: A text string, a Hex number, another text string and a
    'decimal number will be displayed.
    '**************************************************************************************************
    '
    CON
    · _clkmode = xtal1 + pll16x······
    · _xinfreq = 5_000_000
    · ClearScreen = 0
    · number = %1111
    ·'
    OBJ
    · VideoDisplay: "TV_Terminal"·················· 'Creates the object VideoDisplay
    '
    VAR
    · long num
    PUB Start
    '
    · num:= $F03A
    · DisplayTextOnMonitor
    '
    PRI DisplayTextOnMonitor | Count
    · VideoDisplay.start(12)··························· 'Initializes the VideoDisplay object
    · SetScreenWhiteOnDarkBlue····················· 'Calls a procedure that sets the foreground
    ··············································· '· color to white and the background color
    ················································ '· to dark blue.
    ··· VideoDisplay.str(string(" Enter HEX number "))· 'Sends a text string to the video monitor.
    ··· VideoDisplay.hex(num,4)
    ··· VideoDisplay.out(13)
    ··· VideoDisplay.str(string(" Decimal is "))
    ··· VideoDisplay.dec(num)···················· 'Sends a numeric value to a video monitor.
    ··· VideoDisplay.out(13)·················· 'Sends a NewLine to a video monitor.
    ··· VideoDisplay.out(1)················ 'Clear screen.
    '
    PRI SetScreenWhiteOnDarkBlue··················· 'Sets the foreground color to white and the
    · VideoDisplay.out(3)·························· '· background color to dark blue on the monitor.
    · VideoDisplay.out(5)
    'INDENTION IS IMPORTANT IN SPIN:· Spin does not use Ends in its blocks of code.·· For
    '································ example, there is no End Repeat after the Repeat loop and
    '································ you must indent after CON, OBJ, PUB, PRI, and DAT.

    Sid
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-06-19 - 16:17:58
    See Example 18 for how to use the keyboard for making a selection.· Adapting that code along with a simple IF statement will do the job.· Also become familiar with the code in the Keyboard object.






    Newzed said...
    I have modified Dave Scanlan's Example 04 to display the
    decimal equivalent of a HEX or binary number.· The only problem is that the
    number must be entered in the program each time.· If I had a keyboard
    attached to my Propeller board, how would I change the code so I could
    select Hex or Bin and enter the number from the keyboad.· Here is the code
    for converting a Hex humber:
    '·········································· EXAMPLE 04A
    '
    '······························ CONVERTS HEX OR BINARY NUMBER TO DECIMAL····························
    '*************************************************************************************************
    'PURPOSE:
    '· -- Demonstrates how to convert a Hex or binary number to decimal and sends
    '···· the result to a video monitor, and how to set the foreground and
    '···· background colors of a video monitor to white-on-blue.
    '
    'ADDITIONAL INFORMATION:
    '· -- The video signal output is a composite signal.
    '· -- TV_Terminal is an object call TV_Terminal.spin found in the "Propeller Tool" subdirectory.
    '· -- Any name could have been used instead of "VideoDisplay"
    '· -- This examples requires an elementary knowledge of OOP.
    '· -- This example assumes you have the development kit or a schematic of it.·
    '···· You will need one of these to generate a composite video out.
    '
    'Submitted by Sid Weaver, June 19, 2006·········
    'File: Example04A_VideoOutput.spin
    '**************************************************************************************************
    'CORRECT OUTPUT: A text string, a Hex number, another text string and a
    'decimal number will be displayed.
    '**************************************************************************************************
    '
    CON
    · _clkmode = xtal1 + pll16x······
    · _xinfreq = 5_000_000
    · ClearScreen = 0
    · number = %1111
    ·'
    OBJ
    · VideoDisplay: "TV_Terminal"·················· 'Creates the object VideoDisplay
    '
    VAR
    · long num
    PUB Start
    '
    · num:= $F03A
    · DisplayTextOnMonitor
    '
    PRI DisplayTextOnMonitor | Count
    · VideoDisplay.start(12)··························· 'Initializes the VideoDisplay object
    · SetScreenWhiteOnDarkBlue····················· 'Calls a procedure that sets the foreground
    ··············································· '· color to white and the background color
    ················································ '· to dark blue.
    ··· VideoDisplay.str(string(" Enter HEX number "))· 'Sends a text string to the video monitor.
    ··· VideoDisplay.hex(num,4)
    ··· VideoDisplay.out(13)
    ··· VideoDisplay.str(string(" Decimal is "))
    ··· VideoDisplay.dec(num)···················· 'Sends a numeric value to a video monitor.
    ··· VideoDisplay.out(13)·················· 'Sends a NewLine to a video monitor.
    ··· VideoDisplay.out(1)················ 'Clear screen.
    '
    PRI SetScreenWhiteOnDarkBlue··················· 'Sets the foreground color to white and the
    · VideoDisplay.out(3)·························· '· background color to dark blue on the monitor.
    · VideoDisplay.out(5)
    'INDENTION IS IMPORTANT IN SPIN:· Spin does not use Ends in its blocks of code.·· For
    '································ example, there is no End Repeat after the Repeat loop and
    '································ you must indent after CON, OBJ, PUB, PRI, and DAT.

    Sid
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··
  • NewzedNewzed Posts: 2,503
    edited 2006-06-19 - 17:08:12
    Where can I find the object "Keyboard_iso"?

    Thanks

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2006-06-19 - 21:07:34
    In TV Terminal Demo, if I write:

    term.out(2)

    all text is green until I change it.

    If I write in the next little routine:

    term.out(3)

    The previous text stays green and all following text turns red.· That's OK.

    If I write anywhere:

    term.out(5)

    all text on the TV turns to white.· Why is that?

    Are green and red the only colors available, with white the apparent default
    if no color has been called.

    Thanks

    Sid
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-06-22 - 21:31:34
    Sid,

    It is in your Email.

    Dave








    Newzed said...

    Where can I find the object "Keyboard_iso"?

    Thanks

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2006-07-10 - 22:18:56
    Dave, these tutorials are great thanks a million! I'm learning a heck of a lot without having to get too bogged down in manual hell!

    Graham

    p.s. The manual is actually really good, things don't get better.
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-07-11 - 16:02:04
    Hi Graham,

    Thanks for the nice words.·

    I would like to remind you and others that you are free to add your Spin code examples to this thread.· All I ask is that you follow the format I have used and make sure that your code runs correctly.

    Thanks again,

    Dave Scanlan


    Graham Stabler said...
    Dave, these tutorials are great thanks a million! I'm learning a heck of a lot without having to get too bogged down in manual hell!

    Graham

    p.s. The manual is actually really good, things don't get better.
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··

    Post Edited (Dave Scanlan) : 7/12/2006 6:32:36 AM GMT
  • ToyguyToyguy Posts: 1
    edited 2006-07-13 - 02:23:32
    Question and comment from the new guy smile.gif

    In Example 4, there is a (12) parameter passed to the VideoDisplay object. What does that do?

    Also, the commented and uncommented Example 4 listings are somewhat different in the Start function. One passes the (12) in and the other embeds it in the called function. I presume they work the same way but it was momentarily confusing.
  • Mike GreenMike Green Posts: 22,919
    edited 2006-07-13 - 02:54:40
    The 12 is the default number of the first pin of a set of 4 used to generate the video signal. The Demo Board is wired up this way, but you can attach the resistor network needed to any group of 4 pins starting at a multiple of 4. See the TV object documentation for details.
  • dlbdlb Posts: 1
    edited 2006-09-05 - 13:38:48
    How about an example where multiple cogs call the same subroutine passing different parameters?
    (ie pass the LED pin as well as the blink rate.)
  • Beau SchwabeBeau Schwabe Posts: 6,416
    edited 2006-09-05 - 17:43:32
    dlb,

    Take a look at Chapter 3 in the Propeller manual. Excersise 6,9, and 10

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    [url=mailto:bschwabe@parallax.com]Beau Schwabe[/url]

    IC Layout Engineer
    Parallax, Inc.


    Beau Schwabe --- Robotics applications- PCB design, embedded software, and mechanical
    Oklahoma Robotics -

    www.Kit-Start.com - bschwabe@Kit-Start.com ෴෴ www.BScircuitDesigns.com - icbeau@bscircuitdesigns.com ෴෴

  • Tracy AllenTracy Allen Posts: 6,401
    edited 2006-09-26 - 02:35:14
    Hi all. There has been interest in tutorials on use of the cog counter modules, and I decided it was time to help along my own learning by doing. This object lesson deals with the counters and with the sine lookup table that is found in the hub ROM.

    The demo here shows how to use the counters A and B in a coupled manner, to generate a sine wave similar to the one made by the BASIC Stamp FREQOUT command. The sine wave is produced by means of PWM, modulated with a duty cycle that varies from 0% up to 100% and back again in a sinusoidal pattern. This takes a little doing on the Propeller. The counters A and B associated with each COG can in NCO mode provide a square wave output at any frequency, or, in duty mode they can provide the 0% to 100% PWM. This object shows how to couple them together. It has counter A generate a square wave frequency, looks up the phase in the hub ROM table of sine values, and then uses the sine values to set the duty cycle for counter B. The object listed below in the post is a bare bone implementation written in Spin. Also attached are sinewave1.spin and sinewave3.spin.

    Sinewave1.spin launches the sinewave generator into all 8 COGs and uses all 16 cog counters to generate a pulsating pattern at different frequencies on the 8 LEDs that are attached to pins pa16 to pa23 on the demo board.

    Sinewave3.spin is a pASM implementation, so it runs much faster, with an update rate of 1 microsecond. It is capable of generating an audio frequency sine wave to the headphone port on the demo board.

    All of these examples illustrate setup and use of the counters, and reading the sine table in the hub ROM.




    
    '' EXAMPLE generates a square wave output on one pin, and
    '' a sinewave output at the same frequency as PWM on a second pin
    '' uses the ctra and ctrb functions and the sine table in hub ROM
    '' LED on pin pa16 flashes on and off, while LED on pa17 pulsates with the sine wave
    ''
    '' File: sinewave0.spin                
    '' Submitted by Tracy Allen, 23 Sept 2006
    ''
    '' DIFFICULTY LEVEL:  easy program, concept is more difficult
    ''
    '' OPERATION:
    '' 
    '' -- LED on pin pa16 is driven by counter A NCO mode, phsa(31).
    '' -- LED on pin pa17 driven by counter B in duty mode, phsb(carry),
    ''    which gives any intensity from fulll off to full on
    '' -- The program repeatedly reads the phase of counter A
    ''    and looks up the corresponding sine value in the sine table in hub ROM
    ''    and modulates the frqb value of counter B  to give the sinusoidal pulsation
    '' -- The demo board has 8 leds attached to pins a16 to a23, such that
    ''    bringing those pins high causes the yellow leds on the demo board to
    ''    light.
    ''
    ''   pa16 (+)  ────────────  Vss
    ''
    ''   pa17 (+)  ────────────    Vss 
    ''   
    ''  -- This program is written all in Spin, so the update rate is every ~50 microseconds.
    ''     That limits its frequency to less than about 1 kilohertz.
    ''        
    ''*************************************************************************************************
    '' CORRECT OUTPUT:
    '' LED on pin pa16 flashes on and off, while LED on pa17 pulsates with the sine wave
    ''
    '' The program is written in Spin, not pasm, so it is capable of only low frequencies
    '' How to calculate frqa value from desired Fout and CLKFREQ:    frqa = Fout / CLKFREQ * 2^32
    ''
    '' Variations to try:
    '' -- Change the frequency and the amplitude by playing with the parameters.
    '' -- move the signal to pins 10 and 11 (on the demo board).  These pins has an LC filter that will smooth out the wave
    ''     for observation on an oscilloscope.   The duty modulation is a high frequency waveform that can be filtered,
    ''     but unfiltered it looks like a mess on an oscilloscope display.
    '' -- Make it generate a sine wave only when an active low button is pressed. (Hint, use counter mode "logic !A")
    '' -- Make it generate a triangle wave instead of a sine wave.   The triangle PRI is also written below.
    '' -- Make it generate a sawtooth wave, same angle and output scaling.
    
    ''*************************************************************************************************
    
    CON
    
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
      
    VAR
    
    OBJ
    
    PUB sinewave 
      dira[noparse][[/noparse]16..17]~~                  ' pa16 as square wave output, pa17 as sine wave
      dira[noparse][[/noparse]0]~~                       ' pa0 as probe for loop timing
      frqa := 54                      ' gives output frequency of ~1 hertz (1/80_000_000 * 2^32)
      ctra := %0_00100_000_00000000_000000_000_010000 ' NCO mode pin pa16
      ctrb := %0_00110_000_00000000_000000_000_010001 ' duty to pin pa17.
      repeat
        !outa[noparse][[/noparse]0]                                              ' probe this pin to see how fast this repeat loops
                                                            ' which will be much faster than the sine wave output frequency
                                                            ' The repeat loop has to update the output amplitude many times during each sine cycle
        frqb := $8000_0000 - (fullsine(phsa >> 19) << 15)     ' repeat this forever,
                                                            ' sample counter a phase
                                                            ' use high 13 bits for angle 0-360 degrees
                                                            ' lookup sine corresponding to that phase, using the HUB sine table
                                                            ' convert to duty for counter b, 
                                                            ' The <<15 makes modulation near 100% of 3.3 volts.
                                                            ' Try <<14 to make modulation of 50%, or <<13 for 25%, etc.
                                                            ' offset of $8000_0000 centers the waveform on 3.3/2=1.65 volts
      
    
    ' the following PRI takes the angle as input and looks up the sine of the angle in the HUB rom sine table
    ' The input angle is 0 to 8191 (13 bits) corresponding to 0 to 360 degrees or 0 to 2 pi radians
    ' [SIZE=2]Lookup in the [SIZE=2]HUB sine table will use 11 of those bits, as a word address to look up a [SIZE=2]sine value[SIZE=2] in the first quadran[SIZE=2]t.
    ' [SIZE=2]The remaining two bits [SIZE=2]adj[SIZE=2]ust the result for the quadrant 1 to 4.[/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE]
    ' The result is a twos complement number in the range of +/- 65535, representing + and minus 1.
    PRI fullsine(x) | y, q                                  ' x is 0 to 2^13 (0 to 8191) for 0 to 360 degrees
      q := x >> 11                                          ' two highest bits of 13 are the quadrant, 0, 1, 2 or 3
      y := (x & $7ff) << 1                            ' 0 to 90- degrees, are contained in 11 bits, shift left one for Word offset
                                                              ' this is the address offset into the sine table in hub rom
                                                              ' note: the parentheses are important for operator precedence
      case q                                                ' select quadrant 0,1,2,3    
        0 : result := word[noparse][[/noparse]$E000 + y]             ' 
        1 : result := word[noparse][[/noparse]$F000 - y]               ' 2049 angles, 16 bit sin(angle) values corresponding 0 to 90 degrees. 
        2 : result := -word[noparse][[/noparse]$E000 + y]             ' the same table is folded over and mirrored for all 360 degrees
        3 : result := -word[noparse][[/noparse]$F000 - y]              ' value returned in the range of -$ffff to +$ffff
      return 
    
    ' This is an alternative routine that generates a triangle wave instead of the sine.
    ' substitute "triangle" for "fullsine" in the main PUB to see it.
    ' This routine takes the same input "angle" from 0 to 8191.
    ' And returns values in the same range, +$FFFF to -$FFFF
    PRI triangle(x) | y, q                                  ' x is 0 to 2^13 (0 to 8191) for 0 to 360 degrees
      q := x >> 11                                          ' alternate routine to make a triangle wave
      y := (x & $7ff) << 5                                  ' computed values
      outa[noparse][[/noparse]23..18] := q
      case q
        0 : result := y                       ' 
        1 : result := $FFFF-y
        2 : result := -y
        3 : result := -($FFFF-y)
      return
    



    edit: program had lost its indentation

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 5/17/2008 7:11:04 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-26 - 21:32:18
    Has anyone heard from Dave Scanlan?· He hasn't·been on the forums·since July 12, 2006.· He was moving right along with tutorials.· Just wondered if he was okay.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    Chris Savage | Engineering Tech | Main Office: (916) 624-8333 | Direct to Tech Support: (888) 997-8267 | Website | Twitter | Google+
  • Martin HebelMartin Hebel Posts: 1,221
    edited 2006-09-26 - 23:04:52
    I Emailed with him last week about an article we are working on together. He's fine as far I know. But ask Chip, they are neighbors I believe. School is back in session, no more slack time for fun until the next break [noparse]:)[/noparse]

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
    AppBee - XBee ZigBee / IEEE 802.15.4 Adapters & Devices
  • PaulPaul Posts: 263
    edited 2006-11-21 - 15:37:13
    I was running Tracy Allen's Sinewave0.spin and thought I could bump the frequency to 10Hz. At 1Hz·I couldn't tell if it was a sinewave on the scope. By changing the line

    frqa := 54 to frqa := 537,· I am now getting a 10Hz noisy triangle waveform. I just started the Propeller last week and most of this clk,phsa,frqa is over my head.

    Is this because:

    1. Spin can't do sinewaves at this frequency? you will probably need assembly.

    2. The·sinewave is·made from 8000+ parts? Reduce this to a lower number·to lower the noise and get the sinewave back.

    3. The sinewave is really there , just buried in the noise.

    Thanks

    Paul

    UPDATE:
    ·A 0.1 uF capacitor to ground got rid of most the noise. Switching to sinewave3.spin and using the assembly routines did in fact enable audio frequencies. (10khz.)
    ·--Off to work on answer #2.
    UPDATE 2:
    · In Sinewave0.spin, I changed the Y to···
    y := x & $7ff * 2
    

    and got a much nicer sine wave. Just don't ask me why its nicer. Spin still limits this to < 150 Hz tho. Then it gets pretty choppy.

    Post Edited (Paul) : 11/21/2006 8:07:09 PM GMT
  • Tracy AllenTracy Allen Posts: 6,401
    edited 2006-11-22 - 02:13:32
    Hi Paul,

    Ahh, a typo/bug in my listing. It should be

    y := (x & $7ff) << 1 ' with parentheses

    Not
    y := x & $7ff << 1 ' <----WRONG!

    It has to do with the order of operations. The & is _supposed_ to be evaluated before the <<, but without parentheses the << is evaluated first. That also explains why your version with *2 in place of <<1 works, because * is evaluated after & in precedence. Thanks for the heads-up. I've now correctied the original program listing above too.

    With Spin I see a pretty good sine wave at 100 hz and below, but it gets ugly at 1000 hz and positively incoherent at 10khz. The pasm version is much faster and has no problem at audio frequencies. It does need the output filter, an RC or an LC or better. The underlying high frequency pulse density modulation needs to be filtered.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 11/22/2006 7:54:47 AM GMT
  • PaulPaul Posts: 263
    edited 2006-11-22 - 13:04:15
    Thanks Tracy!·The new sinewave0 looks pretty much like what I was expecting. ·But I wonder why the sinewave looks 'fat'. hmmm.
  • Technosaurus-RixTechnosaurus-Rix Posts: 2
    edited 2006-12-08 - 02:49:47
    Does anyone have, or could point me in the right direction, for a Mouse driver for the Demo Board. The driver with the Graphics object seems to use 4 pins instead of the Demo Boards 2.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Ric
  • [Deleted User][Deleted User] Posts: 0
    edited 2006-12-09 - 00:01:41
    Ric,
    Try this link for a wiring schematic

    Brian

    (you should ask questions in the main propeller forum)






    http://www.parallax.com/dl/docs/prod/prop/PropDemoDschem.pdf

    Post Edited (truckwiz) : 12/9/2006 1:46:24 AM GMT
  • squidxsquidx Posts: 33
    edited 2007-01-26 - 05:45:52
    Has anyone written any "beep" sounds? I would love to have a couple different pitched beeps for debugging or user feedback. I've begun to look at the frequency generation routines posted, but they are a bit over my head, and, I think, perhaps more demanding of cog resources than would be necessary for some quick-and-dirty buzzers.

    Any thoughts?
  • rjo_rjo_ Posts: 1,825
    edited 2007-04-19 - 19:34:06
    Hi,

    This taken from Chips's addnum_demo·object.· The only difference is that I put it into a single object... but the behavior is the same if it is left as in the demo.· When I consecutively display the value of xx to the screen the first time xx has the correct value (410)... but the next time it has a value (0).

    ?

    Rich

    CON

    · _CLKMODE = XTAL1 + PLL16X
    · _XINFREQ = 5_000_000

    OBJ
    · TERM : "TV_TERMINAL"
    · 'ASmADD : "ASMADD"
    var
    · long xx
    · long stack[noparse][[/noparse]30]
    PUB main | i
    · term.start(14)
    · term.out(13)
    · term.str(string("Value = "))
    · i:=addnums(10,400)
    · xx:=i··············
    · term.dec(xx)
    · term.out(13)
    · term.str(string("Value = "))
    · term.dec(xx)
    ·
    Pub AddNums(Num1,Num2)
    · Num1_:=Num1
    · Num2_:=Num2
    · cognew(@entry,@num1)

    Dat
    ······· org
    entry·· add Num1_,Num2_
    ······· wrlong Num1_,par
    ······ 'wrlong Num2_,par
    ······· CogId Cognum
    ······· CogStop Cognum

    Cognum· long 0
    Num1_·· long 0
    Num2_·· long 0
    ·
  • rjo_rjo_ Posts: 1,825
    edited 2007-04-20 - 14:48:59
    I'm missing a concept here[noparse]:)[/noparse]

    All we are doing is adding two numbers together... I get the result into i... place that value into xx... write it to the screen. No problem. But when I try to write it again... it's gone!

    xx is global... right? It doesn't seem like it could be a stack problem... unless there is something in the tv_terminal that isn't quite right... and I highly doubt that.

    Rich
  • rjo_rjo_ Posts: 1,825
    edited 2007-04-20 - 15:47:26
    This fixes it... but I don't understand why it needs to be fixed in the first place...

    And if I don't put a waitcnt in the terminal doesn't work right ... which I don't understand either.

    CON

    _CLKMODE = XTAL1 + PLL16X
    _XINFREQ = 5_000_000

    OBJ
    TERM : "TV_TERMINAL"
    var
    long xx

    PUB main | i

    xx[noparse][[/noparse]0]:=addnums(10,400)
    waitcnt(20000 +cnt)
    term.start(12)
    term.out(13)
    term.str(string("Value = "))
    term.dec(xx[noparse][[/noparse]0])
    term.out(13)
    term.str(string("Value = "))
    term.dec(xx[noparse][[/noparse]0])

    pub AddNums(Num1,Num2)
    Num1_:=Num1
    Num2_:=Num2
    cognew(@entry,@xx)

    Dat
    org
    entry add Num1_,Num2_
    wrlong Num1_,par
    CogId Cognum
    CogStop Cognum

    Cognum long 0
    Num1_ long 0
    Num2_ long 0
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-04-20 - 19:33:45
    Well firstly it was Beau's object and it was in the assembly code examples thread.

    That aside you get the same error in Beau's code as well if you add another output of the variable so I looked a bit more. As far as I can tell Beau's code should not work because he passes the assembly code an address to cog ram not hub ram. Also it makes the assumption that the cog will load and complete its business before the function returns.

    The following code works and I think will make sense. Note I put the newline commands in the strings for compactness only, the main difference is in the function.

    CON
    
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    
    OBJ
      TERM : "TV_TERMINAL"
      
    var
      long xx
      
    PUB main | i
      term.start(12)
      term.str(string(13,"Value = "))
      i:=addnums(10,400)              
      term.dec(i)
      term.str(string(13,"Value = "))
      term.dec(i)
     
    Pub AddNums(Num1,Num2)
      Num1_:=Num1
      Num2_:=Num2
      cognew(@entry,@xx)
      waitcnt(cnt+10000)
      return xx
    
    Dat
            org
    entry   add Num1_,Num2_
            wrlong Num1_,par
            CogId Cognum
            CogStop Cognum
    
    Cognum  long 0
    Num1_   long 0
    Num2_   long 0
    
    
    
  • rjo_rjo_ Posts: 1,825
    edited 2007-04-21 - 12:59:36
    Graham,

    Many, many thanks. I offered to show Scotta a method for accelerating exponential functions... and I got side tracked here... and decided not to move on until I understood what was going on...

    I (and I think you) would like a better understanding of exactly what is happening at the machine level in Beau's code... My problem was two fold... getting it to work at all and then understanding what actually was going on... the fact that the right number shows up for a moment...and then disappears is important. I should understand why, but I don't.

    AND... the fact that the terminal code works ... in my above example... only if a waitcnt is put in... seems to indicate that the right number returned in Beau's code is being overwritten by the process of calling the terminal code... but if it is that simple... why can't I write the number to a global to preserve it?

    So, there should be a clear mental picture of the process involved ... but I still don't have it.

    Again,

    Many thanks

    Rich
Sign In or Register to comment.