missing a beat when busy elsewhere

rmeldo

Senior Member
Hi,

I am trying to measure and log energy consumption of a house appliance as well as temperatures off 2 thermocouples and 3 DS18B20.


I have gone down the route of:

1) Buying a second hand energy meter (the ones used by the electricity board). The meter flashes a LED 1000 per kWh, at a frequency of 0 to 4 Hz.

2) Building a sensing circuit as described in http://ciseco.co.uk/forum/viewtopic.php?f=15&t=59 After some calibration of the variable potentiometer I got the pulse long enough to be catchable by a listening Picaxe through an interrupt. I don't know how long the inpulse from the meter lasts, but I know I could potentially miss it if I was in the process of writing to a LCD screen.


This means that a Picaxe could not do anything else but listen for the pulse. Instead I need it to read the temperatures, read the time from an AXE033, write to the EEPROM and display on the LCD.

Apart from listening to the pulses all other activities are not time critical as the logging frequency is once every 15 minutes. Nevertheless if the Picaxe is busy with any of them it will miss a beat.

I am caught in a vicious circle.

Is there a clever way of counting the pulses, maybe with a different chip (a counter? is there such a thing?) or something else and then read it with the Picaxe (say a 28X1)?

METHOD 1:
I thought of this, but please suggest something else if you think it would work better:

1) Use an 8M to count the pulses and increase by one the duty cycle of a PWMOUT command. Also listen for a "dute cycle" reset (a pin held high?) from the main Picaxe
2) convert the PWM signal into a voltage signal in some ways (resistors, capacitors, inductance?)

3) use readac10 on the mainPicaxe to read the integrated signal.


I don't particularly like this method for various reasons:

a) it seems complicated
b) the resolution of the PWM and of the readadc10 are the same and this calls for the need for great accuracy (and linearity)of the integration device
c) by listening for the duty cycle reaset on with the countig 8M I could still miss a bit


METHOD 2:

I could increase the value of the 4k7 resistor to increase the charge time of the 1uF capacitor in the circuit http://ciseco.co.uk/forum/viewtopic.php?f=15&t=59, therefore making the pulse longer and allowing some extra time to do other things. Still that would not solve the problem as the readtemp12 takes up to 750 ms to execute.


I think I a m stuck here. I would welcome suggestions or pointers

Thanks

Riccardo
 

goom

Senior Member
What about using a counter (one with a reset) to monitor the pulses. The PICAXE could read from it every, say, 1 minute, then immediately reset it.
 

lbenson

Senior Member
Or use the 08M to do the counting in a loop. When a flash is detected, have it increment a count, assert a pin, and continue looping to count while also in the loop checking another pin from the main PICAXE. If no response from the main program, 08M keeps counting up on detecting a flash. After a response the 08M lowers its pin, decrements the counter, and checks (while looping) for the return of the responding pin to 0V. When that is detected, if the counter is greater than zero, it again asserts its pin and the cycle continues. This should account for varying busy times on the part of the master PICAXE. This should be doable (on the 08M side) in the simulator.
 
Last edited:

jglenn

Senior Member
Maybe an interrupt would help. Use to avoid missing something happening.

Many chips have counter-timers, a hardware section, but I don't think the basic allows running them, not sure. Have to get a new printer to get copies of the manuals, soon. Digital counter chips like the 4520 are great, but will have a bit pattern output you need to input. Use an I2C port to scan it. Chips are adding up. I do like the subsystem approach though, having sections that process I/O makes the master controller jobs easier, and the software simpler.
 

papaof2

Senior Member
I used interrupt on an 08M running at 8MHz to monitor a water flow meter. The meter provides 820 pulses/gallon and the water flow rate was 4 gallons/minute. That's about 55 pulses/second. The 08M also did sertxd of the accumulated gallons every 0.1 gallon. I can't guarantee that it never missed a count, but the numbers appeared to be correct.

Will your meter provide more than 55 pulses/second? If not, my experience says that an 08M will probably work.

John
 

jglenn

Senior Member
I am curious to know if the interrupts on the picaxe are "real" interrupts, like in a microcontroller. There is an ISR, Interrupt Service Routine, and the hardware interrupt causes the current environment to be stored, on a stack, then the ISR is called. The original PIC chips used a synthetic interrupt concept that was really just super fast polled I/O. Software tricks if you will. Not that it matter, I don't have any need for them at this time, still hooking things up to try real program. :p
 

BeanieBots

Moderator
PICAXE interrupts are not 'real' interrupts such as those people associate with micro interrupts. The pin status is polled between each command.
With commands taking a very long time such as the 750mS for a readtemp, it is possible to miss a 'pulse' of less then 750mS duration.

There are many ways around this. If you are happy to expand to a "X1" device then, use the one wire commands for readtemp to avoid the need to wait for the 750mS. Interrupts should then catch all the pulses.
 

Jeremy Leach

Senior Member
Well I think you could use a 28X1 with the SetTimer command, using it in External Counter mode. This would allow you to count pulses in the background.

Alternatively you could venture into a multi-picaxe solution, which is good fun. Have a dedicated 08M detecting/counting the pulses, and (when convenient) passing this information onto your 'master' 18X or whatever is suitable.
 

steliosm

Senior Member
I've used the 28X1 with the SetTimer command to measure energy consumption and it worked like a charm :)
Since you are using a 'bigger' chip you may also utilize other functions on it, e.g.. add a SimpleLan module to have a Web Interface to your energy meter or even yet to have a way to export data for a collector process running on a pc (small script) to be able to read.
 

hippy

Ex-Staff (retired)
Once commands ( READTEMP ) take longer than the interval between data arrival there will be problems of lost data unless some hardware mechanism is used to catch or count that data whilst the PICAXE is busy.

Using SETTIMER on an X1 is the best way forward and it should be possible to configure the same on some PICAXE's using PEEK and POKE to the right SFR's. That would mean reading the PICmicro datasheet and some experimenting.

I do like the solution from lbenson in post #3 which is quite elegant. I haven't tried that but my gut feeling is that should be good for up to 1kHz signals, maybe more.
 

MFB

Senior Member
N&V again

There is a very good article about serial coms between an 08M and the scratchpad memory of a 28X1 by Ron Hackett in the February issue of Nuts & Volts magazine. Full of generally useful information about receiving serial data in the background with the use of interrupts.
 

rmeldo

Senior Member
Thanks guys,

there is a lot of food for thought.

I'll do my reading now.

I am beginning to like the idea of using a dedicated 8M, as it would make the pulse detecting circuit standalone and not time critical.... as well as fun.

Also I hadn't clocked (pardon the pun) that there is the option of running at higher frequency to effectively expand the Picaxe's time base.

I will probably need to do some time budgeting. Searching the forum I found the following timings, courtesy of BB.

http://www.picaxeforum.co.uk/showthr...light=commands

Is it the most comprehensive and up to date?


Thanks again for the volume and diversity of responses.

Riccardo
 
Top