PIC Processing Speed

Youneedme

New Member
Hello

I need to figure out the speed of PIC chips for every command in the following, as I need to figure out the length of pauses to use in order to keep two chips running their commands in parallel, as if one chip gets an input and the other doesn't, it messes up my project, which, for anyone's interest, Is a prototype of an electronic Connect 4. The chips in question are 28X2, in case the size/age affects the Processing speeds

THe folliwing commands
Low (any output)
HIgh (any output)
If b13=1 then goto OLine4.2
Let b13=1
If pinb.4 =1 then goto Line1

It is a puzzle which I haven't seemed to be able to find on the PIC manuals

Thanks
YNM
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

There are no absolute timings for PICAXE commands and chips will always drift out of synchronisation with each other. You need to use cross-chip signalling to keep two or more chips in sync with each other.
 

Youneedme

New Member
Is It possible to use resonator legs for that? - I asked my teacher about this, as it is a school project, and he said the resonator can be used to make the PIC run at certain speeds
 

hippy

Technical Support
Staff member
Even resonators will run at slightly different speeds so things will eventually get out of kilter, and each chip may take a slightly different time to start. Also that would not overcome the issue that commands have no guaranteed timing.
 

rossko57

Senior Member
Is It possible to use resonator legs for that?
It wouldn't help. If you think about, you have no gaurantee the two PICs would even start off executing code at exactly the same microsecond after power up.
Hippy is driving at making your two chips talk to each other, e.g. over a serial interface. It's than a matter of coding to have one chip wait on the other completing some action, before doing X itself.

Do you actually need two chips for Connect-4 ?
 

srnet

Senior Member
Is It possible to use resonator legs for that? - I asked my teacher about this, as it is a school project, and he said the resonator can be used to make the PIC run at certain speeds
Nope.

A resonator will make the PICAXE run at a more consistent speed, but if you use resonators on each PICAXE they will still not keep in sync.
 

Jeremy Harris

Senior Member
Another vote for wide timing variability, even with seemingly similar code. I've been measuring this this morning, trying to get a bit of code to execute quickly, and even seemingly small changes have an appreciable effect on execution time. For example, running a simple FOR-NEXT loop to consecutively measure and store pulse widths indirectly into storage memory, with an ordinary variable as the loop counter, seems significantly slower than running the same loop with the byte pointer as the loop counter. The internal resonator and other internal function accuracy isn't great, either, my test programme reads around 8% low on a straightforward pulse width measurement, for example, and I suspect that would vary a bit from chip to chip.

Best follow hippy's suggestion connecting two or more Picaxes if you want them to synchronise.
 

Youneedme

New Member
It wouldn't help. If you think about, you have no gaurantee the two PICs would even start off executing code at exactly the same microsecond after power up.
Hippy is driving at making your two chips talk to each other, e.g. over a serial interface. It's than a matter of coding to have one chip wait on the other completing some action, before doing X itself.

Do you actually need two chips for Connect-4 ?
Yes, as I require 32 outputs and 4 inputs, so I cannot use a 40X2.

would this command work
S2Main:
If A.3 = 1 then goto main
High A.3
Pause 100
Low A.3
goto S2Main

main:
If pinb.4 =1 then goto Line1
If pinb.5 =1 then goto Line2
If pinb.6 =1 then goto Line3
If pinb.7 =1 then goto Line4
goto S2Main
 

hippy

Technical Support
Staff member
would this command work
It's impossible to say without knowing what it is you are hoping to achieve. That "If A.3 = 1 then" is not right, but it's not obvious what it ought to be.

Without understanding how you are using the two chips, how they connect to your hardware, the way they are meant to work together, it's hard to give suggestions on how to solve any issues you may be having. A brief explanation and a circuit diagram would likely help.
 

hippy

Technical Support
Staff member
The internal resonator and other internal function accuracy isn't great, either, my test programme reads around 8% low on a straightforward pulse width measurement, for example, and I suspect that would vary a bit from chip to chip.
It's possibly you are reading 8% lower than expected but that could be an issue beyond internal oscillator accuracy. That is well outside manufacturer tolerances for the oscillator and far from what we have experienced when testing. Might be worth creating a separate thread to discuss that issue.
 

rossko57

Senior Member
Are your two PICs representing opposing players? The nature of the game is taking turns anyway, which sounds like a way forward.
 

Youneedme

New Member
Are your two PICs representing opposing players? The nature of the game is taking turns anyway, which sounds like a way forward.
Yes, hiwever the Outputs need to not activate when the other player is taking their turn, otherwise both LED's will activate. I have countered this problem by including memory within the chip which will record which LED's are active. I have had a brain wave of pausing each recording until both are done, but that'll make my chips run really slow as both chips need to catch up, and it can still fail.
 

Youneedme

New Member
Let me just test out a different angle to the problem, it could be fixed now, I just need to get to my breadboard, which I'll only be able to get to tommorow
 

Youneedme

New Member
I have fixed the problem, I delayed the outputs of each by two seconds, from a rough calculation made by adding the average humans reaction time to the Rough delay of each command (an estimate of about 100 microseconds I believe (doing this from memory afterwards)) and adding one second to that and rounding up to the nearest second. To my surprise, the time taken between the two outputs which monitor the PIC activating triggered almost instananeously with the altered program, so maybe my predicted Value is too high. A few extra tweaks later, as in correcting some dodgy Code (sending the command to the wrong sensing area), and making all the Outputs be directed the same way (some were going left to right, and others were going right to left). And it is done.... I'll post up the code and livewire snapshot when I have altered the Livewire as I need to change a buzzer to an LED and add in a new LED. Then I'm going to have to swap around all of my resistors.. as I put them all in back to front, my OCD is callling:mad:
 

Youneedme

New Member
OK, Livewire
Livewire.JPG

Code for one
Code:
Main:
If pinb.4 =1 then goto Line1
If pinb.5 =1 then goto Line2
If pinb.6 =1 then goto Line3
If pinb.7 =1 then goto Line4
goto Main:

SMain:
Low A.4
goto Main

Line1:
High A.4
If b0=1 then goto Line1.1
Let b0=1
Wait 2
Low A.4
goto Other

Line1.1:
If b1=1 then goto Line1.2
Let b1=1
Wait 2
Low A.4
goto Other
 
Line1.2:
If b2=1 then goto Line1.3
Let b2=1
Wait 2
Low A.4
goto Other

Line1.3:
If b3=1 then goto SMain
Let b3=1
Wait 2
Low A.4
goto Other

Line2:
High A.4
If b4=1 then goto Line2.1
Let b4=1
Wait 2
Low A.4
goto Other

Line2.1:
If b5=1 then goto Line2.2
Let b5=1
Wait 2
Low A.4
goto Other
 
Line2.2:
If b6=1 then goto Line2.3
Let b6=1
Wait 2
Low A.4
goto Other

Line2.3:
If b7=1 then goto SMain
Let b7=1
Wait 2
Low A.4
goto Other

Line3:
High A.4
If b8 =1 then goto Line3.1
Let b8=1
Wait 2
Low A.4
goto Other

Line3.1:
If b9=1 then goto Line3.2
Let b9=1
Wait 2
Low A.4
goto Other

Line3.2:
If b10=1 then goto Line3.3
Let b10=1
Wait 2
Low A.4
goto Other

Line3.3:
If b11=1 then goto SMain
Let b11=1
Wait 2
Low A.4
goto Other

Line4:
High A.4
If b12=1 then goto Line4.1
Let b12=1
Wait 2
Low A.4
goto Other

Line4.1:
If b13=1 then goto Line4.2
Let b13=1
Wait 2
Low A.4
goto Other
 
Line4.2:
If b14=1 then goto Line4.3
Let b14=1
Wait 2
Low A.4
goto Other

Line4.3:
If b15=1 then goto SMain
Let b15=1
Wait 2
Low A.4
goto Other

Other:
If pinb.4 =1 then goto OLine1
If pinb.5 =1 then goto OLine2
If pinb.6 =1 then goto OLine3
If pinb.7 =1 then goto OLine4
goto Other:

SOther:
Low A.4
goto Other

OLine1:
High A.4
If b0=1 then goto OLine1.1
Let b0=1
High B.3
Wait 2
Low A.4
goto Main

OLine1.1:
If b1=1 then goto OLine1.2
Let b1=1
High B.2
Wait 2
Low A.4
goto Main
 
OLine1.2:
If b2=1 then goto OLine1.3
Let b2=1
High B.1
Wait 2
Low A.4
goto Main

OLine1.3:
If b3=1 then goto SOther
Let b3=1
High B.0
Wait 2
Low A.4
goto Main

OLine2:
High A.4
If b4=1 then goto OLine2.1
Let b4=1
High A.0
Wait 2
Low A.4
goto Main

OLine2.1:
If b5=1 then goto OLine2.2
Let b5=1
High A.1
Wait 2
Low A.4
goto Main
 
OLine2.2:
If b6=1 then goto OLine2.3
Let b6=1
High A.2
Wait 2
Low A.4
goto Main

OLine2.3:
If b7=1 then goto SOther
Let b7=1
High A.3
Wait 2
Low A.4
goto Main

OLine3:
High A.4
If b8 =1 then goto OLine3.1
Let b8=1
High C.0
Wait 2
Low A.4
goto Main

OLine3.1:
If b9=1 then goto OLine3.2
Let b9=1
High C.1
Wait 2
Low A.4
goto Main

OLine3.2:
If b10=1 then goto OLine3.3
Let b10=1
High C.2
Wait 2
Low A.4
goto Main

OLine3.3:
If b11=1 then goto SOther
Let b11=1
High C.3
Wait 2
Low A.4
goto Main

OLine4:
High A.4
If b12=1 then goto OLine4.1
Let b12=1
High C.7
Wait 2
Low A.4
goto Main

OLine4.1:
If b13=1 then goto OLine4.2
Let b13=1
High C.6
Wait 2
Low A.4
goto Main
 
OLine4.2:
If b14=1 then goto OLine4.3
Let b14=1
High C.5
Wait 2
Low A.4
goto Main

OLine4.3:
If b15=1 then goto SOther
Let b15=1
High C.4
Wait 2
Low A.4
goto Main
Code part 2
Code:
Main:
If pinb.4 =1 then goto Line1
If pinb.5 =1 then goto Line2
If pinb.6 =1 then goto Line3
If pinb.7 =1 then goto Line4
goto Main:

SMain:
Low A.4
goto Main

Line1:
High A.4
If b0=1 then goto Line1.1
Let b0=1
High B.3
Wait 2
Low A.4
goto Other

Line1.1:
If b1=1 then goto Line1.2
Let b1=1
High B.2
Wait 2
Low A.4
goto Other
 
Line1.2:
If b2=1 then goto Line1.3
Let b2=1
High B.1
Wait 2
Low A.4
goto Other

Line1.3:
If b3=1 then goto SMain
Let b3=1
High B.0
Wait 2
Low A.4
goto Other

Line2:
High A.4
If b4=1 then goto Line2.1
Let b4=1
High A.0
Wait 2
Low A.4
goto Other

Line2.1:
If b5=1 then goto Line2.2
Let b5=1
High A.1
Wait 2
Low A.4
goto Other
 
Line2.2:
If b6=1 then goto Line2.3
Let b6=1
High A.2
Wait 2
Low A.4
goto Other

Line2.3:
If b7=1 then goto SMain
Let b7=1
High A.3
Wait 2
Low A.4
goto Other

Line3:
High A.4
If b8 =1 then goto Line3.1
Let b8=1
High C.0
Wait 2
Low A.4
goto Other

Line3.1:
If b9=1 then goto Line3.2
Let b9=1
High C.1
Wait 2
Low A.4
goto Other
 
Line3.2:
If b10=1 then goto Line3.3
Let b10=1
High C.2
Wait 2
Low A.4
goto Other

Line3.3:
If b11=1 then goto SMain
Let b11=1
High C.3
Wait 2
Low A.4
goto Other

Line4:
High A.4
If b12=1 then goto Line4.1
Let b12=1
High C.7
Wait 2
Low A.4
goto Other

Line4.1:
If b13=1 then goto Line4.2
Let b13=1
High C.6
Wait 2
Low A.4
goto Other
 
Line4.2:
If b14=1 then goto Line4.3
Let b14=1
High C.5
Wait 2
Low A.4
goto Other

Line4.3:
If b15=1 then goto SMain
Let b15=1
High C.4
Wait 2
Low A.4
goto Other

Other:
If pinb.4 =1 then goto OLine1
If pinb.5 =1 then goto OLine2
If pinb.6 =1 then goto OLine3
If pinb.7 =1 then goto OLine4
goto Other:

SOther:
Low A.4
goto Other

OLine1:
High A.4
If b0=1 then goto OLine1.1
Let b0=1
Wait 2
Low A.4
goto Main

OLine1.1:
If b1=1 then goto OLine1.2
Let b1=1
Wait 2
Low A.4
goto Main
 
OLine1.2:
If b2=1 then goto OLine1.3
Let b2=1
Wait 2
Low A.4
goto Main

OLine1.3:
If b3=1 then goto SOther
Let b3=1
Wait 2
Low A.4
goto Main

OLine2:
HIgh A.4
If b4=1 then goto OLine2.1
Let b4=1
Wait 2
Low A.4
goto Main

OLine2.1:
If b5=1 then goto OLine2.2
Let b5=1
Wait 2
Low A.4
goto Main
 
OLine2.2:
If b6=1 then goto OLine2.3
Let b6=1
Wait 2
Low A.4
goto Main

OLine2.3:
If b7=1 then goto SOther
Let b7=1
Wait 2
Low A.4
goto Main

OLine3:
High A.4
If b8=1 then goto OLine3.1
Let b8=1
Wait 2
Low A.4
goto Main

OLine3.1:
If b9=1 then goto OLine3.2
Let b9=1
Wait 2
Low A.4
goto Main
 
OLine3.2:
If b10=1 then goto OLine3.3
Let b10=1
Wait 2
Low A.4
goto Main

OLine3.3:
If b11=1 then goto SOther
Let b11=1
Wait 2
Low A.4
goto Main

OLine4:
High A.4
If b12=1 then goto OLine4.1
Let b12=1
Wait 2
Low A.4
goto Main

OLine4.1:
If b13=1 then goto OLine4.2
Let b13=1
Wait 2
Low A.4
goto Main
 
OLine4.2:
If b14=1 then goto OLine4.3
Let b14=1
Wait 2
Low A.4
goto Main

OLine4.3:
If b15=1 then goto SOther
Let b15=1
Wait 2
Low A.4
goto Main
Each code goes on one of the chips, they are pretty much copies of each other, with small edits between. You are welcome to refine it
 

Kecked

Member
Just a thought but would not a serial shift register be the ticket. Shift out as many outputs as you want to the register and then update them all at once. That could be done with 50 outputs rather quickly. I think the 7219 works something like that for led displays. I'm not sure if you could do this quick enough to produce pwm on all the outputs but it is cheap enough to try. There could also be outboard chips that do it.
 
Top