fortunately i bought a 18m2 for some tests so i am going to do soThere is no 'interrupt on analogue change' capability on PICAXE so a change can only be detected by polling and comparing with previous reading.
On the 18M2 it would be possible to put this in a separate task while the main program runs in its own task. The 40X2 doesn't however have multi-tasking capabilities.
Another possibility is to use a separate PICAXE which monitors for change and generates an interrupt when that occurs. The pot can go to analogue inputs on both the master PICAXE and that monitoring. As noted, analogue inputs can change very frequently due to noise but this could be filtered out in the monitoring PICAXE. This is the approach I would most likely take.
your principle is surely good but mi stepper is heavy to move and i need to push it up to 1000rpm , so, for that ,pulse loop must be as shorter as possible, so shorter ,that program part dedicated to potentiometer watching would be out of pulse loop to gain time : like interrupt or paralell (?) tasksI can't see a way to do this on a Picaxe (or a PIC for that matter). Apart from the fact that there is no "interrupt on ADC change" (as opposed to an "interrupt on change" of a digital pin), it would not make much sense to have such an interrupt in the first place: Just imagine the input level sits right between ADC value 100 and 101. The slightest amount of random noise (and there will always be SOME noise) will make the ADC value vary randomly between 100 and 101, causing a string of interrupts even though the input isn't really changing in any direction.
What you could do instead is set up a timer interrupt, e.g. every 1/100th second which then checks the ADC value compared to the previously stored. If it has change by more than 2 (or more steps, depending on the noise, but never make it just 1), then do what you want to do on ADC change and then update your reference (stored) value with the new one. That will accomplish what you wanted to do in the first place.
Wolfgang
it seems that interrupt on adc change theoreticaly existI can't see a way to do this on a Picaxe (or a PIC for that matter). Apart from the fact that there is no "interrupt on ADC change" (as opposed to an "interrupt on change" of a digital pin), it would not make much sense to have such an interrupt in the first place: Just imagine the input level sits right between ADC value 100 and 101. The slightest amount of random noise (and there will always be SOME noise) will make the ADC value vary randomly between 100 and 101, causing a string of interrupts even though the input isn't really changing in any direction.
What you could do instead is set up a timer interrupt, e.g. every 1/100th second which then checks the ADC value compared to the previously stored. If it has change by more than 2 (or more steps, depending on the noise, but never make it just 1), then do what you want to do on ADC change and then update your reference (stored) value with the new one. That will accomplish what you wanted to do in the first place.
Wolfgang
Really, how does that work, cant recall seeing it mentiopned in PIC data sheets ?it seems that interrupt on adc change theoreticaly exist
symbol oldval = w0
symbol newval = w1
symbol thresh_high = w3
symbol thresh_low = w4
symbol mindiff = 2 ' minimum change before action is taken
symbold ADC_CHAN = 1 ' whatever channel you want to use
.... init thresh_low and thresh_high
myloop:
readadc10 ADC_CHAN, newval
if newval >= thresh_high or newval <= thresh_low then
gosub DO_WHAT_YOU_WANT_TO_DO_ON_A_CHANGE
if newval >= mindiff ' avoid wraparound
thresh_low = newval - mindiff
else
thresh_low = 0
endif
thresh_high = newval + mindiff
endif
goto myloop
No, that won't work. No analog filter in the world can prevent the least significant bit of the result from potentially wiggling around randomly from one reading to the next. But you can catch that in software, see my example in the previous post.an adc input filter to kill noise and "le tour est joué"
about analog filter, you are right ,i try it ,i get some stabilisation but the least significant bit keep toggleling and only solution is softwareNo, that won't work. No analog filter in the world can prevent the least significant bit of the result from potentially wiggling around randomly from one reading to the next. But you can catch that in software, see my example in the previous post.
To provide pulses to the servo you could use the pwmout command and adjust the duty cycle as needed. The PWM is implemented in dedicated hardware so it keeps running at a steady pace completely independent of what the program does.
Make sure you use pwmduty to change the duty cycle (pwmout is needed only once, to start the pwm). It is much faster to execute than pwmout, and pwmout resets the pwm counter which would cause the servo to flutter.
hi premelec@jyb I don't know if you've got it solved yet but perhaps try running at fastest clock speed and then tailor pulsouts to the readadcs in the loop -
DO
READADC x 'pot in
x = x * k 'scale factor
PULSOUT x
LOOP
If this is too slow at least you can find out how much so... I'm not fully understanding your situation - hope this helps...