20X2 Parallel Task

TheChief

Senior Member
I know that the X2 range does not support parallel processing. Im wondering is there a way I can work around this for a particular situation.
What I want to do is set a timer and then count pulses in on a pin for a period. Once the number of pulses have been counted for that period I want to process that data, however I do not wish the processing of this data to interfere with the collection of new pulses ie. the counting of pulses should continue in the "background" while the processing of the sampled data occurs. Would it be possible perhaps to use an interrupt on the input pin which could achieve this? the interrupt could then increment a variable by 1 and reset to listen again in the "background"?
Would this approach even be possible?
 

nick12ab

Senior Member
How fast are the pulses to be counted?

It's definately possible to count the pulses with the PICAXE manually, as long as the pulses being counted aren't too fast.

The interrupt would definately work, however if the input pulses are too fast then the interrupt routine could hog the processor as the other code gets no chance to execute.

Another way is to use IF statements in the processing loop - this requires that the processing loop is quite quick and can't count quite as fast (but still quite fast) but you can easily make sure that sufficient processing is done and the CPU won't be hogged by the counting if the counting becomes too fast.
 

TheChief

Senior Member
In this application they will be slow. I will be trying to sample pulses from an old analogue electricity meter using some technique such as an IR diode setup perhaps. I wanted to use the "background" method to ensure a high accuracy. I've read several posts in various places around the whole apparent accuracy of some of the commercial products on the market. Most of them are rubbish and over priced.
 

inglewoodpete

Senior Member
The 20X2 is one of my favorite PICAXEs. It is a very powerful microcontroller with just 20 pins, making it easier to accomodate hardware-wise.

I would use the hardware interupt feature of the 20X2. As long as the repetition rate of the incomong pulses is below about 800/second you should be able to write some code to count the pulses in your interrupt routine, using a background timer for time supervision. Meanwhile, the foreground code would utilise the data that is collected.

As a starting point, have a look at the project that I posted here. It's not exactly what you want but it demonstrates all of the principles that you will need.
 
Top