Timing Pulses over a wide range

dennis

Member
I have an LDR detecting electricity meter LED flashes (one flash every 1Wh cosumed). The LDR is in a voltage divider set up with a 57K resistor and the mid point goes to an 08M. This set up seems immune to daylight and detects flashes without problem.

Each time the 08M detects a flash it increments a word variable and sends it to a second 08M via a Maplin 433MHz link (as described by Hippy)

The second 08M sends the word variable to the PC serial port via the standard download collector. The data is displayed in Excel via PLX-DAQ (free download).

Analysis consists of checking for missing data by seeing if the word variable has incremented by one. The power in W is then calculated by dividing 3600 by the time interval in secs(derived from the PC clock since the last reading) . This works fine but suffers from the limitation that the time used is in integer seconds only.

I now want to eliminate the PC and instead display the power consumption on an LCD.
That means finding some alternative method to accurately time the pulses. The time between pulses can vary from as little as 0.25 secs to around 50 seconds.

Can the DS1307 be used for this ?
As I understand it from the data sheet the DS1307 gives a standard output in integer seconds but has an output that can be set to give 4096 pulses /sec. That would however mean counting about 200 000 pulses to correspond to the longest period. So I suppose a word variable would need to be incremented and a count kept of the number of overflows.
With only 244 us between pulses it seems a lot to do.

Would an X1 part be more suitable using the timer facility ?

Are there any other simple methods that come to mind ?
 

westaust55

Moderator
More a few thoughts on your project than a firm solution.

The DS1307 can be used to time stamp the data or as a pulse generator.
You can also consider a DS1338 which is:
- pin for pin compatible and has the same 56 bytes of NV RAM,
- can be used at lower voltages than the DS1307
- can be used with the i2cfast keyword

You are going to need i2c comms to set the DS1307/DS1338 time and or pulse output in the first instance, so why not change one of the PICAXE chips to an 18X.

Method of timing and calculation is dependant on the accuracy you desire.
Time resolution from a DS1307 RTC is only 1 second.

You could consider counting the pulses from the RTC as you suggest via an interrupt – to better avoid missing a pulse. But at 4096 Hz that is, as you say, a pulse every 244usec. At 4MHz PICAXE speed you may not achieve your goal with that, as it is too fast to do anything else. You would need to consider stepping up the PICAXE speed to say 16MHz to have a chance.

Then when you have a signal from the 433MHz receiver module read the current count from the pulses and do the maths for kW for display on the LCD.
 

dennis

Member
westaust55 Thanks for your thoughts.

For a reasonable accuracy the time resolution needs to much better than 1 sec. Do you think this concept could work ?

The 08M at the meter end continually counts pulses from a 50 Hz source (wall wart) into a word variable. Each time round the loop the counter is incremented by one. (the capacity before overflow would be about 20 mins which is fine). The loop cycle time is then 20 ms.

The LDR set up detecting the meter flashes is connected to another pin and triggers an interrupt. The interrupt routine transmits the word variable, resets it to zero, then returns to the counter loop.
Assuming the interrupt routine can be accomplished in less than 20 ms then only one 50Hz pulse might potentially be lost which is probably acceptable (5.5% error at 10kW but only 0.55% at 1kW). I am not sure how long th transmission takes so will need to make some tests on this.


The receiver end then just needs to receive the signal scale it and display on an LCD . I have this working on a breadboard using an 08M without problems.
 

BeanieBots

Moderator
My understanding is that the 'light' pulses every X units of electricity used.
So, why not have the light pulse trigger an interrupt which increments a counter.
Then, in the main loop, keep checking the RTC and when a certain period has elapsed, (eg 6 minutes), reset that counter and increment a "pulses per hour counter" or whatever unit is suitable for your use.
ie, no timing of individual pulses. Just count them up over a period of time.
 

inglewoodpete

Senior Member
I realise you are doing your current development on an 08M but I would suggest using a 28x1 or 20x2. That way, everything can be done in one chip: no external timers, counters or clocks.

Consider this: Have the LDR cause interrupts to the main routine. Run the internal hardware timer (SetTimer command) and set the major tick in the range 20 to 100mS. On every interrupt (caused by the kWh meter), read the current major tick value, subtract it from the previous one and save the new value for the next interrupt. Possibly reinitialise the timer, too. The result should give you multiples of the major tick value chosen. The heavier your power usage, the smaller the tick count.
 

dennis

Member
BeanieBots thanks for your comment - Yes each pulse corresponds to 0.001 kWh or 1Wh consumed. Because consumption can vary between about 10kW and 80W the times vary between about 0.4 to 45 seconds.

Part of the fascination is to see as quick a response as possible from say turning off a walwart and to see the immediate increase when a 3kW kettle is turned on for a couple of minutes. I think that to do this I have to time the interval between individual pulses rather than collecting them in a fixed time period.

inglewoodpete Thanks for the idea. The hardware simplicity is appealing and I will get a 28X1 and try this out. In the meantime on to the simulator !
 

hippy

Technical Support
Staff member
You can possibly avoid needing a high speed timer by having two algorithms. Say with a one second timer ( as that's convenient ) you can time between pulses arriving slower than one second or count how many pulses within one second. The faster the timer runs the more accurate readings will be when low wattage but there's no real advantage when higher wattage. This is similar to a bike speedo where wheel rotation drops at low speed.
 

dennis

Member
I now have a system working and it has been an excellent learning process. I think I have managed to combine most beginners errors into a single project and sorting them out has been fun.

3 08Ms (on breadboards ) are used. 08Ms 1 and 2 a are connected together and located at the electricity meter in the garage . 08M 3 is in the house.

08M Number one uses an LDR and counts pulses from a neon light on a plug using the ADC function. I soldered a diode in series with the neon and that made readabilty much more reliable as well as dropping the frequency to 50Hz. This picaxe simply loops incrementing a counter and continually (every 20ms) outputs the value to the second 08M using the serout function.

08M Number 2 uses an LDR directly and waits for a meter flash (1Wh per flash). As soon as a flash is detected the counter value from 08M1 is acquired using Serin and the elapsed number of pulses determined. This is then converted to power by first dividing into 60000 and then multiplying by 3. The power value is then transmitted to 08M Number 3 via a 433MHz link (basic AM type from Maplin as detailed on Hippy's site)

08M Number 3 waits for new data using serin and then displays the power using the serial LCD from RevEd.

It is fascinating to stroll round the house turning stuff on and off etc and watching the display. Reaction is quick when loads are added but slow when turned off.

There is scope to react more quickly to load shedding. As an extreme example if the background load was only 100W meter flashes and updates would only occur every half minute or so. Turn on a 3 kW kettle and detection is near instant as flashes come every second. Turn it off and there could be a half minute wait for an update.

A flash not arriving in say 5 secs indicates that power must be less than 750 W so it looks like I need to count non arriving flashes as well ! More fun to come.


I also need to develop a novel display. It needs to be much more eye catching than the AXE non backlit LCD to persuade youngsters to pay attention and turn off stuff.

Anyone got any good ideas for a simple dispay ?
 

womai

Senior Member
For the display have a look at www.crystalfontz.com - they have a large selection of very nice displays for reasonable prices. You should look for character displays with either serial interface (easy to use but more expensive) or with parallel interface. I especially like the one with white font on blue background - looks classy.
 
Top