My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- Title: GP2D02 IR ranger library
-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
-- Adapted-by:
-- Compiler: >=2.4k
-- Revision: $Revision$
--
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the ZLIB license (http://www.opensource.org/licenses/zlib-license.html)
--
-- Description: this lib is able to handle the GP2D02 lib, reading distance
-- measure with this IR Ranger.
-- --
-- You can either use the read procedure, or access the pseudo-variable
-- to retrieve distance measures.
-- --
-- When defining pins the ranger is connected to to, it's important to
-- set them as "volatile" (level will go low/high within function call)
-- See sample(s) for more.
--
-- Notes: reading a distance can take quite a long time, approx. 74ms.
-- See datasheet for more, but you should remember this while using this IR ranger
--
-- Sources:
-- - datasheet: http://www.datasheetcatalog.org/datasheet/Sharp/mXvryzu.pdf
--



include delay


function gp2d02_read_pins(volatile bit out pin_vin, volatile bit in pin_vout) return byte is
-- See GP2D02 for detailed specs
var byte range = 0b_0000_0000
-- pin_in to 1: ready for next range
pin_vin = high
-- pin_in to 0: request for read
pin_vin = low
-- wait 70ms
delay_1ms(70)

-- ok, actually read the measure
for 8 loop
pin_vin = high
delay_10us(10)
pin_vin = low
delay_10us(10)
-- read bit from pin vout
range = range << 1
-- append bit 1 to the end
-- preserving previous bits
-- if ranger is on
if pin_vout == high
then
-- append bit 1 to the end
-- preserving previous bits
range = range | 0b_0000_0001
end if
end loop

-- inactivate ranger
pin_vin = high
delay_1ms(2)
pin_vin = low

-- done, return the results
return range

end function


Change log

r2760 by sebastien.lelong on Jul 31, 2011   Diff
added Revision: field + svn:keywords
Revision property on all existing *.jal
files. Also add to normalize EOL chars to
avoid mixed ones
Go to: 
Project members, sign in to write a code review

Older revisions

r924 by sebastien.lelong on Apr 10, 2009   Diff
issue-46: lib + test + sample for
GP2D02 libs
r863 by sebastien.lelong on Mar 16, 2009   Diff
 issue 46  / GP2D02: first draft lib +
sample, still need tests
All revisions of this file

File info

Size: 1913 bytes, 71 lines

File properties

svn:keywords
Revision
Powered by Google Project Hosting