Help - I've forgotten how to code PASM
Dr_Acula
Posts: 5,484
This is a bit embarrassing to ask but I can't seem to get a pin to change state in pasm and I would be most appreciative if some kind soul could look over my (almost certainly incorrect) code. I've been working with some very complex code driving a touchscreen but a simple pin toggle has failed and so I've ended up simplifying the code right back to something very basic.
I'm sure it is something simple. Problem can be replicated on two boards. Pin 22 is not connected to anything else except a 10k pullup.
Spin seems to work fine.
and set the pin low again
So, port this over to pasm using a driver that cluso wrote years ago and which has always worked fine. Start the cog and initialise the routine. Send a command and it jumps to a line that does this
There is a halt just after this which correctly halts the cog, and returns control to spin (correctly) if you remove the halt.
I tried swapping propeller chips. I also tried putting "zero" instead of "low22" and all the other pins go low. Just not pin 22.
There is a 10k pullup on this pin, but this is not enough to light the led when the pin is set low in spin.
I've tried swapping hardware to a different board though the fact that this works in spin does go against a hardware problem. But nothing is impossible!
Other pins seem to work ok.
Right now I need a sanity check - if the error is not obvious, would someone be kind enough to just run the code below and let me know if P22 is high or low? (I think that mov outa,low22 should make it low but it is not)
Many thanks in advance.
I'm sure it is something simple. Problem can be replicated on two boards. Pin 22 is not connected to anything else except a 10k pullup.
Spin seems to work fine.
DIRA := %00000000_11111111_11111111_11111111 ' enable these pins for output OUTA := %00000000_01000000_00000000_00000000 ' set pin 22 high
and set the pin low again
OUTA := %00000000_10111111_11111111_11111111 ' set pin 22 low
So, port this over to pasm using a driver that cluso wrote years ago and which has always worked fine. Start the cog and initialise the routine. Send a command and it jumps to a line that does this
mov outa,low22 ' always pin P22 is high no matter what you send out. low22 long %00000000_10111111_11111111_11111111
There is a halt just after this which correctly halts the cog, and returns control to spin (correctly) if you remove the halt.
I tried swapping propeller chips. I also tried putting "zero" instead of "low22" and all the other pins go low. Just not pin 22.
There is a 10k pullup on this pin, but this is not enough to light the led when the pin is set low in spin.
I've tried swapping hardware to a different board though the fact that this works in spin does go against a hardware problem. But nothing is impossible!
Other pins seem to work ok.
Right now I need a sanity check - if the error is not obvious, would someone be kind enough to just run the code below and let me know if P22 is high or low? (I think that mov outa,low22 should make it low but it is not)
Many thanks in advance.
' Test pin 22 in a pasm routine CON _clkmode = xtal1 + pll16x ' use crystal x 16 _xinfreq = 5_000_000 VAR long command, hubaddrs, ramaddrs, blocklen, errx, cog ' rendezvous between spin and assembly (can be used cog to cog) PUB Main start_ram ' start the cog driver DIRA := %00000000_11111111_11111111_11111111 ' enable these pins for output OUTA := %00000000_01000000_00000000_00000000 ' set pin 22 high prior to running cog code docmd("A",0,0,0) ' send a command to the cog OUTA := %00000000_10111111_11111111_11111111 ' should never get here if pasm halts repeat PUB start_ram : err_ command := "I" cog := 1 + cognew(@tbp2_start, @command) if cog == 0 err_ := $FF ' error = no cog else repeat while command ' driver cog sets =0 when done err_ := errx ' driver cog sets =0 if no error, else xx = error code PUB stop_ram if cog cogstop(cog~ - 1) PUB DoCmd(command_, hub_address, ram_address, block_length) : err_ hubaddrs := hub_address ' hub address start ramaddrs := ram_address ' ram address start blocklen := block_length ' block length command := command_ ' must be last !! ' Wait for command to complete and get status repeat while command ' driver cog sets =0 when done err_ := errx ' driver cog sets =0 if no error, else xx = error code DAT org 0 tbp2_start ' setup the pointers to the hub command interface (saves execution time later ' +-- These instructions are overwritten as variables after start comptr mov comptr, par ' -| hub pointer to command hubptr mov hubptr, par ' | hub pointer to hub address ramptr add hubptr, #4 ' | hub pointer to ram address lenptr mov ramptr, par ' | hub pointer to length errptr add ramptr, #8 ' | hub pointer to error status cmd mov lenptr, par ' | command I/R/W/G/P/Q hubaddr add lenptr, #12 ' | hub address ramaddr mov errptr, par ' | ram address len add errptr, #16 ' | length err nop ' -+ error status returned (=0=false=good) init mov err, #0 ' reset err=false=good done wrlong err, errptr ' status =0=false=good, else error x wrlong zero, comptr ' command =0 (done) pause rdlong cmd, comptr wz ' command ? if_z jmp #pause ' not yet ' decode command cmp cmd, #"A" wz ' move a block from ram to the display if_z jmp #moveblock cmp cmd, #"I" wz ' init if_z jmp #init mov err, cmd ' error = cmd (unknown command) jmp #done ' ------------------ Commands ---------------------------- Moveblock mov dira,dirpins mov outa,low22 ' always pin P22 is high no matter what you send out. jmp #halt ' should never get here with the halt jmp #init halt jmp #halt zero long %00000000_00000000_00000000_00000000 low22 long %00000000_10111111_11111111_11111111 dirpins long %00000000_11111111_11111111_11111111 fit 496
Comments
I was so close inside the pasm part that I forgot about looking at the spin part.
I think that solves the problem!
Thanks++
Well thanks to your help I've managed to speed up the refresh on the touchscreen from 9 seconds to 30 milliseconds.
I am very grateful for your timely help - I was almost at the hair-pulling stage!