Hello, World :)
pik33
Posts: 2,416
In microcontroller world, "Hello" means blinking some leds. So I started to blink:
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?
[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

Comments
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.
then you can use them in your code like
or (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.
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
[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?
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
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 $00FF0000First 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)
Good progress here. Don't slow down!
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?)
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 $FFFFFFFFExpected: 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
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]:=$FFEdit: 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...