Author: sebastien.lelong
Date: Sat Jan 3 02:06:43 2009
New Revision: 709
Added:
trunk/include/peripheral/pwm/pwm_hardware.jal
trunk/sample/test/peripheral/pwm/test_pwm_led.jal
trunk/sample/test/peripheral/pwm/test_pwm_led_highres.jal
trunk/sample/test/peripheral/pwm/test_pwm_sound.jal
Modified:
trunk/TORELEASE
trunk/sample/by_device/16f88/16f88_pwm_led.jal
trunk/sample/by_device/16f88/16f88_pwm_led_highres.jal
trunk/sample/by_device/16f88/16f88_pwm_sound.jal
Log:
issue 54, pwm_hardware lib: includes apropriate underlying libs + convert
pwm samples to tests, regenerate and test them
Modified: trunk/TORELEASE
==============================================================================
--- trunk/TORELEASE (original)
+++ trunk/TORELEASE Sat Jan 3 02:06:43 2009
@@ -159,6 +159,7 @@
include/peripheral/pwm/pwm_ccp4.jal
include/peripheral/pwm/pwm_ccp5.jal
include/peripheral/pwm/pwm_common.jal
+include/peripheral/pwm/pwm_hardware.jal
include/peripheral/usart/serial_hardware.jal
include/peripheral/usart/serial_hw_int_cts.jal
include/peripheral/usart/serial_software.jal
Added: trunk/include/peripheral/pwm/pwm_hardware.jal
==============================================================================
--- (empty file)
+++ trunk/include/peripheral/pwm/pwm_hardware.jal Sat Jan 3 02:06:43 2009
@@ -0,0 +1,50 @@
+-- Title: hardware PWM control
+-- Author: Sebastien Lelong, Copyright (C) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4i
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the ZLIB license
(http://www.opensource.org/licenses/zlib-license.html)
+--
+-- Description: just include this library if you want to use PWM.
+-- Why this one ? It uses to conditional compile to selectively include
+-- appropriate underlying pwm libs and number of PWM channels (up to 5),
+-- according to the PIC configuration.
+-- --
+-- Ex: - 16f88 has 1 PWM channel: including pwm_hardware will configure PWM
+-- for 1 channel (using pwm_ccp1.jal)
+-- - 16f877 has 2 PWM channels: including pwm_hardware will configure
PWM
+-- for 2 channels (using pwm_ccp1.jal and pwm_ccp2.jal)
+-- --
+-- This is transparent for the user
+-- --
+-- Please refer to pwm_common, pwm_ccp1, pwm_ccp2, ... and pwm_ccp5
documentation
+-- to understand how to use PWM.
+--
+-- Notes: this libraries uses conditional compilation. It requires
+-- at least jalv2 2.4i compiler version
+--
+
+
+
+if(defined(CCP1CON) == true) then
+ include pwm_ccp1
+end if
+
+if(defined(CCP2CON) == true) then
+ include pwm_ccp2
+end if
+
+if(defined(CCP3CON) == true) then
+ include pwm_ccp3
+end if
+
+if(defined(CCP4CON) == true) then
+ include pwm_ccp4
+end if
+
+if(defined(CCP5CON) == true) then
+ include pwm_ccp5
+end if
+
+
Modified: trunk/sample/by_device/16f88/16f88_pwm_led.jal
==============================================================================
--- trunk/sample/by_device/16f88/16f88_pwm_led.jal (original)
+++ trunk/sample/by_device/16f88/16f88_pwm_led.jal Sat Jan 3 02:06:43 2009
@@ -1,7 +1,7 @@
--- Title: Sample using hardware (built-in) PWM, in low resolution mode
--- Author: Sebastien Lelong, Copyright (c) 2008, all rights reserved.
+-- Title: Test program for 1 PWM channel, using a LED
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
-- Adapted-by:
--- Compiler: >=2.4g
+-- Compiler: >=2.4i
--
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
@@ -10,47 +10,57 @@
-- It progressively light up and down a LED. Sweet...
--
--
+----
+-- This file has been generated on Sat Jan 3 10:55:37 2009, from:
+-- * board: board_16f88_sl.jal
+-- * test : test_pwm_led.jal
--
-
--- select chip
+;@jallib section chipdef
+-- chip setup
include 16f88
--- set all IO as digital
-enable_digital_io()
+;--
-- 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
--- no watchdog, please
-pragma target WDT disabled
+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
+
+;@jallib section ccp
+-- ccp setup
+var volatile bit pin_ccp1_direction is pin_b0_direction
+enable_digital_io()
-- Configure PWM
-pin_b0_direction = output
-include pwm_ccp1
+pin_ccp1_direction = output
+include pwm_hardware
pwm_max_resolution(1)
pwm1_on()
forever loop
- var byte i
- i = 0
- -- loop up and down, to produce different duty cycle
- while i < 250 loop
- pwm1_set_dutycycle(i)
- _usec_delay(10000)
- i = i + 1
- end loop
- while i > 0 loop
- pwm1_set_dutycycle(i)
- _usec_delay(10000)
- i = i - 1
- end loop
- -- turning off, the LED lights at max.
- _usec_delay(500000)
- pwm1_off()
- _usec_delay(500000)
- pwm1_on()
-
+ var byte i
+ i = 0
+ -- loop up and down, to produce different duty cycle
+ while i < 250 loop
+ pwm1_set_dutycycle(i)
+ _usec_delay(10000)
+ i = i + 1
+ end loop
+ while i > 0 loop
+ pwm1_set_dutycycle(i)
+ _usec_delay(10000)
+ i = i - 1
+ end loop
+ -- turning off, the LED lights at max.
+ _usec_delay(500000)
+ pwm1_off()
+ _usec_delay(500000)
+ pwm1_on()
+
end loop
Modified: trunk/sample/by_device/16f88/16f88_pwm_led_highres.jal
==============================================================================
--- trunk/sample/by_device/16f88/16f88_pwm_led_highres.jal (original)
+++ trunk/sample/by_device/16f88/16f88_pwm_led_highres.jal Sat Jan 3
02:06:43 2009
@@ -1,59 +1,68 @@
--- Title: Sample using hardware (built-in) PWM, in high resolution mode
--- Author: Sebastien Lelong, Copyright (c) 2008, all rights reserved.
--- Adapted-by:
--- Compiler: >=2.4g
---
--- 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 shows how to use PWM in high resolution mode
--- It lights up and down an LED.
---
---
-
--- select chip
-;;include 16f877
-include 16f88
--- set all IO as digital
-enable_digital_io()
-
--- 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
--- no watchdog, please
-pragma target WDT disabled
-
-
--- Configure PWM
-pin_b0_direction = output
-include pwm_ccp1
-pwm_max_resolution(1)
-pwm1_on()
-
-
-forever loop
-
- var word i
- i = 0
-
- -- High resolution means up to 10bits values (duty < 1024)
- while i < 1020 loop
- pwm1_set_dutycycle_highres(i)
- _usec_delay(50000)
- i = i + 10
- end loop
- while i > 0 loop
- pwm1_set_dutycycle_highres(i)
- _usec_delay(50000)
- i = i - 10
- end loop
-
- _usec_delay(500000)
- pwm1_off()
- _usec_delay(500000)
- pwm1_on()
-
-end loop
-
+-- Title: Test program for hardware (built-in) PWM, in high resolution
mode, using a LED
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4i
+--
+-- 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 shows how to use PWM in high resolution mode
+-- It lights up and down an LED.
+--
+----
+-- This file has been generated on Sat Jan 3 10:55:52 2009, from:
+-- * board: board_16f88_sl.jal
+-- * test : test_pwm_led_highres.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
+
+;@jallib section ccp
+-- ccp setup
+var volatile bit pin_ccp1_direction is pin_b0_direction
+
+enable_digital_io()
+
+-- Configure PWM
+pin_ccp1_direction = output
+include pwm_hardware
+pwm_max_resolution(1)
+pwm1_on()
+
+
+forever loop
+
+ var word i
+ i = 0
+
+ -- High resolution means up to 10bits values (duty < 1024)
+ while i < 1020 loop
+ pwm1_set_dutycycle_highres(i)
+ _usec_delay(50000)
+ i = i + 10
+ end loop
+ while i > 0 loop
+ pwm1_set_dutycycle_highres(i)
+ _usec_delay(50000)
+ i = i - 10
+ end loop
+
+ _usec_delay(500000)
+ pwm1_off()
+ _usec_delay(500000)
+ pwm1_on()
+
+end loop
+
Modified: trunk/sample/by_device/16f88/16f88_pwm_sound.jal
==============================================================================
--- trunk/sample/by_device/16f88/16f88_pwm_sound.jal (original)
+++ trunk/sample/by_device/16f88/16f88_pwm_sound.jal Sat Jan 3 02:06:43
2009
@@ -1,7 +1,7 @@
--- Title: Sample using hardware (built-in) PWM. Plays sound
+-- Title: Test program for hardware (built-in) PWM. Plays sound
-- Author: Sebastien Lelong, Copyright (c) 2008, all rights reserved.
-- Adapted-by:
--- Compiler: >=2.4g
+-- Compiler: >=2.4i
--
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
@@ -12,39 +12,50 @@
-- the buzzer, because frequency is too low (no valid combination of
PR2/T2CON)
--
--
+----
+-- This file has been generated on Sat Jan 3 10:55:21 2009, from:
+-- * board: board_16f88_sl.jal
+-- * test : test_pwm_sound.jal
--
-
--- select chip
+;@jallib section chipdef
+-- chip setup
include 16f88
--- set all IO as digital
-enable_digital_io()
+;--
-- 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
--- no watchdog, please
-pragma target WDT disabled
+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
+
+;@jallib section ccp
+-- ccp setup
+var volatile bit pin_ccp1_direction is pin_b0_direction
+
+enable_digital_io()
-- Configure PWM
-pin_b0_direction = output
-include pwm_ccp1
+pin_ccp1_direction = output
+include pwm_hardware
-- Let's go !!!
pwm1_on()
var dword counter = 0
forever loop
-
- for 100_000 using counter loop
- pwm_set_frequency(counter)
- -- Setting @50% gives max volume
- -- must be re-computed each time the frequency
- -- changes, because it depends on PR2 value
- pwm1_set_percent_dutycycle(50)
- end loop
-
+
+ for 100_000 using counter loop
+ pwm_set_frequency(counter)
+ -- Setting @50% gives max volume
+ -- must be re-computed each time the frequency
+ -- changes, because it depends on PR2 value
+ pwm1_set_percent_dutycycle(50)
+ end loop
+
end loop
Added: trunk/sample/test/peripheral/pwm/test_pwm_led.jal
==============================================================================
--- (empty file)
+++ trunk/sample/test/peripheral/pwm/test_pwm_led.jal Sat Jan 3 02:06:43
2009
@@ -0,0 +1,47 @@
+-- Title: Test program for 1 PWM channel, using a LED
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4i
+--
+-- 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 PWM in low resolution mode.
+-- It progressively light up and down a LED. Sweet...
+--
+--
+--
+
+;@jallib use chipdef
+;@jallib use ccp
+
+enable_digital_io()
+
+-- Configure PWM
+pin_ccp1_direction = output
+include pwm_hardware
+pwm_max_resolution(1)
+pwm1_on()
+
+forever loop
+ var byte i
+ i = 0
+ -- loop up and down, to produce different duty cycle
+ while i < 250 loop
+ pwm1_set_dutycycle(i)
+ _usec_delay(10000)
+ i = i + 1
+ end loop
+ while i > 0 loop
+ pwm1_set_dutycycle(i)
+ _usec_delay(10000)
+ i = i - 1
+ end loop
+ -- turning off, the LED lights at max.
+ _usec_delay(500000)
+ pwm1_off()
+ _usec_delay(500000)
+ pwm1_on()
+
+end loop
+
Added: trunk/sample/test/peripheral/pwm/test_pwm_led_highres.jal
==============================================================================
--- (empty file)
+++ trunk/sample/test/peripheral/pwm/test_pwm_led_highres.jal Sat Jan 3
02:06:43 2009
@@ -0,0 +1,49 @@
+-- Title: Test program for hardware (built-in) PWM, in high resolution
mode, using a LED
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4i
+--
+-- 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 shows how to use PWM in high resolution mode
+-- It lights up and down an LED.
+--
+--
+
+;@jallib use chipdef
+;@jallib use ccp
+
+enable_digital_io()
+
+-- Configure PWM
+pin_ccp1_direction = output
+include pwm_hardware
+pwm_max_resolution(1)
+pwm1_on()
+
+
+forever loop
+
+ var word i
+ i = 0
+
+ -- High resolution means up to 10bits values (duty < 1024)
+ while i < 1020 loop
+ pwm1_set_dutycycle_highres(i)
+ _usec_delay(50000)
+ i = i + 10
+ end loop
+ while i > 0 loop
+ pwm1_set_dutycycle_highres(i)
+ _usec_delay(50000)
+ i = i - 10
+ end loop
+
+ _usec_delay(500000)
+ pwm1_off()
+ _usec_delay(500000)
+ pwm1_on()
+
+end loop
+
Added: trunk/sample/test/peripheral/pwm/test_pwm_sound.jal
==============================================================================
--- (empty file)
+++ trunk/sample/test/peripheral/pwm/test_pwm_sound.jal Sat Jan 3 02:06:43
2009
@@ -0,0 +1,42 @@
+-- Title: Test program for hardware (built-in) PWM. Plays sound
+-- Author: Sebastien Lelong, Copyright (c) 2008, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4i
+--
+-- 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 PWM with a constant duty cycle
and
+-- a variable frequency. It plays a "nice" melody (connect a small piezzo)
+-- Frequencies from 0 to 100_000Hz are played. At the beginning, no sound
will come
+-- the buzzer, because frequency is too low (no valid combination of
PR2/T2CON)
+--
+--
+--
+
+;@jallib use chipdef
+;@jallib use ccp
+
+enable_digital_io()
+
+-- Configure PWM
+pin_ccp1_direction = output
+include pwm_hardware
+-- Let's go !!!
+pwm1_on()
+
+
+var dword counter = 0
+forever loop
+
+ for 100_000 using counter loop
+ pwm_set_frequency(counter)
+ -- Setting @50% gives max volume
+ -- must be re-computed each time the frequency
+ -- changes, because it depends on PR2 value
+ pwm1_set_percent_dutycycle(50)
+ 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
-~----------~----~----~----~------~----~------~--~---