counter command comes in late

ciseco

Senior Member
Hi all,

I've just built a wireless electricity meter monitor and all is well, except that this bit of code is taking 12-13 secs to run (been 15 once), in my imagination it should be 60 secs+the output time (which cant be 2 to 5 secs)

The board is running from 4 x AA with a 3.3v 1117CDT LDO reg

I'm puzzled, this is the old rev 28x1 which I have to calibfreq-4 to get the comms working at 4800bps (newer rev seems a lot better)

Miles

Code:
main:
count 4,60000,w3
sertxd ("   COUNTER-",#w3,"--")
serout XBEEdataoutPIN,BAUD,("aR",s1,s2,"C",#w3,"------")
goto main
________
mflb
 
Last edited:

Wrenow

Senior Member
OK, let's see if I have this right - you are running it speeded up, and included no pauses, and are worried that it is running too fast?

I am guessing you are expecting the program to take .001 sec to run through the loop, right? I am not conversant enough to opine whether this is about what this loop should take, but I am thinking you could tune it with a pauseus if you are looking for 60 seconds.


Cheers,

Wreno
 

ciseco

Senior Member
Hi,

Not speeded up, running at 4mhz on the internal Resonator. No not running too fast, sorry if I gave that impression

count 4,60000,w3 is essentially count me the number of pulses on pin 4 within 60000usec or 60 secs

I dont want a pause it needs to be continuous

I seem to remember theres also a back ground counter, PH mason made mention of it but doing peeks and pokes, is this right guys? does it still run when doing a serin?

Cheers

Miles
________
og kush pictures
 
Last edited:

BCJKiwi

Senior Member
Count is actually in mSec, not uSec

Since this is an electricity meter and presumably you will also need RTC data against which to log the power usage, why not just take the 1 sec SQ wave pulse from an RTC chip and use an interrupt on that to give the 1 sec time base.
 
Last edited:

Technical

Technical Support
Staff member
works fine for us at 60s, maybe post your whole code... and check for a 16MHz resonator!
 

ciseco

Senior Member
Hi

sorry, you are right msec not usec

RTC, not really, the recieving PC timestamps the data, the sensor doesnt need to know anything but the correct amount of pulses. Doing this in the background would be better, than I can poll the sensor instead and the problem of it being out of time isnt an issue.

Here's the full code

cheers

miles

Code:
'-----------
'CISECO PLC (c) 2008 - Electricty monitor v1.0
init:
setfreq m4
disablebod
calibfreq -4
gosub XBEEwake
symbol BAUD=T4800_4'set baud rate
symbol XBEEdataoutPIN=4
symbol XBEEdatainPIN=7
symbol s1="M" 'serial code part 1
symbol s2="1" 'serial code part 2
high XBEEdataoutPIN' get xbee ready
pause 300
serout XBEEdataoutPIN,BAUD,("aA",s1,s2,"STARTED-") 'send alert to say the sensor has started
pause 300
'###############################################################################
main:
count 4,60000,w3
sertxd ("   COUNTER-",#w3,"--")
serout XBEEdataoutPIN,BAUD,("aR",s1,s2,"C",#w3,"------")
goto main
'###############################################################################
XBEEwake:
high 7'take XBee SLEEP pin high
high 2'take XBee DATA pin high
high 3'take XBee RESET pin high
return
'###############################################################################
XBEEsleep:
low 7'take XBee SLEEP pin low
low 2'take XBee DATA pin low
low 3'take XBee RESET pin low
return
________
vapir air one
 
Last edited:

hippy

Ex-Staff (retired)
"COUNT pin,60000,var" should take 60 seconds to execute ( give or take a bit ) so it's perhaps worthwhile testing it ( and other time periods ) with a sinple loop and toggling a LED ...

Code:
Do
  Count 4,60000,w3
  Toggle LED_PIN
Loop
I'd use a LED rather than SERTXD/SEROUT to remove them from being potential problem causes.

Test it without any CALIBFREQ than add any adjustment and compare. I wouldn't have expected significant difference.

Compare results on the old 28X1 and the new - you say it "seems a lot better" so maybe it's a firmware issue which has been fixed but not documented ?
 

ciseco

Senior Member
!!!ERROR, sorry I meant 62 to 63 seconds


Hi Hippy,

I use SMD chips so changing them over between two boards to do the test would be a joy, mmmm 2 x 28 pins twice then back again :)

Being able to count in the background would be the best solution if it'll do serin at the same time, counter would run out after 65.535 KWh but thats enough for now

How I imagine this to work is

Poll the device (picaxe is sitting waiting with serin, and counting in the background)

picaxe sends current value say 15

computer recieves the value and logs it

picaxe still counting

computer then sends back I've recieved 15, so it takes 15 off the counter value

repeat forever

This would be perfect, so that if the computer goes down the picaxe is still counting till its next request.

Hope that makes sense?

Cheers

Miles
________
hotbox vaporizers
 
Last edited:

ciseco

Senior Member
Hi,

Found the prof mason thing, anyone, any thoughts?

Miles

Code:
' T1COUNT.Bas  (PICAXE-28X)
'
'
' clock source ------------ PICAXE-28X (term 6) (T1CKI)
'
' copyright, Peter H Anderson, Baltimore, MD, April, '04

Symbol T1CONVal = B0
Symbol CounterH = B3
Symbol CounterL = B2
Symbol Counter = W1

     Poke $0F, 0	' clear high and low bytes of Timer1
     Poke $0E, 0

     Poke $10, $03	' Configure T1CON for Timer1 On, External Clock

Top:

     High 0
     Pause 100
     Low 0
     Peek $10, T1CONVal
     Peek $0F, CounterH
     Peek $0E, CounterL
     SerTxD (#T1CONVal, "  ", #CounterH, "  ", #CounterL, 13, 10)
     SerTxD (#Counter, 13, 10)
     Pause 1000
     GoTo Top
________
Honda CBX1000 picture
 
Last edited:

hippy

Ex-Staff (retired)
!!!ERROR, sorry I meant 62 to 63 seconds
So was the problem that COUNT is near 60 seconds consistently, just not bang-on 60 seconds ?

I use SMD chips so changing them over between two boards to do the test would be a joy, mmmm 2 x 28 pins twice then back again :)
I won't expound on the virtues of bread-boarding and prototyping; we'll just deal with what we have :)

Using TIMER1 to do background counting should work and you've also got TIMER2 which should also be usable to measure how long it was counting for but I've not tried either. It should be possible.
 

ciseco

Senior Member
hehehehehe, yeah it's near not exact, sorry for the mistype, I saw it was a couple of seconds out and mentally added 10 not 60, so so sorry

is there no standard picaxe command for these counters?

cheers

Miles
________
Suzuki TU250 history
 
Last edited:

hippy

Ex-Staff (retired)
Good point - 28X1/40X1 supports "timer" and associated commands and flags but I've no idea what they map to internally. All the rest have to be handled by PEEK and POKE.
 

ciseco

Senior Member
Cool, he states

T1CKI is on terminal 6 which may be used as an input. Note that this is bit0 of PICAXE PortC.

Is this the pin marked - In 6/out c6/hserout/kbclk (used already on board see diags)

or is it as I hope - In0/Outc0/timer clk? (which is free to use)



Pin outs - left to right on above picture, below pin outs on the PICAXE

01 - ADC 0 (8 or 10 bit resolution)
02 - ADC 1 (8 or 10 bit resolution)
03 - ADC 2 (8 or 10 bit resolution)
04 - ADC 3 (8 or 10 bit resolution)
05 - GND (0v)
06 - IN0 / out c0 / timer clock
07 - IN1 / out c1 / pwm1 / ON BOARD LED INDICATOR
08 - IN2 / out c2 / pwm2 / hpwm A
09 - IN3 / out c3 / i2c sci / spi sck
10 - IN4 / out c4 / i2c sda / spi sdi
11 - IN5 / out c5 / spi sdo
12 - GND (0v)
13 - OUT0
14 - OUT1 / hpwm C
15 - OUT2 / hpwm B
16 - OUT3
17 - OUT4 / hpwm D / slow speed serial out & XBee IN (reserved)
18 - OUT5 / ON BOARD RELAY if fitted
19 - GND (0v)
20 - +supply (5v)






Cheers

Miles
________
og kush
 
Last edited:

ciseco

Senior Member
Sorry,

That wasnt my intention at all, the next question is often, how is it wired, what goes where etc and had all the details to hand to clarify.

I'm just one guy, designing, coding and giving all that I do out for free, whilst trying to pay the bills. I might be involved in something commercial but it's all open source, not a penny to pay for individual use. Anyone can build this board for nothing if they so chose, I give out the code, the schematics and the board artwork, I'm struggling to see why I'm not furthering the "cause" so to speak and why you are cross with me, in respect of this post :(

Cheers for the answer Hippy, do you have a link to the spec sheet?

Miles
________
Honda Airwave history
 
Last edited:
Top