Author: sebastien.lelong
Date: Mon Mar 16 10:40:37 2009
New Revision: 863
Added:
trunk/include/external/ranger/ir/ir_ranger_gp2d02.jal
trunk/sample/16f88_ir_ranger_gp2d02.jal
trunk/test/external/ranger/
trunk/test/external/ranger/ir/
trunk/test/external/ranger/ir/test_ir_ranger_gp2d02.jal
Modified:
trunk/test/board/board_16f88_sl.jal
Log:
issue 46 / GP2D02: first draft lib + sample, still need tests
Added: trunk/include/external/ranger/ir/ir_ranger_gp2d02.jal
==============================================================================
--- (empty file)
+++ trunk/include/external/ranger/ir/ir_ranger_gp2d02.jal Mon Mar 16
10:40:37 2009
@@ -0,0 +1,90 @@
+-- Title: GP2D02 IR ranger library
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4j
+--
+-- 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
+
+if !(defined(GP2D02_COUNT) == true) then
+ const byte GP2D02_COUNT = 1
+end if
+
+-- will store couple (pin_vin,pin_vout)
+var byte GP2D02_ARRAY[GP2D02_COUNT * 2]
+
+procedure gp2d02_register(byte in idx, bit in pin_vin, bit in pin_vout) is
+ GP2D02_ARRAY[idx] = pin_vin
+ GP2D02_ARRAY[idx+1] = pin_vout
+end procedure
+
+function gp2d02_read_pins(bit in pin_vin, 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
+
+function gp2d02_read(byte in idx) return byte is
+ -- retrieve corresponding pin for ranger num.idx
+ var volatile bit pin_vin = GP2D02_ARRAY[idx]
+ var volatile bit pin_vout = GP2D02_ARRAY[idx+1]
+ var byte measure = gp2d02_read_pins(pin_vin,pin_vout)
+ return measure
+end function
+
+
+
Added: trunk/sample/16f88_ir_ranger_gp2d02.jal
==============================================================================
--- (empty file)
+++ trunk/sample/16f88_ir_ranger_gp2d02.jal Mon Mar 16 10:40:37 2009
@@ -0,0 +1,110 @@
+-- Title: Test program for GP2D02 IR ranger
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4j
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: this sample show how to use GP2D02 IR ranger library
+-- It regularly gets distance measures, and print them back to serial.
+-- It also uses a LED to "show" the distance:
+-- - when the distance is low (object is closed from the ranger),
+-- the LED will blink very fast
+-- - when the distance is high (object is far way from the ranger),
+-- the LED will blink very slow
+-- - when the distance is to high (nothing detected), the LED is on, no
+-- blinking
+-- --
+--
+--
+--
+-- This file has been generated on Mon Mar 16 18:41:14 2009, from:
+-- * board: board_16f88_sl.jal
+-- * test : test_ir_ranger_gp2d02.jal
+--
+
+
+;@jallib section chipdef
+-- chip setup
+include 16f88
+
+;--
+-- We'll use internal oscillator. It work @ 8MHz
+pragma target clock 8_000_000
+pragma target OSC INTOSC_NOCLKOUT
+-- Specify no postscaler, ie. really runs @8MHz
+OSCCON_IRCF = 0b_111
+pragma target WDT disabled -- no watchdog
+pragma target LVP disabled -- no low-voltage programming
+pragma target CCP1MUX RB0 -- ccp1 pin on B0
+pragma bootloader long_start -- for TinyBootloader
+
+enable_digital_io()
+;@jallib section led
+-- LED IO definition
+var bit led is pin_b3
+var bit led_direction is pin_b3_direction
+var bit led2 is pin_b1
+var bit led2_direction is pin_b1_direction
+
+include delay
+;@jallib section serial
+const serial_hw_baudrate = 57_600
+include serial_hardware
+serial_hw_init()
+
+;@jallib section gp2d02
+var volatile bit gp2d02_vin is pin_a4
+var volatile bit gp2d02_vout is pin_a6
+var bit gp2d02_vin_direction is pin_a4_direction
+var bit gp2d02_vout_direction is pin_a6_direction
+include ir_ranger_gp2d02
+-- set pin direction (careful: "vin" is the GP2D02 pin's name,
+-- and is an output, not an input...)
+gp2d02_vin_direction = output
+gp2d02_vout_direction = input
+-- now register these pins as ranger num. 0
+gp2d02_register(0,gp2d02_vin,gp2d02_vout)
+
+
+-- Flash a litlle to show we're alive !
+led_direction = output
+for 4 loop
+ LED = on
+ delay_100ms(3)
+ LED = off
+ delay_100ms(3)
+end loop
+
+var byte measure1
+var byte measure2
+var byte mean
+var word tmp
+forever loop
+
+ -- read distance from ranger num. 0
+ measure1 = gp2d02_read(0)
+ -- you can also pass a couple of (pin_vin,pin_vout)
+ -- to save stack and code space
+ measure2 = gp2d02_read_pins(gp2d02_vin,gp2d02_vout)
+ -- results via serial
+ serial_hw_write(measure1)
+ serial_hw_write(measure2)
+ -- compute the mean
+ tmp = (measure1 + measure2) / 2
+ -- cast to byte (can't be more than byte, since
+ -- it's a mean...)
+ mean = byte(tmp)
+ serial_hw_write(measure2)
+
+ -- now blink more or less
+ for 10 loop
+ LED = on
+ delay_1ms(mean)
+ LED = off
+ delay_1ms(mean)
+ end loop
+
+end loop
+
Modified: trunk/test/board/board_16f88_sl.jal
==============================================================================
--- trunk/test/board/board_16f88_sl.jal (original)
+++ trunk/test/board/board_16f88_sl.jal Mon Mar 16 10:40:37 2009
@@ -76,3 +76,9 @@
-- ccp setup
var volatile bit pin_ccp1_direction is pin_b0_direction
+;@jallib section gp2d02
+var volatile bit gp2d02_vin is pin_a4
+var volatile bit gp2d02_vout is pin_a6
+var bit gp2d02_vin_direction is pin_a4_direction
+var bit gp2d02_vout_direction is pin_a6_direction
+
Added: trunk/test/external/ranger/ir/test_ir_ranger_gp2d02.jal
==============================================================================
--- (empty file)
+++ trunk/test/external/ranger/ir/test_ir_ranger_gp2d02.jal Mon Mar 16
10:40:37 2009
@@ -0,0 +1,83 @@
+-- Title: Test program for GP2D02 IR ranger
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4j
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: this sample show how to use GP2D02 IR ranger library
+-- It regularly gets distance measures, and print them back to serial.
+-- It also uses a LED to "show" the distance:
+-- - when the distance is low (object is closed from the ranger),
+-- the LED will blink very fast
+-- - when the distance is high (object is far way from the ranger),
+-- the LED will blink very slow
+-- - when the distance is to high (nothing detected), the LED is on, no
+-- blinking
+-- --
+--
+--
+
+;@jallib use chipdef
+enable_digital_io()
+
+;@jallib use led
+
+include delay
+
+;@jallib use serial
+include serial_hardware
+serial_hw_init()
+
+
+;@jallib use gp2d02
+include ir_ranger_gp2d02
+-- set pin direction (careful: "vin" is the GP2D02 pin's name,
+-- and is an output, not an input...)
+gp2d02_vin_direction = output
+gp2d02_vout_direction = input
+-- now register these pins as ranger num. 0
+gp2d02_register(0,gp2d02_vin,gp2d02_vout)
+
+
+-- Flash a litlle to show we're alive !
+led_direction = output
+for 4 loop
+ LED = on
+ delay_100ms(3)
+ LED = off
+ delay_100ms(3)
+end loop
+
+var byte measure1
+var byte measure2
+var byte mean
+var word tmp
+forever loop
+
+ -- read distance from ranger num. 0
+ measure1 = gp2d02_read(0)
+ -- you can also pass a couple of (pin_vin,pin_vout)
+ -- to save stack and code space
+ measure2 = gp2d02_read_pins(gp2d02_vin,gp2d02_vout)
+ -- results via serial
+ serial_hw_write(measure1)
+ serial_hw_write(measure2)
+ -- compute the mean
+ tmp = (measure1 + measure2) / 2
+ -- cast to byte (can't be more than byte, since
+ -- it's a mean...)
+ mean = byte(tmp)
+ serial_hw_write(measure2)
+
+ -- now blink more or less
+ for 10 loop
+ LED = on
+ delay_1ms(mean)
+ LED = off
+ delay_1ms(mean)
+ end loop
+
+end loop
+
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---