Shop OBEX P1 Docs P2 Docs Learn Events
Hello, World :) — Parallax Forums

Hello, World :)

pik33pik33 Posts: 2,398
edited 2012-04-27 09:06 in Propeller 1
In microcontroller world, "Hello" means blinking some leds. So I started to blink:
[FONT=courier new]con delay=40000


pub start
coginit (1,@proc,delay)

dat[/FONT]

[FONT=courier new]proc    mov 489,#3
        shl 489,#16
        mov dira,489

loop3   mov 490,par
        shl 490,#4
        mov 489,#1
        shl 489,#16
        mov outa,489
loop    djnz 490,#loop
        mov 489,#1
        shl 489,#17
        mov outa,489
        mov 490,par
        shl 490,#4
loop2   djnz 490,#loop2

        jmp #loop3[/FONT]

maybe in some strange way, but it blinks :) And I discovered that I cannot pass more than 16-bits delay value via coginit. Where is this value truncated?

Comments

  • LeonLeon Posts: 7,620
    edited 2012-04-18 05:57
    The coginit parameter is only 14-bits. See the documentation.
  • Heater.Heater. Posts: 21,230
    edited 2012-04-18 05:59
    pik33,

    Good start. No idea what is going on there but I would suggest that you declare some longs in your cog rather than use numerical addresses.

    Put them at the end of your code.
    someVariableName    long    0
    otherVariableName     long    0
    
    then you can use them in your code like
         mov     someVariableName, #1
    
    or
                 mov     outa, otherVariableName
    
    (Note the lack of a # in that, everyone always makes mistakes with # or not.)

    For completeness an ORG at the begining of PASM is a good idea and a FIT at the end.

    Oh yeah, normally one would use cognew instead of coginit. It's not often you actually need to start a specific cog and if you are mixing and matching code from here and there it avoids any conflicts over which object uses which cog.
  • RS_JimRS_Jim Posts: 1,768
    edited 2012-04-18 06:02
    Congratulations,
    When you pass a literal, you can only pass 9 bits, refer to asm manual. If you need to use a larger value, you need to set it up as a var at compile time.
    Delay. Long. 32bitvalue

    Jim
  • pik33pik33 Posts: 2,398
    edited 2012-04-20 05:49
    Tried to get sawform wave on led using counters:
    [FONT=courier new]pub start
    
    mode_a:=$18000000+16 'set counter A to duty mode on pin 16
    mode_b:=$10000000    'set counter B to NCO mode
    freq:=100            'should be about 1.9 Hz, why it is 0.3 Hz??
    
    
    cognew(@proc,@mode_a)
    
    dat
    
    proc    org   0
    
            mov   temp1,#1
            shl   temp1,#16
            mov   dira,temp1
    
    'init counter a
            mov   ctra,mode_a
            mov   phsa,#0
            mov   frqa,#1
    'init counter b
            mov   ctrb,mode_b
            mov   phsb,#0
            mov   frqb,freq
    
    'get sawform value
    
    loop    mov   temp1,phsb
            mov   frqa,temp1
            jmp   #loop
    
    mode_a  long 0
    mode_b  long 0
    freq    long 0
    temp1   long 0[/FONT]
    

    and it works, giving a led on pin p16 blinking with sawform way. But why is frequency about 0.3 Hz, when I supposed 1.8 Hz?

    Counting:frqb=$80000000 => 40MHz
    frqb=1 =>40000000/$80000000 => 0.0186Hz
    frqb=100 =>1.86 Hz

    Where am I wrong with this counting and this code?
  • kuronekokuroneko Posts: 3,623
    edited 2012-04-20 05:56
    pik33 wrote: »
    Where am I wrong with this counting and this code?
    Doing the math (frequency ratio ~6.2) it looks like you're running with RCFAST (~13MHz). Just add the proper _clkmode/_xinfreq setup.
  • pik33pik33 Posts: 2,398
    edited 2012-04-20 07:08
    Added
    con
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    

    Now it works OK. Time to change pin from 16 to 11 and try some beeps :)

    Edit - changed pin to 11 and freq to 53*440. Now it beeps :)
  • pik33pik33 Posts: 2,398
    edited 2012-04-22 12:09
    Say hello to VGA :)
    CON
    
      _clkmode = xtal1+pll16x
      _clkfreq = 80_000_000
    
    
    pub start(bufor)
    
    cognew(@vga_start,@bufor)
    
    
    dat
    vga_start               org               0
    
    init_vga
                            mov dira,pinmask
                            mov ctra,#0
                            movi ctra,#%0_00001_110 'pll div 2
                            mov frqa,frqa_val       '6 MZz
                                                    'now we have 48 MHz pixel clock
                            mov vscl,vscl_val
                            mov vcfg,vcfg_val
    
    frame                   mov l_count,#25          '25 lines of back porch
    bp_loop                 call #blank_line
                            djnz l_count,bp_loop
                            mov l_count,#100        ' 100 lines of upper border
    up_frm_loop             call #frame_line
                            djnz l_count,up_frm_loop
                            mov l_count,#400         '400 lines picture
    line_loop               call #normal_line
                            djnz l_count,line_loop
                            mov l_count,#100        ' 100 lines of lower frame
    d_frm_loop              call #frame_line
                            djnz l_count,d_frm_loop
                            mov l_count,#25          '25 lines of front porch
    fp_loop                 call #blank_line
                            djnz l_count,fp_loop
                            mov l_count,#10          '10 lines of vsync porch
    vbl_loop                call #vsync_line
                            djnz l_count,vbl_loop
                            jmp  #frame
    
    blank_line              mov p_count,#34
    bl1                     waitvid blank_color,blank_pixels  '32 px@48 MHz - 53 cycles @80 MHz between waitvids
                            djnz p_count,#bl1
                            mov p_count,#3
    bl2                     waitvid hblk_color,blank_pixels
                            djnz p_count,#bl2
    blank_line_ret          ret
    
    vsync_line              mov p_count,#34
    vl1                     waitvid vblank_color,blank_pixels  '32 px@48 MHz - 53 cycles @80 MHz between waitvids
                            djnz p_count,#vl1
                            mov p_count,#3
    vl2                     waitvid vhblk_color,blank_pixels
                            djnz p_count,#vl2
    vsync_line_ret          ret
    
    frame_line              mov p_count,#2                       'back porch
    fl1                     waitvid blank_color,blank_pixels
                            djnz p_count,#fl1
                            mov p_count,#30                      '960 pixels of border
    fl2                     waitvid border_color,blank_pixels
                            djnz p_count,#fl2
                            mov p_count,#2                       'front porch
    fl3                     waitvid blank_color,blank_pixels
                            djnz p_count,#fl3
                            mov p_count,#3                        'hsync
    fl4                     waitvid hblk_color,blank_pixels
                            djnz p_count,#fl4
    frame_line_ret          ret
    
    
    normal_line             mov p_count,#2                       'back porch
    nl1                     waitvid blank_color,blank_pixels
                            djnz p_count,#nl1
                            mov p_count,#5                       '160 pixels of border
    nl2                     waitvid border_color,blank_pixels
                            djnz p_count,#nl2
                            mov p_count,#20                      '640 pixels of picture, now blank
    nl3                     waitvid back_color,blank_pixels
                            djnz p_count,#nl3
                            mov p_count,#5                       '160 pixels of border
    nl4                     waitvid border_color,blank_pixels
                            djnz p_count,#nl4
                            mov p_count,#2                       'front porch
    nl5                     waitvid blank_color,blank_pixels
                            djnz p_count,#nl5
                            mov p_count,#3                        'hsync
    nl6                     waitvid hblk_color,blank_pixels
                            djnz p_count,#nl6
    normal_line_ret         ret
    
    
    
    l_count                 long    0
    p_count                 long    0
    frqa_val                long    $15555555       '6 MHz
    vscl_val                long    $00001020       '1 clock/pixel, 32 clock/frame
    vcfg_val                long    $200004ff       'video vga, 2 colors, 16..23
    blank_color             long    $03030303       'high sync
    hblk_color              long    $01010101       'hblk, hsync low
    vhblk_color             long    0               'all sync low
    vblank_color            long    $02020202       'vsync low
    border_color            long    $3F3F3F3F       'blue-green?
    back_color              long    $0F0F0F0F       'blue?
    blank_pixels            long    0
    pinmask                 long    $00FF0000
    

    First attempt to access vga, successful. Will try to write a nostalgic vga driver, with borders.
    Now it displays only background color, 640x400 2-colors window on 960x600 screen (my monitor is 1920x1200, so I made 1/2 of these)
  • kuronekokuroneko Posts: 3,623
    edited 2012-04-23 02:23
    CON
    
      _clkmode = xtal1+pll16x
      _clkfreq = 80_000_000
    
    ...
    
    frqa_val                long    [B]$15555555[/B]       '6 MHz
    
    At 80MHz this frqx setup will give you 1/12 of the system clock as PLL input (6.67MHz). Some math gone wrong? :)

    Good progress here. Don't slow down!
  • pik33pik33 Posts: 2,398
    edited 2012-04-23 02:55
    Yes, it was something wrong with hex math, it was too late evening :)

    This code gives too much border; I updated this to get 640x400 screen on 720x480 border. It looks much better now, and clock is 30.625 MHz (pll/4, $1880_0000 as frqa_val). And it gives more time between waitvids.

    Now I am struggling with basics of Spin, to add a frame buffer and character definitions. (is there any Spin tutorial somewhere?)
  • pik33pik33 Posts: 2,398
    edited 2012-04-23 04:39
    Stuck with basic Spin stuff. :(
    CON
    
      _clkmode = xtal1+pll16x
      _clkfreq = 80_000_000
    
    
    var
    byte buf[2000]
    
    pub demo
    buf_init(buf)
    start(buf)
    
    
    pub buf_init(bufor) |i
    
    repeat i from 0 to 1999
      bufor[i]:=$FF
    
    pub start(bufor)
    
    cognew(@vga_start,bufor)
    
    
    dat
    vga_start               org               0
    
    init_vga
    
                            mov dira,pinmask
                            mov ctra,#0
                            movi ctra,#%0_00001_101 'pll div 4
                            mov frqa,frqa_val       '
                                                    '
                            mov vscl,vscl_val
                            mov vcfg,vcfg_val
    
    frame                   mov buffer_addr,par
    
                            mov l_count,#15          '15 lines of back porch
    bp_loop                 call #blank_line
                            djnz l_count,bp_loop
                            mov l_count,#40          '40 lines of upper border
    up_frm_loop             call #frame_line
                            djnz l_count,up_frm_loop
                            mov l_count,#400         '400 lines picture
    line_loop               call #normal_line
                            djnz l_count,line_loop
                            mov l_count,#40         '40 lines of lower frame
    d_frm_loop              call #frame_line
                            djnz l_count,d_frm_loop
                            mov l_count,#15          '15 lines of front porch
    fp_loop                 call #blank_line
                            djnz l_count,fp_loop
                            mov l_count,#15          '15 lines of vsync
    vbl_loop                call #vsync_line
                            djnz l_count,vbl_loop
                            jmp  #frame
    
    blank_line              mov p_count,#28
    bl1                     waitvid blank_color,blank_pixels  '32 px@30.625 MHz - 83 cycles @80 MHz between waitvids
                            djnz p_count,#bl1
                            mov p_count,#3
    bl2                     waitvid hblk_color,blank_pixels
                            djnz p_count,#bl2
    blank_line_ret          ret
    
    vsync_line              mov p_count,#28
    vl1                     waitvid vblank_color,blank_pixels
                            djnz p_count,#vl1
                            mov p_count,#3
    vl2                     waitvid vhblk_color,blank_pixels
                            djnz p_count,#vl2
    vsync_line_ret          ret
    
    frame_line              mov p_count,#2                       'back porch
    fl1                     waitvid blank_color,blank_pixels
                            djnz p_count,#fl1
                            mov p_count,#24                      '768 pixels of border
    fl2                     waitvid border_color,blank_pixels
                            djnz p_count,#fl2
                            mov p_count,#2                       'front porch
    fl3                     waitvid blank_color,blank_pixels
                            djnz p_count,#fl3
                            mov p_count,#3                        'hsync
    fl4                     waitvid hblk_color,blank_pixels
                            djnz p_count,#fl4
    frame_line_ret          ret
    
    
    normal_line             mov buffer_addr,par
    
                            mov p_count,#2                       'back porch
    nl1                     waitvid blank_color,blank_pixels
                            djnz p_count,#nl1
                            mov p_count,#2                       '64 pixels of border
    nl2                     waitvid border_color,test_pixels
                            djnz p_count,#nl2
                            mov p_count,#20                      '640 pixels of picture, now blank
    
    nl3                     rdlong temp_buff,buffer_addr       '4 bytes to cog memory
    
                            or temp_buff,blank_color           ' be sure sync is high
    
                            add buffer_addr,#4
                            waitvid temp_buff,test_pixels
                            djnz p_count,#nl3
    
    
                            mov p_count,#2                       '64 pixels of border
    nl4                     waitvid border_color,blank_pixels
                            djnz p_count,#nl4
                            mov p_count,#2                       'front porch
    nl5                     waitvid blank_color,blank_pixels
                            djnz p_count,#nl5
                            mov p_count,#3                        'hsync
    nl6                     waitvid hblk_color,blank_pixels
                            djnz p_count,#nl6
    normal_line_ret         ret
    
    
    
    l_count                 long    0
    p_count                 long    0
    frqa_val                long    $18800000       '7.65625 MHz
    vscl_val                long    $00001020       '1 clock/pixel, 32 clock/frame
    vcfg_val                long    $200004ff       'video vga, 2 colors, 16..23
    blank_color             long    $03030303       'high sync
    hblk_color              long    $01010101       'hblk, hsync low
    vhblk_color             long    0               'all sync low
    vblank_color            long    $02020202       'vsync low
    border_color            long    $4f4f4f4f       'violet
    back_color              long    $03030303       'blue?
    blank_pixels            long    0
    pinmask                 long    $00FF0000
    buffer_addr             long    0
    temp_buff               long    $0000c30f
    test_pixels             long    $0000FFFF
    test_ff                 long    $FFFFFFFF
    
    

    Expected: white screen (buffer filled with $FF)
    Got: vertical color bars.

    Edit:found error: add buffer_addr,4; should be #4
    Still get color vertical bars
  • kuronekokuroneko Posts: 3,623
    edited 2012-04-23 06:03
    Try this:
    pub demo
    buf_init(@buf[COLOR="#D3D3D3"]{0}[/COLOR])
    start(@buf[COLOR="#D3D3D3"]{0}[/COLOR])
    
    
    pub buf_init(bufor) |i
    
    repeat i from 0 to 1999
      byte[bufor][i]:=$FF
    
    
  • pik33pik33 Posts: 2,398
    edited 2012-04-23 06:15
    Now screen is white :) I only had to understand this syntax...
  • pik33pik33 Posts: 2,398
    edited 2012-04-27 09:06
    I had no free time to program, but now, I added a sd card to the demo board. :) Next to add: 4x 32k256.

    Waiting for key press to start tests
    
    Mount tests first
    First mount.
    Succeeded; stopping cog.
    Second mount.
    Succeeded.
    Reading block 0 (should be a boot block)
    Read finished; checking for boot block signature
    Boot block checks out; unmounting
    Third mount.
    Succeeded.
    Reading block 0 again (should still be a boot block)
    Read finished; checking for boot block signature
    Boot block checks out; writing it back
    Write finished; unmounting
    Fourth mount.
    Succeeded.
    Reading block 0 again (should still be a boot block)
    Read finished; checking for boot block signature
    Block layer seems to check out
    Now speed tests
    How fast can we write, sequentially?
    Raw write 3968 kB in 3018 ms at 1314 kB/s
    Do a single non-sequential write...Done
    How fast can we read, sequentially?
    Raw read 1920 kB in 2186 ms at 878 kB/s
    Now the filesystem tests
    Trying to mount
    Mounted.
    How fast can we write using pwrite?
    fsrw pwrite 2016 kB in 2470 ms at 816 kB/s
    How fast can we read using pread?
    fsrw pread 2016 kB in 2300 ms at 876 kB/s
    How fast can we write using pputc?
    FSRW pputc 63 kB in 2097 ms at 30 kB/s
    How fast can we read using pgetc?
    FSRW pgetc 63 kB in 1838 ms at 34 kB/s
    Repeating all the speed results:
    
    Clock: 80000000 ClusterSize: 32768 ClusterCount: 123586
    Raw write 3968 kB in 3018 ms at 1314 kB/s
    Raw read 1920 kB in 2186 ms at 878 kB/s
    fsrw pwrite 2016 kB in 2470 ms at 816 kB/s
    fsrw pread 2016 kB in 2300 ms at 876 kB/s
    FSRW pputc 63 kB in 2097 ms at 30 kB/s
    FSRW pgetc 63 kB in 1838 ms at 34 kB/s
    All done!
    

    Edit: test from fsrw 2.6 works (see code section). FemtoBasic cannot mount this card. It is 4GB, FAT32, SDHC card.

    Edit 2: just read about FemtoBasic doesn't support SDHC. Need to use smaller card. Or try to add this http://obex.parallax.com/objects/619/ driver...
Sign In or Register to comment.