PIC Programmer Wanted!

BeanieBots

Moderator
You really don't like looking do you?

That video is blatently using a AXE027 (available from Rev-Ed) download cable into a 3.5mm stereo jack socket (available from Rev_Ed and many other stores) to program his PICAXE Xbox rapid fire mod.

It's not a commercial product. Just something he's done to his Xbox.
 

BeanieBots

Moderator
Maybe not, but having a good look at the parts supplied in the starter kits would be a good idea!

Clue: They contain all the parts you need to program a PICAXE.
 

inglewoodpete

Senior Member
AXE230 Module (08M)

Speaking of imagination, just look at the AXE230 module!

AXE230 Data Sheet

I'd love to know how big (or should I say 'how small') it is. Unfortunately, I don't have any of those odd Brit coins to compare it with.

Since the size is an important selling point, perhaps Technical could update the data sheet.
 
Last edited:
With the "pause" for burst fire code, is the higer the number faster rapid fire or slower?

For example is this:

Code:
Rapidburst:
Do
High 1
High 4
Pause 80
Low 4
Pause 80
High 4
Pause 80
Low 4
Pause 80
High 4
Pause 80
Low 4
Pause 80
High 4
Pause 80
faster or slower then this?

Code:
Rapidburst:
Do
High 1
High 4
Pause 111
Low 4
Pause 111
High 4
Pause 111
Low 4
Pause 111
High 4
Pause 111
Low 4
Pause 111
High 4
Pause 111
 

BeanieBots

Moderator
The number which comes after the pause is how long it pauses for.
Therefore, the first will fire quicker than the second.

Also, rather than keep repeating the lines, you can put it in a loop for a specified number of times.

Symbol DelayTime=80
Symbol Numberofshots = 7

To send 7 shots 80mS apart, something like this.

High 1
For b0=1 to Numberofshots
High 4
Pause DelayTime
Next b0
 

inglewoodpete

Senior Member
Whoops... slips!

There wasn't a link for the AXE230 on the docs page so took a punt and copied the 210 link onto my clipboard. Pasted it into the address bar and edited it to read 230 and voila! ...got the said document.

Then, in my excitement, I pasted the original URL into the hyperlink field. Try this one:
AXE230 Data Sheet

Hey! that one works!
 

BeanieBots

Moderator
That's a 20p coin.
It's about 21mm diameter.

Oh, but you don't know what mm are over there either do you!
That's 0.83" or ~ 7/8"
 

inglewoodpete

Senior Member
Oh, but you don't know what mm are over there either do you!
Sheesh, BB. You'll start a rivalry worse than Australia vs New Zealand!

I think Australia went metric before the UK, starting with currency in 1966. I was learning metric conversions in primary school at about the same time (1966) too.
 

inglewoodpete

Senior Member
To keep the thread on track, if I was trying to squeeze a PICAXE (or any microcontroller) into a game controller, the AXE230 would be a great choice. Since I'm not, I'll have to look for another excuse to buy a couple. With the UK pound plummetting, they have never been so attractive to us colonials.

Back to the side chatter. Not mentioning the 'H' word, you've lost me on that one, BB. Is it something that the Australian Dept of Propaganda is keeping from me?
 
The AXE230 would definetly be a great choice. I've sort of changed how I'm going to do the controller programming. Since I'm going to have the chip connected to 3 buttons, 2 LEDs and the right and left trigger, I think I'll have to go with the 14m to get the required number of I/Os. If only it came in the same form as the AXE230 lol.
 

hippy

Ex-Staff (retired)
It's possible to read multiple buttons on a single ADC line and you may also be able to design down to using an AXE230, or perhaps use two AXE230's, one per fire trigger with commoned mode select.
 
Ok so I've just finished making some basic code for 10 mode rapid fire. It's very simple and incomplete, but I have a problem. When I try to simulate it (I'm using the free PICAXE programming editor) it says that the program is 39 bytes over the memory size. I wrote it for the PICAXE 14M. Can someone please take a look at this and tell me what I need to do to improve it and if there is anyway to make the code shorter. :eek:

Here it is:
Code:
		Setfreq m8
			
rapidoff:	Low 1
		do
		if pin3 = 1 then pause1
		loop while pin3 = 0
		goto rapidoff

pause1:		pause 1000
			
rapidon:	Low 1
		High 1
		Readadc 4,b0
		If b0 > 80 then Rapid1
		If pin3 = 1 then pause2
		goto rapidon
	
Rapid1:		Do
		High 1
		High 4
		Pause 200
		Low 4
		Low 1
		Pause 195
		b0=b0 and %00000000
		Let dirsc=b0
		Readadc 4, b0
		Loop while b0 > 80
		goto rapidon

pause2:		pause 1000
						
rapidon2:	Low 1
		High 1
		Readadc 4,b0
		If b0 > 80 then Rapid2
		If pin3 = 1 then pause3
		goto rapidon2


Rapid2:		Do
              	High 4
              	Pause 170
             	Low 4
             	Pause 165
             	b0=b0 and %00000000
              	Let dirsc=b0
              	Readadc 4, b0
            	Loop while b0 > 80
               	goto rapidon2
               	
pause3:		pause 1000
            	
rapidon3:	Low 1
            	High 1
            	Readadc 4,b0
            	If b0 > 80 then Rapid3
            	If pin3 = 1 then pause4
            	goto rapidon3

Rapid3:		Do
              	High 4
              	Pause 140
             	Low 4
             	Pause 135
             	b0=b0 and %00000000
              	Let dirsc=b0
              	Readadc 4, b0
            	Loop while b0 > 80
               	goto rapidon3

pause4:     	pause 1000

rapidon4:	Low 1
            	High 1
            	Readadc 4,b0
            	If b0 > 80 then Rapid4
            	If pin3 = 1 then pause5
            	goto rapidon4
            	
Rapid4:		Do
              	High 4
              	Pause 110
             	Low 4
             	Pause 105
             	b0=b0 and %00000000
              	Let dirsc=b0
              	Readadc 4, b0
            	Loop while b0 > 80
               	goto rapidon4

pause5:     	pause 1000

rapidon5:	Low 1
            	High 1
            	Readadc 4,b0
            	If b0 > 80 then Rapid5
            	If pin3 = 1 then pause6
            	goto rapidon5
            	
Rapid5:		Do
              	High 4
              	Pause 80
             	Low 4
             	Pause 75
             	b0=b0 and %00000000
              	Let dirsc=b0
              	Readadc 4, b0
            	Loop while b0 > 80
               	goto rapidon5

pause6:     	pause 1000
            	
Burst1:		Symbol DelayTime1=80
		Symbol Numberofshots1 = 3
		High 1
		For b0=1 to Numberofshots1
		High 4
		Pause DelayTime1
		Next b0
			
pause7:		pause 1000	
			
Burst2:		Symbol DelayTime2=110
		Symbol Numberofshots2 = 3
		High 1
		For b0=1 to Numberofshots2
		High 4
		Pause DelayTime2
		Next b0

pause8:	        pause 1000

Burst3:		Symbol DelayTime3=110
		Symbol Numberofshots3 = 3
		High 1
		For b0=1 to Numberofshots3
		High 4
		Pause DelayTime3
		Next b0

pause9:	        pause 1000

Burst4:		Symbol DelayTime4=110
		Symbol Numberofshots4 = 3
		High 1
		For b0=1 to Numberofshots4
		High 4
		Pause DelayTime4
		Next b0

pause10:	pause 1000

Burst5:		Symbol DelayTime5=110
		Symbol Numberofshots5 = 3
		High 1
		For b0=1 to Numberofshots5
		High 4
		Pause DelayTime5
		Next b0
			
pause11:	pause 1000
		Goto rapidoff
It's long and is probably full of mistakes, but it's my first attempt so please don't flame.

Thanks! :)
 

BeanieBots

Moderator
I've not looked thoroughly but a few things jump out.
Firstly, commenting your code you let others know what was intended.

Why do you have several instances of:-
"b0=b0 and %00000000" ?

What is b0 and why mask it with zero?
b0=0
will do the same thing and use less space.
 

hippy

Ex-Staff (retired)
It's long and is probably full of mistakes, but it's my first attempt so please don't flame.
Looks to me like the code has been based ( inefficiencies and all ) upon the following ...

http://forums.xbox-scene.com/index.php?showtopic=653455&st=0

The usual process for developing code is to build it up a little at a time, proving it works and optimising as you go, taking note of how much memory is being used as you add things.

The code is full of inefficiencies, and poor code flow, for example the "b0=b0 and %00000000" and also control loops -

rapidoff:
Low 1
do
if pin3 = 1 then pause1
loop while pin3 = 0
goto rapidoff

pause1:

That's not criticism of the original author, because the primary thing with any code is whether it runs or not, and this appears to be first attempt code. But a far better way of representing the above would be -

Rapidoff:
Do
Low 1
Loop While pin3 = 0

Pause1:

That cuts this particular code down from 14 bytes to 8, a 40% saving.

The mechanism of reducing code size and improving code design is called 'refactoring'. That involves analysing and understanding what the code sets out to achieve then considering if there are other, better, ways to achieve the same. This requires a degree of experience which you best gain through experience with other projects.

It also helps to have an understanding of the code, what it does and how it does it, coupled withthe hardware it operates with. Simply changing from a 08M to a 14M, and renaming 'dirs' to 'dirsc' will not work. The first step is understanding what every command in the original code does with respect to when it is executed. Without that you will not get very far.
 
Ok thanks guys!

@ hippy, I was looking at a number of source codes including the one you linked me to, so that I could get an idea of what the code is based on.

I'll go back and give it another stab, and try to improve all the bits that are plain crap lol.

Thanks again!
 

inglewoodpete

Senior Member
I understand that you are 'repocessing' code that was was written for a slightly different situation.

However, for readability, put all your 'Symbol' statements in a group (or series of groups) near the top of the program. This way you can tell if you have double allocated a variable, pin or constant more easily. Also, document your code. Ie put comments on (practically) every line of code. That way, when you revisit the code a day, week, month or year later you can easily see what you intended the code to be doing. You will find it very frustrating to have to reaload your code each time you make a change, especially when several block look very similar.

The following are examples only. I haven't tried to fully understand your code. Reason: there are no comments to guide me as to what is happening as a result of the code.
Eg. Instead of
Loop While pin3 = 0
Low 1

Add a comment or two
Loop While pin3 = 0 'While trigger A released
Low 1 'Green LED #3 off
 
Ok I'm adding comments now. It's frustrating already lol. I'm thinking about going with less modes, even though i don't want to. I don't know how GamerModz got theirs on to this chip, and still managed to code it to recognise the controller it was in and adjust. :confused:

I need a "Coding Rapid Fire for Dummies" book lol.
 

inglewoodpete

Senior Member
That chip is probably a raw microcontroller chip coded for that specific purpose (ie gaming controller). The developer probably spent many, many hours writing the code. The PICAXE is a generic chip, intended to make coding easier for all sorts of applications, particularly education, but there is an expense: the amount of code you can fit on a chip.

With time, you will learn how to squeeze your code down to fit in the available space. One way to do that is to use subroutines to execute identical or similar functions with the same piece of code. For example, several 'bursts' of fire could be handled by one piece of code in a subroutine. Before entering the subroutine, you could set the firing speed in one variable and the number of shots in another. The subroutine would then do the 'firing' according to the input values passed into it.

"Coding Rapid Fire for Dummies"
Try "Coding PICAXEs for Dummies": its available here online, 24 hours a day ;). All you have to do is make an effort to read the manuals, learn and try different techniques. Ask the right questions here and you'll find a wealth of help but you have to do the 'work' for yourself.

Most importantly, enjoy the ride. Rome wasn't built in a day.
 

SilentScreamer

Senior Member
I can't see why you can't put that into a PICAXE. Requires you to learn how to write fairly well optimised code though else you'll exceed the 256 byte limit on an 08M.
 
What does this:

Code:
Readadc 4,b0
If b0 > 80 then Rapid1
and this:

Code:
b0=0
Let dirsc=b0
Readadc 4, b0
Loop while b0 > 80
actaully do and mean? I looked it up in the manual and have a vague idea but doesn't have much detail about what the "b0" does.
 

lbenson

Senior Member
b0 is one of the "registers" or "variables" available on the picaxe for holding values. It is a "byte" register, so it can hold an 8-bit value--a number between 0 and 255. It is something like "X" in high school algebra--X=1+2 could translate into the picaxe basic command, "b0 = 1 + 2". After this command was executed, b0 would have the value of 3.

Have a read of picaxe manual 1 and the first part of manual 2 to see more about variables. Different picaxes have different numbers of variable, e.g., b0 throu b13 for the "M" series and older, b0 through b27 for the X1 series, more for the X2 series.

Readadc 4,b0

This line reads a voltage (which must be between 0V and the voltage which powers the picaxe) on ADC pin 4, converts the voltage so that it has a value between 0 and 255 which is proportional to the voltage powering the chip, and puts that value into the register, b0 (read up on readadc in Manual 2).

If b0 > 80 then Rapid1

If the value in b0 is greater than 80, then go to the label, "Rapid1" and execute the code there. If the voltage powering the chip is 5V, then a value of b0 of, say, 81, represents a voltage on pin 4 of about 1.59V (81/255*5V).
 

westaust55

Moderator
PICAXE variables and maths

Have another read at PICAXE manual 2 (currently rev6.8).

General details on variables start at page 10

and variable maths start at page 20
 

hippy

Ex-Staff (retired)
In the original 08M code ...

Do
:
b0=b0 and %00000000
Let dirs=b0
Readadc 4, b0
Loop while b0 > 80

That makes all pins inputs, reads the analogue connected to pin 4 and repeats what's in the loop until the analogue level drops below 80.

The important thing though is "Why?". What is the purpose of doing that, what does it achieve and what is the program trying to determine is happening ?

Where does the analogue on pin 4 come from ? How is pin 4 used, and to what purpose ?

I'll be surprised if you can answer all those questions and without that knowledge you won't get far with converting the code to a 14M.

The clue to what is happening comes from other uses of pin 4 in the program ( and in that loop of the above code ), where it is also used as an output. Very strange until you understand what's going on, then it becomes crystal clear.

Pin 4 is connected to one of the triggers. That can be read as an analogue input, a low reading when pulled in, a high reading when released ( or vice-versa ). So what this code is doing is determining whether the trigger is pulled-in or not.

To do auto-fire, the trigger needs to be automatically pulled. This is done by using pin 4 to override the trigger; a pulse out on pin 4 simulates pulling the trigger. What the code does is automatically fire one shot, check if the trigger is released, if not fire another shot. To read the trigger pin 4 must be an input ( hence dirs= ) and to control the trigger pin 4 must be an output and pulse ( HIGH 4, LOW 4 ). Pin 4 is dual function.

Porting the code to a non-08M requires the same dual function use to be achieved, but on different hardware. On a 14M output pin 4 and ADC 4 are no longer on the same pins, so you need a different hardware design.

In this code it is only single trigger and you will be requiring dual trigger control. In the 08M version I recall that this used pin 1 or pin 2 for the second trigger. That's more complicated because pin 1 and pin 2 cannot be made inputs which means moving them to another pin which can be.

The first thing you need to do is come up with a hardware design, define what pins connect where, then write the code which can achieve what you want, test that on real hardware and make it work. After that you can chain the code you have into a functioning program which does all you want it to.

It's more complicated than just editing code as you are making a significant change to the hardware and need to know the consequences of that. The hardware design rests upon understanding how the hardware works and the PICAXE capabilities. It's an iterative process - Knowing what you need to achieve, designing hardware to allow it to be achieved, writing code to achieve it.

In starting with editing the code and not having a system design you are largely doomed to failure; you don't know what the change needed is or if it will do what it needs to achieve.

It's not a project I'd recommend as a first PICAXE programming exercise, and involves some electrical knowledge as well as software skills, but it can be done. I would suggest getting a basic PICAXE-08M starter kit to run programs upon and to test things out as that, IMO, is the best way to get to understand how the PICAXE works.
 
Top