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
-- Title: Test program for hardware (built-in) PWM. Plays sound
-- Author: Sebastien Lelong, Copyright (c) 2008, all rights reserved.
-- Adapted-by:
-- Compiler: >=2.4i
-- Revision: $Revision$
--
-- 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)
--
--
--
--
-- This file has been generated on Sun Feb 8 11:05:56 2009, from:
-- * board: board_16f88_sl.jal
-- * test : test_pwm_sound.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
-- 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


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

r1338 by sebastien.lelong on Sep 21, 2009   Diff
more tutorials, updated PDF
All revisions of this file

File info

Size: 1824 bytes, 65 lines

File properties

svn:keywords
Revision
Powered by Google Project Hosting