08m running out of bytes

marzan

Senior Member
Hello. I have been working on a project to remotely adjust the height of agility poles. I now have some prototypes working. The motors that drive them are twin shaft motors. on one side there is a gearbox geared to turn a 10 turn pot which is used as a voltage divider. the other shaft is geared down to give decent torque and turn a threaded rod. As the gearboxes are run from the same motor the voltage divider can be used to check the height setting of the jump. the motor is run from a driver module by 2 pins one that enables/PWM the motor and a direction pin. The wireless module is hooked up through another voltage divider so I need only to use 1 ADC pin rather than 4 pins.

I am using a 4 button remote, but I needed 6 positions. I have written the code so that you press button A for the lower 3 heights, and button B for the 3 higher heights. then you press the buttons again to select the height. So the sequence is:
A,A 100mm
A,B 200mm
A,C 300mm
B,A 400mm
B,B 500mm
B,C 600mm

D returns to the first menu.

Everything works good, but I need to squeeze some more code in to check weather the shaft has jammed but there is not much space left. I am using 08M`s because I have quite a few of them (thanks SABorn) and as I need 40 of them it was a cheap option.

Here is the code:
Code:
; PICAXE 08M

;************************************************************
symbol enable = c.2          ;start motor movement and PWM
symbol direction = c.0       ;forward/reverse selection
symbol respot = c.1          ;ADC 1 Trimpot input to check position
symbol signalin = c.4        ;wireless in
symbol heightval = b1  	     ;which button was pressed 
symbol hcheck = b2	     ;check position of rotary resistor pot
symbol heightapproach = b4   ;when approching correct position use PWM to slow down motor

main:					;Select bottom or top 3 heights
	b0 = 0
	heightval = 0
	pause 250
      do
      	readadc 4,b0
			select case b0
				case > 80 goto lowerheight
				case > 55 goto upperheight
				case > 25 goto upperheight
				case > 15 goto main
			endselect
	loop
	
lowerheight:              ; Select which of the bottom 3 heights
	pause 400
	b0 = 0
	heightval = 0
	pause 250
      do
      	readadc 4,b0
			select case b0
				case > 80 heightval = 245 :goto heightmove
				case > 55 heightval = 203 :goto heightmove
				case > 25 heightval = 154 :goto heightmove
				case > 15 goto main
			endselect
	loop
	

upperheight:            ; Select which of the top 3 heighs
	wait 1pause 400
	b0 = 0
	heightval = 0
	pause 250
      do
      	readadc 4,b0
			select case b0
				case > 80 heightval = 96 :goto heightmove
				case > 55 heightval = 44 :goto heightmove
				case > 25 heightval = 10 :goto heightmove
				case > 15 goto main
			endselect
	loop

		
heightmove:   ; Check weather to go up or down
	
	readadc 1,hcheck
		if hcheck < heightval then low direction : goto go_up
		else high direction : goto go_down
		endif
		
Go_up:

 heightapproach = heightval - 4       ; Slow down motors with PWM to prevent overrun
  high enable
      do
      	readadc 1, hcheck
      	loop until hcheck > heightapproach
  pwmout C.2, 49, 139
      do
      	readadc 1, hcheck
      	loop until hcheck >= heightval
  pwmout C.2, 0, 0
  low enable
  goto main
Go_down:

  heightapproach = heightval + 8  ; Slow down motors with PWM to prevent overrun
  high enable
      do
      	readadc 1, hcheck
      	loop until hcheck < heightapproach
  pwmout C.2, 49, 169             
      do
      	readadc 1, hcheck
      	loop until hcheck <= heightval
  pwmout C.2, 0 , 0
  low enable
  goto main
Can anyone suggest any improvements to save space ?

Thanks in advance
Marz.
 

lbenson

Senior Member
I'm sure you know that the quickest solution is the 08M2. 40 * (cost of 08M2) compares how to the value of your time (considering that further enhancements may require you to go there anyway)?
 

hippy

Technical Support
Staff member
You can probably move your -

Code:
pause 400
	b0 = 0
	heightval = 0
	pause 250
      do
      	readadc 4,b0
			select case b0
				case > 80 heightval = 96 :goto heightmove
				case > 55 heightval = 44 :goto heightmove
				case > 25 heightval = 10 :goto heightmove
				case > 15 goto main
			endselect
	loop
To a subroutine which returns 0 to 3 indicating which height to go to, then replace all those with calls to that routine with a BRANCH / ON-GOTO after them.
 

BESQUEUT

Senior Member
Here is my proposal for 171 bytes :
Code:
; PICAXE 08M		'234/256

;************************************************************
symbol enable = c.2          ;start motor movement and PWM
symbol direction = c.0       ;forward/reverse selection
symbol respot = c.1          ;ADC 1 Trimpot input to check position
symbol signalin = c.4        ;wireless in
symbol heightval = b1  	     ;which button was pressed 
symbol hcheck = b2	     ;check position of rotary resistor pot
symbol heightapproach = b4   ;when approching correct position use PWM to slow down motor
symbol H=b5

main:					;Select bottom or top 3 heights
	b0 = 0
	heightval = 0
	pause 250

      do
      	readadc 4,b0
			select case b0
				case > 80 H=150:goto upperheight
'				case > 55 goto upperheight			' 9 bytes saved
				case > 25 H=0: goto upperheight
				case > 15 goto main
			endselect
	loop
	
;lowerheight:              ; Select which of the bottom 3 heights
;	pause 400
;	b0 = 0
;	heightval = 0
;	pause 250									' 43 bytes saved with H
;      do
;      	readadc 4,b0
;			select case b0
;				case > 80 heightval = 245 :goto heightmove
;				case > 55 heightval = 203 :goto heightmove
;				case > 25 heightval = 154 :goto heightmove
;				case > 15 goto main
;			endselect
;	loop
	

upperheight:            ; Select which of the top 3 heighs
	wait 1
	pause 400
	b0 = 0
	heightval = 0
	pause 250


      do
      	readadc 4,b0
			select case b0
				case > 80 heightval = H+96 :goto heightmove
				case > 55 heightval = H+44 :goto heightmove
				case > 25 heightval = H+10 :goto heightmove
				case > 15 goto main
			endselect
	loop

		
heightmove:   ; Check weather to go up or down
	
	readadc 1,hcheck
	if hcheck < heightval then
		low direction
'		goto go_up					' 11 bytes saved removing this GOTO
		heightapproach = heightval - 4       ; Slow down motors with PWM to prevent overrun
  		high enable
      	do
      		readadc 1, hcheck
      	loop until hcheck > heightapproach
  		pwmout C.2, 49, 139
	
      	do
      		readadc 1, hcheck
	loop until hcheck >= heightval


	else
		high direction
'		goto go_down
 		heightapproach = heightval + 8  ; Slow down motors with PWM to prevent overrun
  		high enable
      	do
      		readadc 1, hcheck
	loop until hcheck < heightapproach

  		pwmout C.2, 49, 169             
      	do
      		readadc 1, hcheck
	loop until hcheck <= heightval


	endif
  	pwmout C.2, 0 , 0
  	low enable
 	goto main
If necessary, it's certainly possible to save more...
 

premelec

Senior Member
What I've done when confronted with 08M limitations [and I used to use 08s] is write the code for 08M2 so I can check running and then start paring down bits while still checking with simulator... I don't even know what an agility pole is but 40 of them must be tricky!
 
Last edited:

westaust55

Moderator
Concur with premlec's idea.

How much space does your proposed enhancement need?

We do not know what parts of the existing code can or cannot be changed.

For example in the first loop alone, if the "change points" can be adjusted from 15, 25, 55, 80 to equal steps of 15, 30, 45, 60 then 19 bytes can be save by using:
Code:
main:					;Select bottom or top 3 heights
	b0 = 0
	heightval = 0
	pause 250
      do
        	readadc 4,b0
        	b0 = b0 / 15 MAX 4
        	; if < 15 then loop,15 to 29 goes to main, 30 to 44 and 45 to 59 to upperheight and >60 to lowerheight
        	ON b0 GOTO cont, main, upperheight,upperheight,lowerheight
cont:
;      	readadc 4,b0
;			select case b0
;				case > 80 goto lowerheight
;				case > 55 goto upperheight
;				case > 25 goto upperheight
;				case > 15 goto main
;			endselect
	loop
why have
Code:
upperheight:            ; Select which of the top 3 heights
	wait 1 
	pause 400
save 3 bytes with
Code:
upperheight:            ; Select which of the top 3 heights
;	wait 1 
	pause [COLOR="#FF0000"]1[/COLOR]400
 

marzan

Senior Member
Thanks for the replies guys. That will save me a heap of frustration.
I probably didn`t explain what they are very well. They are DOG agility poles. As an instructor it is a pain to have to reset the jumps all the time. The jump height depends on the size of the dog.
here`s piccies:
ag1.jpgag2.jpg
 

marzan

Senior Member
This is what is inside the poles:
ag3.jpgag4.jpg

I have used the 08m because it is not my money I am spending, and seeing every set costs over $180 to build just in parts, I need to save every cent. When I can prove these work for more than 5 minutes there will probably be some enhancements that will need a bigger chip, either a 14 or 18 pin the mechanical portion will remain the same so it will just be a new circuit board.
Anyhoo, Now to figure out how to check that the motor is still turning when it is supposed to. I guess it would be easiest to keep comparing the resistor pot value with itself when it is moving. does that sound feasible?

Marz
 

marzan

Senior Member
@wetsaust the first 2 inputs are the buttons from the remote, using resistors as a voltage divider. I tried different combinations of resistors. In testing the buttons these gave me the best results, so not easy to change. I think there is enough room now thanks to the posts on this thread to put some safety features in place. Thank you for your ideas everyone.
Marz.
 

inglewoodpete

Senior Member
I probably didn`t explain what they are very well. They are DOG agility poles....
I'm glad that you explained. Myself not knowing, I did a quick google and got the impression that they were either fancy walking sticks or ski poles. Since the nearest snow to me appears about 3,000km away, I thought I'd leave it to the experts....

The budget must be really tight if a reusable agility pole with an 08M2 is too expensive, considering what we pay every week to feed our pets. Not to mention what it costs for my vet to vaccinate my cat (1 minute) and scratch it behind the ears (another 5 minutes)!

Good on you for donating your time!
 

marzan

Senior Member
I will post a video of them working when they are finished. This is just the first stage. other pieces of equipment needs to move as well. I also want to include timing gear. Then the whole lot needs to be integrated do that you just scan the dogs microchip and the jumps move automatically to the right height and the times are logged. But for now I am just getting the jumps working because I want to show them off at a demonstration we are doing for the RSPCA in a few weeks.
 

SAborn

Senior Member
Nice work. Its for more than I would have dedicated to the cause.

Send me a PM as I have lost your contact details.
 

marzan

Senior Member
Doesn't need to be that close.as long as they end up at the same height. I forgot to turn one side of and there was 100 mm difference and it still didn't fall off. Held on by 4 rare earth magnets.
 

marzan

Senior Member
Well I had my debut of the jumps at the million paws walk today. Went down a treat. Posted them working on Facebook yesterday. In 30 hrs over 10k views!!!
 

westaust55

Moderator
Concur with IWP.
A very neat and useful project for the canine groups.

One comment - a pity there is absolutely no mention that the brains behind the control is a PICAXE microcontroller.
 

marzan

Senior Member
No. But quite a few competitors saw them at the million paws walk and thought they were great. Are you here for the Nationals?
 

flyingnunrt

Senior Member
No, we are not going to the Nats, but quite a few of our friends will be there. Some flyballers there also doing agility.
 

marzan

Senior Member
The video of 6 of them working has gone nuts. 55k views!! If you want to see it lookup school for dogs Aldinga bay on Facebook
 

marzan

Senior Member
It`s been a year now and we have torture tested the design for the jumps, and the only issues have been with the monitoring of the LiPo batteries. Picaxe and circuitry haven't missed a beat! Due to a change of employment I haven't had time for hobbies, But hopefully soon things will calm down enough to now finish the design and make the proper jumps. If you are interested on how they ended up, here is a video of 6 sets working.
https://www.facebook.com/sfdab/videos/949379378515040/
Thanks for everyones help on this.
Marz
 
Top