Alain,
I already got it working weeks ago.
The issue is that I need to make it work at 4Mhz.
For new sampling, I am giving it more then it needs. (it needs 3.7mS, I give it 10mS).
BTW; I added Application note; sampling example to my post above.
Alain,
I already got it working weeks ago.
The issue is that I need to make it work at 4Mhz.
For new sampling, I am giving it more then it needs. (it needs 3.7mS, I give it 10mS).
BTW; I added Application note; sampling example to my post above.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Hi Sayzer.
As Alain said and after looking at the datasheets, there is no need for hyper speed controller. What the DS states, are the minimum pulse width that you are allowed to apply. So, in case you have an extra-super-duper-high-speed controller capable to output 1ps pulses the sensor won't be able to follow.
You can just apply the pulses as fast as possible for the unique reason, to get your data soon. Otherwise there is no need to hurry.
As I understood the procedure:
1. MCU applies a high pulse for at least 200ns
2. MCU enter Z-state and sensor understands that MCU will read now the data
3. Sensor outputs the data bit
4. MCU reads the data bit
5. MCU outputs new high pulse
etc...
All you have to do is repeat the cycle as fast as possible if you want "real time" surveilance.
Ioannis
Ioannis
Ok;
Thanks Alain and Ioannis.
Since the circuit worked very well at 20Mhz, I thought I was holding the sensor too long at 4Mhz. I must be having some other simple issue based on what you two have said.
I will work on this direction.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Hi, Ioannis
The problem here is the sensor "1" level lasts only 1µS ....
the only solution I see here is use an asm part to generate the high state and test the pin as soon as end of high state .
If i remember ... it's the trick used to test if a pin is low, high or Hi-Z ... !!!
( thanks for the last picture, Sayzer ...)
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Where is this 1µs? Did I missed it?
As I understood, the sensor will respond only when the MC enters Z-state.
Ioannis
P.S. Oh I got it. But Alain, this is settling time, not bit width time.
Last edited by Ioannis; - 11th December 2007 at 11:47.
Hi, Ioannis
looks the sensor output is seen by the PIC like a small capacitor ...and this capacitor is discharged by the low state of the pic pin ... not by the sensor itself.
this is a little confusing in the datasheet as the settling time is called as bitwidth time !!!
That explains why Ingvar's program works well ...
INPUT Datapin 'Let PIR control the Datapin
PIRdata.0(i) = Datapin 'Sample the datapin
surely need more than 1µs to be done !!! ...
Thanks, Ingvar ... we've learnt something !
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Alain, surely that was obvious .......Nah, must admit that it wasn't all that clear in the datasheet.
I figure the PIR must be driving the output with resistors since there would otherwise often be a collision when the MCU drives the pin. No good. Driving via resistors will always be sensitive to capacitance on the lead and therefore a settlingtime will be needed. I figured it had to be this way since they specified tbit as "Data bit settling time" with a 10pF load.
It is kind like the 1-wire of Dallas devices. They are active low with pull up resistors, so that collisions can be avoided.
Ioannis
My guess is that this code will work......
... it compiles and runs as expected. Only problem is that i don't have a PIR to verify it with, it does however look OK on a scope. If i have interpreted the datasheet correctly you should be flying.Code:@ device pic12F675, protect_off, mclr_off define OSC 4 DEFINE OSCCAL_1K 1 'Set OSCCAL for 1K device DataPin VAR GPIO.0 'DOCI on the PIR PIRdata VAR WORD i VAR BYTE ANSEL = 0 'No AD on 12F675 CMCON = %00010111 'Digital pins - no comparator WPU = 0 'No pullups WHILE 1 'Do forever HIGH GPIO.1 'Set a pin to time the reading GOSUB ReadPIR 'Call the Sub LOW GPIO.1 'Reset a pin to time the reading PAUSE 10 'Just something to sync the scope WEND ReadPIR: INPUT DataPin 'Let PIR control the Datapin PIRdata = 0 'Use this time to let Datapin settle WHILE DataPin = 0 : WEND 'Wait for PIR to indicate "new data" PAUSEUS 25 'Wait for PIR to fiddle with the data FOR i = 14 to 0 STEP -1 'Loop to get 15bits LOW DataPin 'Force Datapin Low HIGH Datapin 'Force Datapin High INPUT Datapin 'Let PIR control the Datapin ' You may need a short pause here if you have long wires to the PIR PIRdata.0(i) = Datapin 'Sample the datapin NEXT LOW DataPin 'Force Datapin Low INPUT Datapin 'Let PIR control the Datapin RETURN END
/Ingvar
Ingvar,
I tested your code a minute ago; with some additions;
Congratulations! It works flawlessly.
My code is almost the same as yours.
What I see here is that, when we set the pin HIGH and then LOW, the time it takes to set the pins is already good enough for the sensor reading.
Last edited by sayzer; - 11th December 2007 at 12:22.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Good to know that we have working code ... if i ever buy one of theese PIRs.
Bookmarks