PDA

View Full Version : Count Per Second



oslinux
- 21st March 2007, 19:04
Hi all,

i've got a question for you,

I've a Geiger-Muller Tube, an instrument for measuring radiations, which gives me an output in the form of a pulse of minimum 90uS,

i need to measure the number of pulses per second with the minimal possible error,

cause the pulse is minimum 90uS every second i can have at max
1.000.000uS / 90uS = 11.111 CPS (Counts Per Second)

this means that every 5 seconds i have to store the variable in an I2C memory (To be downloaded in a PC)

i was thinking to something like a loop to check for the pulses and store them in a RAM word-sized variable and use an interrupt that every 5 seconds store the variable into the I2C mem,

like this:

GEIGER VAR PORTD.0
CNT VAR WORD
ADD VAR WORD
CONTROL VAR BYTE

CONTROL = $A0
ADD = 0

CheckLoop:
IF GEIGEG THEN
CNT = CNT + 1
ENDIF
GOTO CheckLoop

IntHand:
I2CWRITE SDA,SCL,CONTROL,ADD,[CNT]
ADD = ADD + 1
CNT = 0
RESUME

Do you think it would suit me? (I don't know a lot about pic timing...)
there would be a better way to count or to check for the pulse? (i'm not interested in the pulse lenght)
(Please ignore the missing TMR or INTCONT)

Thank you,

Luca

HenrikOlsson
- 21st March 2007, 19:57
Hi,
If that's the only thing the PIC will do this may work:


GEIGER VAR PORTD.0
CNT VAR WORD
ADD VAR WORD
CONTROL VAR BYTE

Start:
CNT = 0
COUNT GEIGER, 5000, CNT 'Count pulses for 5 seconds, store in CNT.
Gosub SaveData
Goto Start

SaveData:
'Save data to EEPROM here
RETURN


/Henrik Olsson.

skimask
- 22nd March 2007, 00:44
Hi,
If that's the only thing the PIC will do this may work:


GEIGER VAR PORTD.0
CNT VAR WORD
ADD VAR WORD
CONTROL VAR BYTE

Start:
CNT = 0
COUNT GEIGER, 5000, CNT 'Count pulses for 5 seconds, store in CNT.
Gosub SaveData
Goto Start

SaveData:
'Save data to EEPROM here
RETURN


/Henrik Olsson.

Assuming you don't get over 65,535 pulses...
What happens if you overflow too early? I've never tried, but does COUNT kick out before 5 seconds if it hits 65,535, does it roll over...
And don't forget, COUNT is entirely dependant upon the PICs oscillator speed and will only count low to high transitions (not that either of those should matter much).

HenrikOlsson
- 22nd March 2007, 06:17
Hi,


Assuming you don't get over 65,535 pulses...

Yes, but you don't since each pulse is said to be 90uS or longer... About the oscillator speed, yes, COUNT depends on the accuracy of the oscillator but so does any other method I can think of.

/Henrik Olsson.

oslinux
- 22nd March 2007, 11:59
Cause i have pulses not shorter than 90uS, i can have a max of 11.111 pulses per second, in 5 seconds i can have a max of 55.555 pulses, there's a way to count for more than 5 seconds, (In other words, there's a way to use a variable longer than a word, like a double word) ?

with a double word i could count up to 4.294.967.296 which is 386.550 seconds!

thank you,

Luca

ronsimpson
- 22nd March 2007, 16:00
I had a similar problem where the count might exceed 65000.
I divided up the COUNT into 4 COUNTS.
It can be argued that there is holes between each COUNT. It does work! Don't think about the holes. time=4 seconds
rons
COUNT GEIGER, 1000, CNT1
COUNT GEIGER, 1000, CNT2
COUNT GEIGER, 1000, CNT3
COUNT GEIGER, 1000, CNT4

skimask
- 22nd March 2007, 17:01
I had a similar problem where the count might exceed 65000.
I divided up the COUNT into 4 COUNTS.
It can be argued that there is holes between each COUNT. It does work! Don't think about the holes. time=4 seconds
rons
COUNT GEIGER, 1000, CNT1
COUNT GEIGER, 1000, CNT2
COUNT GEIGER, 1000, CNT3
COUNT GEIGER, 1000, CNT4

And those 'holes' between COUNT statements will be on the order of a few microseconds anyways and since the pulses are > 90us, it should catch them.

oslinux
- 22nd March 2007, 17:21
ok, so i will use one word variable every 5 seconds, everything into an array, and every 500 seconds i will put the array in an external eeprom, this should work!

Now it's only up to the EEPROM that's not working :D (In the other topic)

Thank you!

Luca

skimask
- 22nd March 2007, 17:48
ok, so i will use one word variable every 5 seconds, everything into an array, and every 500 seconds i will put the array in an external eeprom, this should work!

Now it's only up to the EEPROM that's not working :D (In the other topic)

Thank you!

Luca

Which PIC are you using anyways?

HenrikOlsson
- 22nd March 2007, 18:15
Hi,


ok, so i will use one word variable every 5 seconds, everything into an array, and every 500 seconds i will put the array in an external eeprom, this should work!

I may be missing some key information here but why store it in array? Why not count for 5 seconds, write the value to the EEPROM, increase adress pointer by one (or two), reset count and start over?

/Henrik Olsson.

oslinux
- 22nd March 2007, 22:17
PIC16F877A

If i store it in an array, i can write it directly via a page write in the external I2C EEPROM, i can't store in the EEPROM every 5 seconds, because it takes more than 10mS.

Luca

mister_e
- 22nd March 2007, 22:22
PBP count is bul**** anyways, use a PIC timer for that. It will do the job in background.

From your sampling time you substract the needed time to write to your eeprom.

NOW you have something acurate. Unless, it's pure crap.

oslinux
- 22nd March 2007, 23:58
please explain what do you mean for a "Pic timer",

P.S.: i'm going to bed, here it's 1:00 A.M....

skimask
- 23rd March 2007, 03:13
please explain what do you mean for a "Pic timer",

P.S.: i'm going to bed, here it's 1:00 A.M....

Check the datasheet, tmr0, tmr1, tmr2, whichever...

oslinux
- 23rd March 2007, 14:46
AAAH but it doesn't have the limit of 1 byte??

so you mean, when it's counting, i'm storing the data in the eeprom, right?

and with another timer i can count the seconds i have to sample, and stop the sampling at the right moment?

aniway it sound a bit complex to me... what happens if i geto to 255 counts while i'm writing the eeprom?

i'm going to see if there's a WORD timer,

Luca

mister_e
- 23rd March 2007, 14:50
Timer1, T1CKI pin on PORTC if my memory serves me well.

oslinux
- 23rd March 2007, 15:16
yes, so timer1 with interrupt enabled, on interrupt i write to the eeprom, AND timer0 (Linked to another pic which produce a 1Hz frequency) with interrupt enabled, on timer0 interrupt i stop the sampling and place the last word in the eeprom, should this work?

Thx

Luca