Using an array
Harley
Posts: 997
I need to hand off a variable from Spin to PASM. I planned to use a spare location in an array already in place. But I get an error message of Expected a constant, unary operator, or "(". This was working OK prior to adding 'Nsamp' variable. I'm sure I've gotten into this fix before, but don't recall what it took to make things work. Wish it were simpler to work with cogs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
A2D or DIRA,Msk20 ' make A20 an output or DIRA,asm_dira ' make A2 (pin 3) an output for A/D movs CTRA,#adcpin movd CTRA,#fbpin ' movi CTRA,#%01001_000 ' POS detector on Apin w/feedback on Bpin mov FRQA,#1 mov avg,#avg_init ' start w/ 60 bpm pulst average :initLoop mov hpix,#128 'count 128 samples/width of screen mov _ptr,PAR ' pickup 'value' ptr to 'A2Dbuf' array add _ptr,#4 ' step past location 0 of 'period' [b] rdlong Nsamp,_ptr ' get value @ second location[/b] <<<<<<<--- error line add _ptr,#4 ' step past to 1st A/D array location mov flag,#0 ' clear flag each loop through array mov asm_cnt,CNT add asm_cnt,asm_cycles :loop0 mov samp_ct,Nsamp :loop WAITCNT asm_cnt,asm_cycles ' wait for next CNT value mov asm_sample,PHSA xor OUTA,Msk20 ' toggle A20 for A/D time marker TEMP sub asm_sample,asm_old ' WHAT'S THIS DOING ???? add asm_old,asm_sample djnz samp_ct,#:loop wrlong asm_sample,_ptr ' store a sample mov samp_ct,Nsamp cmp asm_sample,threshold wc ' Now, test if at/over THRESHOLD if_b jmp #:exit ' exit if below threshold ' jmp #:exit ' JUSY A TEST !!! mov ptr_old,_ptr ' then, check if a peak POSITION sub ptr_old,PAR ' is more than sub ptr_old,#20 wc ' the horiz limit (5 positions; 20/4 longs) and flag,#1 wz ' test if flag set (= 1) '' jmp #:no_move if_c_or_nz jmp #:no_move ' exit if left of limit or flag set (4*3=20) ':mov_It xor OUTA,Msk20 ' toggle time marker LO TEMP shr ptr_old,#2 ' get offset in 'pixels'; divide by 4 add hpix,ptr_old ' correct remaining 'hpix' count mov ptr_old,_ptr ' get last ptr value INIT for MOVE sub ptr_old,#20 ' adjust for 5 locations prior mov _ptr,PAR ' set ptr to left of array/screen add _ptr,#4 ' of array (= to left of screen; 2nd loc. mov ctr,#5 ' set ctr to move 5 longs of data (8*4=32) [img]http://forums.parallax.com/images/smilies/tongue.gif[/img]os_loop rdlong temp,ptr_old ' get old value DO the MOVE TO LEFT wrlong temp,_ptr ' to left side add ptr_old,#4 ' increment both add _ptr,#4 ' from and to pointers djnz ctr,#[img]http://forums.parallax.com/images/smilies/tongue.gif[/img]os_loop ' loop until all data moved (4*8*5=160) sub last_cnt,#196 ' fix mov_It CNTs lost (1*4=4; 32+160+4=196) :no_move sub last_cnt,#20 ' fix for CNTs before jmp to no move(1*4=4) ' mov tmp2,CNT ' get sys ctr mov temp,tmp2 ' save for later use sub temp,last_cnt ' form 'period' (last - previous CNTs) mov last_cnt,tmp2 ' update last_cnt mov tmp2,avg ' get last period average shr tmp2,#5 ' only 1/32 value (remove 1/32nd last avg) sub avg,tmp2 ' reduce by that amount mov tmp2,temp ' get last period value shr tmp2,#5 ' only 1/32 of it (add 1/32nd new period add avg,tmp2 ' add back to average wrlong avg,PAR ' write for Spin (display pulse rate) mov flag,#1 ' set flag :exit add _ptr,#4 ' now increment pointer to next long djnz hpix,#:loop ' loop until done rdbyte tmp2,atr_ptr ' clear A2D gets done' flag andn tmp2,#16 ' clear 'A2D done' flag; for ST7920 update display wrbyte tmp2,atr_ptr { mov pause,sec :dly nop nop djnz pause,#:dly } jmp #:initLoop ' back to top' ' Initialized data asm_cycles long |< bits - 1 ' sample time (20 bits = 13.1 ms; 76.294/min) asm_dira long |< fbpin ' output mask threshold LONG |< bits - 1 '$08_0000 ' 1/2 full value TRY '|< (bits-1)' 'threshold LONG $08_0000 ' 1/2 full value TRY '|< (bits-1)' avg_init LONG 80_000_000 ' = 1 beat/sec initial value (4C4B00 counts) Msk20 LONG |<20 ' A/D time marker on pin A20 for sec LONG 8_000 ' one second of sys clock ticks atr_ptr LONG atr ' Uninitialized data _ptr RES 1 ' holds pointer to PAR, for 1000 long samples ptr_old RES 1 avg RES 1 ' holds average of period flag RES 1 ' flag for 1st value > threshold temp RES 1 ' working reg for measuring period tmp2 RES 1 ' another TEMP reg last_cnt RES 1 ' used for last count of period hpix RES 1 ' #samples counter asm_cnt RES 1 ' holds asm_cycles and CNT asm_old RES 1 ' holds old value from last sample asm_sample RES 1 ' 'amplitude' of sample ctr RES 1 pause RES 1 samp_ct RES 1 ' 'divider' of A/D samples Nsamp RES 1 FIT 496
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
Comments
There's nothing obviously wrong with either the line you marked or the declaration of Nsamp later (RES). Could you have Nsamp declared somewhere else in your program? Next time please attach your source code rather than cutting and pasting into a code block.
I'm running under Parallels on an iMac and find it a chore to move a source file from Windows to Mac OS for some reason. So figured it would be better to just post this snippet, as the program prints to 11 pages. Apologies.
Thanks MagIO2 too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
I do use PASD and Viewport a lot. Wish they were also written to run on the Mac. I'll look into BST. Thanks for the recommendation, Mike.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
(I love Brad's inclusion of ifdefs) but I can't seem to debug with PASD unless I am using the Parallax IDE. So no more BST and ifdefs .... sigh.
Note to Brad if he sees this: Can we code fold based on defines ala emacs? or even manually if you put the +- box by the ifdefs