Need your help: 2 Processes - one very fast - / one slow - how to do ?

albatros

New Member
Hello,

I need to setup two processes - where one shall be run as fast as possible, and the second
shall be done any 100 - 200ms (for instance).

The first one, shall also "interrupt" the slower one ..or saying in other words - the first one shall always be able to
run every x µs ...while the slower one can take a longer time.

In a first step I thought about using the parallel procedure - but in detail they are taking each 20ms and they
are in reality sequently.

2nd idea is - to setup the first process as an interrupt routine - and the 2nd process as an usual program.
But how can I trigger the first routine - if I wouldn't spent another inputpin and an oscillator?

Is there an internal value available, which can be used of a 14M2 or 20M2.

OR - is it possible to trigger an interrupt by an ADC-value ?
so far I understood - this is only with "digital High/low" feasable ?

So - It would be kind if anybody can help me.

Thanks in advance
albatros


Story behind:
The first process shall read values from ADC, calculate it, and control a PWM. So only some line of codes.
The 2nd process is to read UserInputs by Buttons, deliver informations on LCD...
 

inglewoodpete

Senior Member
To provide exactly what you are asking will be a challenge on a PICAXE. I have done a similar thing on a 'raw' PIC18F25K22 (without the PWM) but it was too much for a PICAXE. In that project, the 2 x 10-bit ADCs were reading an accelerometer and the output was used to energise two solenoids operating a pendulum that swung in two axes.

Having said that, I have used slower timer interrupts (Eg 100mS) interrupting a reasonably tight loop which (Case 1) reads ADC 10-bit and controls a motor with PWM and (Case 2) reads ADC 8-bit, performs same calculations and uses PWM to control high-powered RGB lighting colour LEDs. The 100mS interrupt is used for other, supervision roles.

Perhaps your need for such fast updating of PWM is not necessary. Can you tell us what the PWM is used to control and why it would need to be updated at a sub-millisecond rate?
 

erco

Senior Member
Two seperate Picaxes is always a possibility, and pretty darn cheap, with a few I/O pins communicating between them to sync everything.
 

AllyCat

Senior Member
Hi,

I guess this is for the Bench Power Supply project?

To be honest, a PICaxe will probably "struggle" to do the job well. If you use multitasking (two Starts: ) then you are limited to a 4 MHz clock with typical single instruction times around 1 ms. A 20M2 with "linear" coding could get to 100us instructions (32 MHz clock) but no timer interrupts. Or a 20X2 is twice as fast, with timer interrupts and a (supported) comparator to perhaps generate an interrupt when exceeding an analogue voltage level.

Personally, since I don't have any experience with X2s (and you have specified M2s), I think I would probably make the large task2 the main polling loop, with frequent explicit subroutine "visits" to the "fast" task. The voltage feedback control loop probably doesn't need to be too fast because the "easy" way to make a feedback loop stable is to make it slow ;) .

IMHO you should use a pure hardware current limit circuit: That need be only a single transistor, where exceeeding its 600 mV Vbe would make it "steal" current from the voltage driver. Or if you want the PICaxe to select an adjustable threshold current (limit), then there are analogue comparators (and a "DAC" bias network) inside all M2s, which can be accessed via PEEK-/POKESFR commands.

Cheers, Alan.
 

Janne

Senior Member
I think AllyCat offered good advice, I would also go with a hardware solution, or with a "raw" micro instead of picaxe if I really wanted to do it in software.
If you want more accuracy / resolution that what an internal DAC on picaxe can offer, one solution would be to use an external DAC like MCP4921 or 4922. I don't know how you are controlling the voltage set point, but this DAC would be a good solution to that as well. It supports external voltage reference, so you could achieve quite nice voltage stability and accuracy with a good 2.5V or 5V voltage reference.
 

albatros

New Member
Hello all,

thanks a lot for the feedback.

Jipp - it is for my project LAB Bench controlled by PicAxe.

I managed now, that the PicAxe can control and regulate the OutputVoltage by a Tranisistor-Amplifier-Unit by a PWM-Signal. This works realy pretty fine - and adjustment is realy close (according the 10Bit resolution).
As AllCat correctly mentioned - the topic is, if I release the load (for instance heavy load), the control-mechanism of the Picaxe needs time to recognize the release - in the meanwhile, the voltage increase at the output, because the the downsizing regulation
was not started. Thats the only case, where I need "speed".

When I hav only the adjustment/regulation code - the response time is less then 2ms .....but adding the other code (for reading buttons, control display) - consumes the time.

@AllCat - I tried the DAC of the PicAxe - but my measures have been shown, that the DAC is realy unstable ....even with a opamp buffer (as described in the manual). I had a lot of noise on the output. Do you have some additional information for me ? (links or something similar) ?

Maybe also a hint for the Transistor - stealing the Base-Control ?

Maybe I will give a try to the 28X2 (5V) - running on 64Mhz.

Thanks in advance
Albatros
 

AllyCat

Senior Member
Hi,

Yes, IMHO as a "DAC output" with only 32 levels (5 bits) and high output impedance, the PICaxe hardware module is rather "rubbish" and I wouldn't consider using it. However, as an internal "bias" network, e.g. for the on-chip comparator(s), it can be very useful and I often use it.

Whilst I agree with fernando (in the other thread) that the original "published" current-sense resistor was too large, I wouldn't go as far as using an Op-Amp and struggling to find (and use correctly) a 0.01 ohm resistor (for a simple power supply). Similarly, "high side" sensing would be better, but probably an unnecessary complication when the variable output voltage is much higher than the PICaxe supply rail. But for a "dissipating" (non-PWM) outut stage, it might be worth researching a "foldback" current limiter design, to reduce the maximum overload power.

For my simple "one-transistor" arrangement, choose the resistor (R19) to drop about half a volt at the maximum normal output current. Then use any low-power NPN (BC548, etc.), with emitter to ground (low end of current-sensing resistor), base via a few kohms (to prevent the base being "blown out" by overload currents) to the top of the current sense, and collector to (say) the middle or output of your PWM Low-Pass filter (R14).

Not directly relevant, but you might find "Part 1" of the code snippet which I posted recently, of some interest.

Cheers, Alan.
 

albatros

New Member
Hi Alan,

thanks for the feedback.

I read your article about measuring the current - looks very intersting - and I will give it a try ...
Regarding the current measuring - I would re-arange the resistor R19.
And I'm currently thinking about to measure the voltage drop over the current sense with opamp - differenciation ....lets see.

There is another thing which I'm very interested in .. you wrote in your article that the M2 have an analogue comparator. Is it possible to use these comparators to detect the voltage overflow (from the predefined internal value) ? and use this "trigger" for an interrupt to scale down the output-voltage (PWM?)

@Remark - Sorry I misunderstood - the comparators are only on X2s available ....

kr
Pierre
 
Last edited:

AllyCat

Senior Member
Hi,

The comparators do exist in the "silicon" of M2 PICaxes, but can be accessed only by PEEK/POKESFR commands. They can be read by the program or output to a pin, or even used to trigger a latch to "remember" short spikes. But there is quite a lot to read about them in the "base" Microchip PIC Data Sheet (which has about 500 pages in total).

However, the M2 "interrupts" only support inputs on pins, not internal flags. Furthermore, a single pin cannot (normally) be used as both an input and output at the same time. So to generate an interrupt, it is necessary to output the comparator on its allocated pin and externally link that to a second (input) pin.

Cheers, Alan.
 
Top