need help please

jyb

Senior Member
hi all
i wrote a simple program to drive a stepper motor behind a "leadshine" driver
a simple switch to give the direction rotation and a potentiometer to drive speed between 30rpm to 800 rpm
for gain speed a short loop is used
what i want is to change cpu speed clock setfreq m8 at motor start and when launched, change to setfreq em64.this is done using comsetup and setintflags
at begining potentiometer rise up with low speed and passing over a threshold , freq is siwtched to 64mhz
it don't run correctly
there is something i misunderstood but what?
here is one example of tens tests i tryed
perhaps somebody could help me?
thanks

pic18f45k22
#picaxe 40x2
setfreq m8
symbol compvalue_ = b2
symbol potentiometre = w0
symbol pulse = c.2
low C.6
adcsetup = A.1
'9876543210 76543210
compsetup %0010100010,%10011110
'flags mask
setintflags %00010000,%00010000
compvalue = 0
marche:
readadc10 A.1 , potentiometre
pulsout C.2 , 1 pauseus potentiometre 'debug'sound A.0,(100,50)
goto marche

interrupt:
setintflags off
if compvalue > 1 then setfreq em64 else setfreq m8 endif 'debug

setintflags %00010000,%00010000
return
 

Attachments

hippy

Ex-Staff (retired)
Can you post a circuit diagram of your hardware and also explain exactly what does not work as expected.
 

jyb

Senior Member
mill machine help

here is joined the drawing

what i want to do is at the starting motor state the setfreq is 8mhz, and when potentiometer begin to move , and once motor is running very slow , an interrupt is generated on programmed potentiometer level and system clock is switched to 64mhz permiting higher speed to the stepper motor

(no pwm needed, just only pulses frequency variation)

the little program previously joined is to find best solution for lower and higher speeds but it locks in beginning phasis and i can't undersand why
i think the problem is using compsetup and setintflags , something i misunderstood ?
thanks
 

hippy

Ex-Staff (retired)
You do not appear to have attached the circuit diagram and it is hard to see what the code should be without that.

The two most likely issues it seems to me, beyond COMPSETUP configuration error, are the PICAXE prematurely entering interrupt or continually entering interrupt.

Does the code work as expected when interrupts are not used ?
 

hippy

Ex-Staff (retired)
There appears to be an issue with COMPSETUP which we are investigating.

In the meantime you might be able to work round the issue by testing the pot value rather than interrupting. You may need to adjust the value of "K" -

Code:
#picaxe 40x2

symbol potentiometre = w0

symbol K = 256

do
  setfreq m8
  do
    readadc10 A.1 , potentiometre
    pulsout C.2 , 1 
    pauseus potentiometre
  loop until potentiometre > K
  setfreq em64
  do
    readadc10 A.1 , potentiometre
    pulsout C.2 , 1 
    pauseus potentiometre
  loop until potentiometre < K
loop
 

Jamster

Senior Member
Another error is that you require a colon in the second last line.
Code:
#picaxe 40x2
setfreq m8
symbol compvalue_ = b2
symbol potentiometre = w0
symbol pulse = c.2
low C.6
adcsetup = A.1
'9876543210 76543210
compsetup %0010100010,%10011110
'flags mask
setintflags %00010000,%00010000
compvalue = 0
marche:
readadc10 A.1 , potentiomet[COLOR="red"]er[/COLOR]
pulsout C.2 , 1 pauseus potentiometre 'debug'sound A.0,(100,50) 
goto marche

interrupt:
setintflags off
if compvalue > 1 then setfreq em64 else setfreq m8 [COLOR="Red"]:[/COLOR] endif 'debug

setintflags %00010000,%00010000
return
also work on spelling is required ;)
 

westaust55

Moderator
Another error is that you require a colon in the second last line.
Code:
#picaxe 40x2
readadc10 A.1 , potentiomet[COLOR="red"]er[/COLOR]
pulsout C.2 , 1 pauseus potentiometre 'debug'sound A.0,(100,50) 
goto marche
QUOTE]

My understanding is that the need for a colon is (unfortunately) not correct.

While the manual 2 does state:
Newline
Commands are normally placed on separate lines. However if desired the colon
(:) character can be use to separate multiple commands on a single line e.g.
if pin1 = 1 then : high 1 : else : low 1 : endif
As a matter from past history, I believe that Rev Ed have included within the PE the capability of having a space as an alternate separtor.
Sloppy coding IMHO as it then adds a further complexity for those helping to be sure where a new line functionality is intended.
 

jyb

Senior Member
hi jamster

Another error is that you require a colon in the second last line.
Code:
#picaxe 40x2
setfreq m8
symbol compvalue_ = b2
symbol potentiometre = w0
symbol pulse = c.2
low C.6
adcsetup = A.1
'9876543210 76543210
compsetup %0010100010,%10011110
'flags mask
setintflags %00010000,%00010000
compvalue = 0
marche:
readadc10 A.1 , potentiomet[COLOR="red"]er[/COLOR]
pulsout C.2 , 1 pauseus potentiometre 'debug'sound A.0,(100,50) 
goto marche

interrupt:
setintflags off
if compvalue > 1 then setfreq em64 else setfreq m8 [COLOR="Red"]:[/COLOR] endif 'debug

setintflags %00010000,%00010000
return
also work on spelling is required ;)
does quote change anything when program run?
 
Top