PASM need some help, ctra x 3
OlovA
Posts: 23
Hi. I want to use 3 input's for frequency counting ( P18,19,20 ),around· 100 KHz.
I tried to modify the code from AN001 but i cannot get the 2'nd and 3'd counter to work.
I just start to try to understand PASM, so probably my problem is in tha't part...
Okay, i'll try to insert "my" code here.
Thank's, Olov, Sweden...
I tried to modify the code from AN001 but i cannot get the 2'nd and 3'd counter to work.
I just start to try to understand PASM, so probably my problem is in tha't part...
Okay, i'll try to insert "my" code here.
Thank's, Olov, Sweden...
''Demonstration of the counter used as a frequency counter ' 20 mm = Khz ' 40 mm = ' P11 Down 3 ' P12 Up 3 ' P13 D2 ' P14 U2 ' P15 D1 ' P16 U1 ' P18 Sensor 1 ' P19 S2 ' P20 S3 ' P21 Kollision 1 ' P22 K2 ' P23 K3 ' P24 RS485 TXDE ' P25 TX ' P26 RX CON Vald_Hojd = 160000 Hysteres = 2000 _clkmode = xtal1 + pll16x _XinFREQ = 5_000_000 OBJ debug : "FullDuplexSerial" VAR long Akt_Hojd,Akt_Hojd2,Akt_Hojd3,Fq1,Fq2,Fq3 long CogStack1[noparse][[/noparse] 20] PUB Go Dira[noparse][[/noparse]11..16]~~ debug.start(31, 30, 0, 9600) cognew(@entry1, @fq1) 'New cog for the 1'st freq.counter cognew(@entry2, @fq2) ' 2'nd fq-counter cognew(@entry3, @fq3) ' 3'd fq-counter cognew(M1,@CogStack1) ' Routine for serial output of values repeat Akt_Hojd := fq1 Akt_Hojd2 := fq2 Akt_Hojd3 := fq3 If AKt_Hojd > Vald_Hojd + Hysteres ' För nära plåten OutA[noparse][[/noparse]16] := 0 OutA[noparse][[/noparse]15] := 1 elseif AKt_Hojd < Vald_Hojd - Hysteres ' För långt ifrån plåten OutA[noparse][[/noparse]16] := 1 OutA[noparse][[/noparse]15] := 0 else OutA[noparse][[/noparse]16] := 0 OutA[noparse][[/noparse]15] := 0 PUB M1 repeat waitcnt(ClkFreq * 1 + cnt) 'wait 1 seconds then set MyVar to value 1 debug.str(string("Fq1 = ")) ' Send to the PC debug.dec(Akt_Hojd) debug.str(string("Fq2 = ")) debug.dec(Akt_Hojd2) debug.str(string("Fq3 = ")) debug.dec(Akt_Hojd3) debug.Tx(13) DAT org entry1 mov ctra, ctra_1 'establish mode and start counter mov frqa, #1 'increment for each edge seen mov cnt_1, cnt 'setup time delay add cnt_1, cntadd1 :loop1 waitcnt cnt_1, cntadd1 'wait for next sample mov new1, phsa 'record new count mov temp1, new1 'make second copy sub new1, old1 'get delta mov old1, temp1 'set next delta's base wrlong new1, par jmp #:loop1 entry2 mov ctra, ctra_2 'establish mode and start counter mov frqa, #1 'increment for each edge seen mov cnt_2, cnt 'setup time delay add cnt_2, cntadd2 :loop2 waitcnt cnt_2, cntadd2 'wait for next sample mov new2, phsa 'record new count mov temp2, new2 'make second copy sub new2, old2 'get delta mov old2, temp2 'set next delta's base wrlong new2, par jmp #:loop2 entry3 mov ctra, ctra_3 'establish mode and start counter mov frqa, #1 'increment for each edge seen mov cnt_3, cnt 'setup time delay add cnt_3, cntadd3 :loop3 waitcnt cnt_3, cntadd3 'wait for next sample mov new3, phsa 'record new count mov temp3, new3 'make second copy sub new3, old3 'get delta mov old3, temp3 'set next delta's base wrlong new3, par jmp #:loop3 fit 496 ctra_1 long %01010 << 26 + 18 'mode + APIN cntadd1 long 80_000_000 'wait 0,1 second, answer in Hz/10 ctra_2 long %01010 << 26 + 19 'mode + APIN cntadd2 long 80_000_000 'wait 0,1 second, answer in Hz/10 ctra_3 long %01010 << 26 + 20 'mode + APIN cntadd3 long 80_000_000 'wait 0,1 second, answer in Hz/10 cnt_1 res 1 new1 res 1 old1 res 1 temp1 res 1 cnt_2 res 1 new2 res 1 old2 res 1 temp2 res 1 cnt_3 res 1 new3 res 1 old3 res 1 temp3 res 1
Comments
eg
' set the PASM variables
ctra_1 := %01010<<26 + 18
dest_1 := @spin_variable_1
cognew( @entry, doesn matter )
ctra_1 := %01010<<26 + 19
dest_1 := @spin_variable_2
cognew( @entry, doesnt matter )
ctra_1 := %01010<<26 + 20
dest_1 := @spin_variable_3
cognew( @entry, doesnt matter )
You may have to do some more book-keeping, depending on how you rewrite the PASM code.
Cheers!