Simultaneous pin outputs

Iponder

New Member
Hello
Apologies if this is a daft question!
I am playing with the 08M chip and I wondered if I could make two output pins go high at the same time?
Nothing in the manual (I think!)
So I separated the pins with a comma like this...

high 4,2

This seems to work, but does this mean that pin 4 goes high before pin 2?
Academic question at the moment, but may be best to find out now for future experiments where this could be critical?
Or is there a "proper" way to do it?
All the best
 

hippy

Ex-Staff (retired)
Yes, "High 4,2" will set pin 4 slightly before pin 2. The simultaneous way is to use "LET pins=".

That will set both pins simulatenously to all intents and purposes, that is, so closely together you likely won't be able to tell unless you look in pico-second timescales.
 

westaust55

Moderator
PICAXE Manual 2 (rev 6.7) page 59 indictaes that you can use the one HIGH command to bring several pins high at the same time.
high
Syntax:
HIGH pin {,pin,pin...}
- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
the part in braces (curly brackets: {} ) indicates it is optional AND legal.

If you look at page 106 you will find that the same also applies to the LOW command.
 
Last edited:

hippy

Ex-Staff (retired)
That's really a colloquial "at the same time", together but not simultaneously, and it is correct within the timespan of the statement's overall execution period, but the pins will be taken high ( low, toggled etc ) in the order specified with a short delay between them.
 

Dave E

Senior Member
Let's see

Let's set this up and see what we can see.......

08M running at 5V and 4 MHz:

High 1,2
Takes about 290 uS (0.00029 sec) between output 1 going high and output 2 going high.
Same going low.

Let PINS = %110
Can't see a difference even with the scope set to 50 nS/div. So this does happen at the same time.

Hope this helps.

Dave E
 

jglenn

Senior Member
Doesn't Let pins need all 8 bits? Having 3 bits works? The problem with it, although it takes less memory use than High or Low, is that what if you only want to just change one bit with Let pins? Getting into masking is a lot of trouble.
 

lbenson

Senior Member
With that timing, there would seem to be a fair chance that
high 1,2
is interpreted into the same code as
high 1
high 2
 

Dave E

Senior Member
Let's see again

With the same set up as above....

High 1
High 2

has the same timing as

High 1,2

and uses the same amount of memory. So it does look like they are interpreted the same way.

Dave E
 

hippy

Ex-Staff (retired)
@ lbenson, Dave E : Correct. "HIGH a,b,c" is a convenient shorthand for those PICAXE programmers who want to use that and who had asked for it to be supported.

@ jglenn : to use "LET pins=" and not adversely affect existing pins it's necessary to set the pins not to be changed to what they already are. READOUTPUTS is convenient for that. To set pins 1 and 2 high, leave the others as they are we can stage the operation through b0 and use the bit variables ( or OR operator etc ) ...

ReadOutputs b0
bit1 = 1
bit2 = 1
pins = b0
 

westaust55

Moderator
That's really a colloquial "at the same time", together but not simultaneously, and it is correct within the timespan of the statement's overall execution period, but the pins will be taken high ( low, toggled etc ) in the order specified with a short delay between them.

True hippy.

I was more aiming at the sentence Iponder gave:
" Nothing in the manual (I think!)"

Thereafter time/delays are relative to what one is trying to achieve.
 

Iponder

New Member
Hello all
Thanks for all your help.
At least my question might be helping other members as well.
I was going to check it on my scope, but it is a bit rickety (broken control knob, but still workable... just!)
Thanks again
 

jglenn

Senior Member
To set pins 1 and 2 high, leave the others as they are we can stage the operation through b0 and use the bit variables ( or OR operator etc ) ...

ReadOutputs b0
bit1 = 1
bit2 = 1
pins = b0

Hippy: thanks for response, be patient as I try to digest this, as transitioning from decades of assem programming to the much more enjoyable Basic. Ways of doing some things seem different. Using the output port as a register is new to me, normally output bits exist in their own register, and are sent to the output port when rqrd. I have never needed to "read" the output port, but I guess it can be done. PICs have an assem cmd of SETB and CLRB which are used to control single output bits. The same as your High and Low, which I am fine with using for digital control, but the manual says it saves code space to use Let pins.

This seemed more cumbersome due to having to specify all 8 bits at once (or do you?).

???Let pins = %010xxx10.....wish I could do this.

I have no problem with the 4 lines of code you list to just change 2 bits, other than it takes 4 commands. That's a millisecond execution time versus the .25mS of a single Let pins line, right? Sometimes I need to go fast, in assembly we are always cognizant of every byte, at least I am.Habit.

Have been getting good results with a/d input and output tests, looking at doing most digital I/O with I2C, other than for small apps. The PCA9555 chips from TI might fit the bill. Thanks for any help, on how do do fast efficient single bit I/O, without fancy XOR etc. :rolleyes:
 
Last edited:

hippy

Ex-Staff (retired)
Basic is usually somewhat different to assembler because you are not only communicating with the hardware but also the firmware itself. The READOUTPUTS trick is in many ways the same as -

MOVF PORTB,W
IORLW 0x01
IORLW 0x02
MOVWF PORTB

However, because reading the actual outputs back in can give results other than what was written ( what PORTB returns depends on what the I/O connects to ), there's a 'shadow register'' within the firmware which is automatically updated whenever PORTB is written and it's that which is used not the actual PORTB SFR. This is what references to PEEK $30 are in forum posts before we got the convenient READOUTPUTS command.

HIGH and LOW are the same as SETB and CLRB (BSF/BCF) and can be used the same way. The only thing is they take longer to execute. They also take more code space than "LET pins=" because it's not a compiler but an interpreter -

HIGH 1 : HIGH 2 --> <command> <number> <command> <number>

LET pins=$03 --> <command> <variable> <number>

Having to set eight bits isn't really any more cumbersome than MOVLW / MOVWF PORTB. If more complex processing is required then it takes additional commands.

There's no way round the fact that interpretation is going to be slower than assembler, that those four commands for READOUTPUTS will take around a millisecond. Two HIGH commands are faster but don't give simultaneous pin change; if that's acceptable then you can use that. Alternatively you can allocate 'b0' ( or 'b1' ) as a shadow register of your own ( as was often done before Microchip added LATB etc ), update b0 or bit0 through bit7 as if they were output bits then 'LET pins=b0'. Very much like the READOUTPUTS example but because b0 always tracks the output bits there's no need to do a READOUTPUTS, that saves a little time.

Apart from optimising code to make it faster, raw execution speed shouldn't be a major concern or issue for most PICAXE programmers. In most cases for those choosing PICAXE either speed isn't required or a reduction in it an acceptable compromise for ease of use. If speed and ease of use are required then it's necessary to look at other options, Basic compilers, or sticking with assembler if proficient with that.

Like 'ready to cook meals', they are rarely made exactly as you'd make your own but then they don't take hours to make, and one has to decide which route to go.
 
Last edited:

jglenn

Senior Member
Thanks for the insight, Hippy. Let pins is more efficient, I see, will try to use it.

Basic makes many things easier than in assembly, like I2C, I am already hooked on it. Actually most of my needs right now are analog in/out, was just looking at the fine points of digital I/O.

Just one other pesky question, the manual says the PIC watchdog is active during Sleep, and another instruction or 2, does that mean we assume it is not running during typical program execution not using these instructions? This may have been answered before, can't remember. I may need some kind of auto power recycling device in case of crash, which probably will be due to a programming error of mine. :p
 

hippy

Ex-Staff (retired)
I wouldn't say "LET pins=" is necessarily more efficient; it can use up more code space than a simple HIGH or LOW etc and overall take longer to execute. More a question of which is most appropriate to what you want to achieve at any time.

As I understand it, the watchdog is used for SLEEP and NAP timing so it has to always be enabled and the watchdog timeout routinely cleared by the firmware while interpreting the PICAXE Basic code to prevent reset. So it's running but not usable by a PICAXE programmer. If watchdog functionality is needed that has to be implemented externally.
 
Top