Revision: 1611
Author: sebastien.lelong
Date: Thu Jan 21 06:57:12 2010
Log: added frontpage + automate publishing + ADC intro + reorganize PWM
with intro and modified titles + updated changelog
http://code.google.com/p/jallib/source/detail?r=1611
Added:
/trunk/doc/dita/tutorials/Makefile
/trunk/doc/dita/tutorials/images/adc_16f877_diagram.jpg
/trunk/doc/dita/tutorials/images/adc_16f877_table.jpg
/trunk/doc/dita/tutorials/images/adc_16f88_ans.jpg
/trunk/doc/dita/tutorials/images/adc_16f88_diagram.jpg
/trunk/doc/dita/tutorials/tutorial_adc_intro.xml
/trunk/doc/dita/tutorials/tutorial_book.xml
/trunk/doc/dita/tutorials/tutorial_pwm_intro.xml
Modified:
/trunk/doc/dita/tutorials/tutorial_changelog.xml
/trunk/doc/dita/tutorials/tutorial_pwm1.xml
/trunk/doc/dita/tutorials/tutorial_pwm2.xml
/trunk/doc/dita/tutorials/tutorials.ditamap
=======================================
--- /dev/null
+++ /trunk/doc/dita/tutorials/Makefile Thu Jan 21 06:57:12 2010
@@ -0,0 +1,25 @@
+
+
+VERSION=dev
+
+prepare:
+ -rm -fr tmp
+ -mkdir tmp
+
+pdf: prepare
+ ant -f $$DITA_HOME/build_demo.xml
-Dprompt.ditamap.filename=`pwd`/tutorials.ditamap -Dprompt.output.type=pdf
-Dprompt.output.directory=`pwd`/tmp -Dprompt.output.confirm=y
+ mv `pwd`/tmp/tutorials.pdf `pwd`/tmp/Tutorial_Book_${VERSION}.pdf
+
+html: prepare
+ ant -f $$DITA_HOME/build_demo.xml
-Dprompt.ditamap.filename=`pwd`/tutorials.ditamap -Dprompt.output.type=web
-Dprompt.output.directory=`pwd`/tmp -Dprompt.output.confirm=y
+
+front: html
+ # this page is only dedicated to website, it needs to integrate TOC
+ # prepare generated TOC for web publishing
+ cd ../../../tools/japp && python htmlizer.py
japp_config.py ../../doc/dita/tutorials/tmp/toc.html
+ ant -Dargs.transtype=xhtml -Doutput.dir=`pwd`/tmp
-Dargs.input=`pwd`/tutorial_book.xml -Dargs.target=init -f
$$DITA_HOME/build.xml dita2xhtml
+ # the beauty and magic of sed :)
+ cat tmp/tutorial_book.html | sed -e '/Table of
Content/rtmp/topublish/content' -e "s...@version@#${VERSION}#g" >
tmp/tutorial_book.html.toc
+ mv tmp/tutorial_book.html.toc tmp/tutorial_book.html
+ mv tmp/topublish tmp/topublish.toc
+ cd ../../../tools/japp && python htmlizer.py
japp_config.py ../../doc/dita/tutorials/tmp/tutorial_book.html
=======================================
--- /dev/null
+++ /trunk/doc/dita/tutorials/images/adc_16f877_diagram.jpg Thu Jan 21
06:57:12 2010
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/doc/dita/tutorials/images/adc_16f877_table.jpg Thu Jan 21
06:57:12 2010
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/doc/dita/tutorials/images/adc_16f88_ans.jpg Thu Jan 21 06:57:12
2010
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/doc/dita/tutorials/images/adc_16f88_diagram.jpg Thu Jan 21
06:57:12 2010
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/doc/dita/tutorials/tutorial_adc_intro.xml Thu Jan 21 06:57:12
2010
@@ -0,0 +1,216 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- This document was created with Syntext Serna Free. -->
+<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd" []>
+<topic id="template_id">
+ <title>Analog-to-Digital Conversion (ADC)</title>
+ <prolog>
+ <author>Sébastien Lelong</author>
+ <publisher>Jallib Group</publisher>
+ </prolog>
+ <body>
+ <p id="firstcontent"><xref
href="http://en.wikipedia.org/wiki/Analog-to-digital_converter"
format="html">Analog-to-Digital Conversion</xref> is yet another nice
feature you can get with a PIC. It's basically used to convert a
voltage as an analog source (continuous) into a digital number
(discrete).</p>
+ <section>
+ <title>ADC with water...</title>
+ <p id="firstcontent_1">To better understand ADC, imagine you have
some water going out of a pipe, and you'd like to know how many water
it goes outside. One approach would be to collect all the water in a
bucket, and then measure what you've collected. But what if water flow
never ends ? And, more important, what if water flow isn't constant
and you want to measure the flow in real-time ?</p>
+ <p id="firstcontent_2">The answer is ADC. With ADC, you're
going to extract samples of water. For instance, you're going to put a
little glass for 1 second under the pipe, every ten seconds. Doing the
math, you'll be able to know the mean rate of flow.</p>
+ <p id="firstcontent_3">The faster you'll collect water, the
more accurate the rate will be. That is, if you're able to collect 10
glasses of water each second, you'll have a better overview of the
rate of water than if you collect 1 glass each ten seconds. This is the
process of making a continous flow a discrete, finite value. And this is
about <b>resolution</b>, one important property of ADC (and this is also
about clock speed...). The higher the resolution, the more accurate the
results.</p>
+ <p id="firstcontent_5">Now, what if the water flow is so high that
your glass gets filled before the end of the sample time ? You could use a
bigger glass, but let's assume you can't (scenario need...). This
means you can't measure any water flow, this one has to be scaled
according to your glass. On the contrary, the water flow may be so low
samples you extract may not be relevant related to the glass size (only few
drops). Fortunately, you can use a smaller glass (yes, scenario need) to
scale down your sample. That is about <b>voltage reference</b>, another
important property.</p>
+ <p id="firstcontent_4">Leaving our glass of water, many PICs provide
several <b>ADC channels</b>: pins that can do this process, measuring
voltage as input. In order to use this peripheral, you'll first have
to configure how many ADC channels you want. Then you'll need to
specify the <b>resolution</b>, usually using 8 bits (0 to 255), 10 bits (0
to 1024) or even 12 bits (0 to 4096). Finally, you'll have to setup
<b>voltage references</b> depending on the voltage spread you plan to
measure.</p>
+ </section>
+ <section>
+ <title>ADC with jallib...</title>
+ <p>As usual, Microchip PICs offers a wide choice configuring ADC:<ul>
+ <li>N<b>ot all PICs</b> have ADC module (...)</li>
+ <li>Analog pins are <b>dispatched differently</b> amongst PICs,
still for user's sake, they have to be automatically configured as
input. We thus need to know, for each PIC, where analog pins are...</li>
+ <li>Some PICs have their <b>analog pins dependent</b> from each
other, and some are <b>independent</b> (more on this later)</li>
+ <li><b>Clock configuration</b> can be different</li>
+ <li>As previously stated, some PICs have <b>8-bits low
resolution</b> ADC module, some have <b>10-bits high resolution</b> ADC
module<fn> and some have 12-bits, those aren't currently handled by
jallib ADC libraries, That's a restriction.</fn></li>
+ <li>Some PICs can have <b>two voltage references</b> (VRef+ and
VRef-), only <b>one voltage reference</b> (Vref+) and some <b>can't
handle voltage references at all</b></li>
+ <li>(and probably other differences I can't
remember :)...</li>
+ </ul></p>
+ <p>Luckily most of these differences are transparent to users...</p>
+ </section>
+ <section>
+ <title>Dependent and independent analog pins</title>
+ <p>OK, let's write some code ! But before this, you have to
understand one very important point: some PICs have their analog pins
<i>dependent</i> from each other, some PICs have their analog pins
<i>independent</i> from each other. "What is this suppose to
mean ?" I can hear...</p>
+ <p>Let's consider two famous PICs: 16F877 and 16F88. 16F877
datasheet explains how to configure the number of analog pins, and vref,
setting <b>PCFG bits</b>:</p>
+ <p><fig>
+ <title>16F877 ADC channels are controlled by PCFG bits</title>
+ <image href="images/adc_16f877_table.jpg" width="400"
placement="break" otherprops="clickable"/>
+ </fig></p>
+ <p>Want 6 analog pins, no Vref ? Then PCFG bits must be set to
0b1001. What will then be the analog pins ? RA0, RA1, RA2, RA3, RA5 and
RE0. "<i>What if I want 7 analog pins, no Vref ?</i>" You
can't because you'll get a Vref pin, no choice. "<i>What if
I want 2 analog pins being RE1 and RE2 ?</i>" You can't, because
there's no such combination. So, for this PIC, <b>analog pins are
dependent from each other</b>, driven by a combination. In this case,
you'll have to specify: <ul>
+ <li>the <b>number of ADC channels</b> you want,</li>
+ <li>and <i>amongst</i> them, the <b>number of Vref
channels</b></li>
+ </ul></p>
+ <p>Now, let's consider 16F88. In this case, there's no
such table:</p>
+ <p><fig>
+ <title>16F88 ADC channels are controlled by ANS bits</title>
+ <image href="images/adc_16f88_ans.jpg" width="400"
placement="break" otherprops="clickable"/>
+ </fig></p>
+ <p>Mmmh... OK, there are <b>ANS bits</b>, one for each analog pins.
Setting an ANS bit to 1 sets the corresponding pin to analog. This means I
can set whatever pin I want to be analog. "<i>I can have 3 analog
pins, configured on RA0, RA4 and RB6. Freedom !</i>"</p>
+ <p><b>Analog pins are independent</b> from each other in this case,
you can do what you want. As a consequence, since it's not driven by a
combination, you won't be able to specify the number of ADC channels
here. Instead, you'll use <codeph>set_analog_pin()</codeph> procedure,
and if needed, the reverse <codeph>set_digital_pin()</codeph> procedure.
These procedures takes a analog pin number as argument. Say analog pin AN5
is on pin RB6. To turn this pin as analog, you just have to write
<codeph>set_analog_pin(5)</codeph>, because this is about analog pin
AN<b>5</b>, and not RB<b>6</b>.
+</p>
+ <note type="remember">as a consequence, these procedures don't
exist when analog pins are dependent as in our first case.</note>
+ <note type="caution">it's not because there are PCFG bits that
PICs have dependent analog pins. Some have PCFG bits which act exactly the
same as ANS bits (like some of recent 18F) </note>
+ <note type="tip">how to know if your PIC has dependent or
independent pins ? First have a look at its datasheet, if you can a table
like the one for 16F877, there are dependent. Also, if you configure a PIC
with dependent pins as if it was one with independent pins (and
vice-versa), you'll get an error. Finally, if you get an error like:
"<i>Unable to configure ADC channels. Configuration is supposed to be
done using ANS bits but it seems there's no ANS bits for this PIC.
Maybe your PIC isn't supported, please report !</i>", or the
like, well, this is not a normal situation, so as stated, please
report !</note>
+ <p>Once configured, using ADC is easy. You'll find
<codeph>adc_read()</codeph> and <b>adc_read_low_res()</b> functions, for
respectively read ADC in high and low resolution. Because low resolution is
coded on 8-bits, <codeph>adc_read()</codeph> returns a
<codeph>byte</codeph> as the result. <b>adc_read_low_res()</b> returns a
<codeph>word</codeph>.</p>
+ </section>
+ <section>
+ <title>Example with 16F877, dependent analog pins</title>
+ <p>The following examples briefly explains how to setup ADC module
when analog pins are dependent from each other, using PIC 16F877.</p>
+ <p>The following diagram is here to help knowing where <b>analog
pins</b> (blue) are and where <b>Vref pins</b> (red) are:</p>
+ <p><fig>
+ <title>Analog pins and Vref pins on 16F877</title>
+ <image href="images/adc_16f877_diagram.jpg" width="400"
placement="break" otherprops="clickable"/>
+ </fig></p>
+ <p><b>Example 1</b>: <i>16F877, with only one analog pin, no voltage
reference</i></p>
+ <p><codeblock>-- beginning is about configuring the chip
+-- this is the same for all examples for about 18F877
+include 16f877
+-- setup clock running @20MHz
+pragma target OSC HS
+pragma target clock 20_000_000
+-- no watchdog
+pragma target WDT disabled
+pragma target LVP disabled
+enable_digital_io()
+include delay
+
+-- ok, now setup serial, we'll use this
+-- to get ADC measures
+const serial_hw_baudrate = 19_200
+include serial_hardware
+serial_hw_init()
+
+
+-- ok, now let's configure ADC
+-- we want to measure using low resolution
+-- (that's our choice, we could use high resolution as well)
+const bit ADC_HIGH_RESOLUTION = false
+-- we said we want 1 analog channel...
+const byte ADC_NCHANNEL = 1
+-- and no voltage reference
+const byte ADC_NVREF = 0
+-- now we can include the library
+-- note it's now named "adc", not "adc_hardware"
anymore
+include adc
+-- and run the initialization step
+adc_init()
+
+
+-- will periodically send those chars
+var byte measure
+forever loop
+ -- get ADC result, on channel 0
+ -- this means we're currently reading on pin RA0/AN0 !
+ measure = adc_read_low_res(0)
+ -- send it back through serial
+ serial_hw_write(measure)
+
+ -- and sleep a litte to prevent flooding serial...
+ delay_1ms(200)
+end loop
+</codeblock></p>
+ <p><b>Example 2</b>: <i>16F877, with 5 analog pins, 1 voltage
reference, that is, Vref+ </i></p>
+ <p>This is almost the same as before, except we now want 5 (analog
pins) + 1 (Vref) = <b>6 ADC channels</b> (yes, I consider Vref+ pin as an
ADC channel).</p>
+ <p>The beginning is the same, here's just the part about ADC
configuration and readings:</p>
+ <p><codeblock>const bit ADC_HIGH_RESOLUTION = false
+-- our 6 ADC channel
+const byte ADC_NCHANNEL = 6
+-- and one Vref pin
+const byte ADC_NVREF = 1
+-- the two parameters could be read as:
+-- "I want 6 ADC channels, amongst which 1 will be
+-- reserved for Vref, and the 5 remaining ones will be
+-- analog pins"
+include adc
+adc_init()
+
+-- will periodically send those chars
+var byte measure
+forever loop
+ -- get ADC result, on channel 0
+ -- this means we're currently reading on pin RA0/AN0 !
+ measure = adc_read_low_res(0)
+ -- send it back through serial
+ serial_hw_write(measure)
+
+ -- same for pin RA1/AN1
+measure = adc_read_low_res(1)
+ serial_hw_write(measure)
+
+ -- same for pin RA2/AN2
+measure = adc_read_low_res(2)
+ serial_hw_write(measure)
+
+-- pin RA3/AN3 can't be read, since it's Vref+
+
+-- same for pin RA5/AN4
+-- 4 is from from "AN4" !
+ measure = adc_read_low_res(4)
+ serial_hw_write(measure)
+
+-- same for pin RE10/AN5
+ measure = adc_read_low_res(5)
+ serial_hw_write(measure)
+
+ -- and sleep a litte to prevent flooding serial...
+ delay_1ms(200)
+end loop </codeblock></p>
+ </section>
+ <section>
+ <title>Example with 16F88, independent analog pins</title>
+ <p>The following example is about setting up ADC module with PIC
16F88, where analog pins are independent from each other.</p>
+ <p>The following diagram is here to help knowing where <b>analog
pins</b> (blue) are and where <b>Vref pins</b> (red) are:</p>
+ <p><fig>
+ <title>Analog pins and Vref pins on 16F88</title>
+ <image href="images/adc_16f88_diagram.jpg" width="400"
placement="break" otherprops="clickable"/>
+ </fig></p>
+ <p><b>Example 1</b>: <i>16F88, analog pins on RA0/AN0, RA4/AN4 and
RB6/AN5. No voltage reference. </i></p>
+ <p><codeblock>-- beginning is about configuring the chip
+include 16f88
+-- We'll use internal oscillator. It work @ 8MHz
+pragma target CLOCK 8_000_000
+pragma target OSC INTOSC_NOCLKOUT
+OSCCON_IRCF = 0b_111
+pragma target WDT disabled
+enable_digital_io()
+
+-- ok, now setup serial, we'll use this
+-- to get ADC measures
+const serial_hw_baudrate = 19_200
+include serial_hardware
+serial_hw_init()
+
+-- now configure ADC
+const bit ADC_HIGH_RESOLUTION = false
+const byte ADC_NVREF = 0
+-- we can't specify a number of ADC channel here,
+-- or we'll get an error !
+include adc
+adc_init()
+-- now we declare the pin we want as analog !
+set_analog_pin(0) -- RA0/AN0
+set_analog_pin(4) -- RA4/AN4
+set_analog_pin(5) -- RB6/AN5
+
+-- reading is then the same
+var byte measure
+forever loop
+
+ measure = adc_read_low_res(0)
+ serial_hw_write(measure)
+
+ measure = adc_read_low_res(4)
+ serial_hw_write(measure)
+
+ measure = adc_read_low_res(5)
+ serial_hw_write(measure)
+
+end loop</codeblock></p>
+ <p>Whether you would want to turn RB6/AN5 into a digital pin again,
you'd just call:</p>
+ <p><codeblock>set_digital_pin(5)</codeblock></p>
+ </section>
+ <p>OK, enough for today, in next tutorials, we'll use our
breadboard to practice what we learned here.</p>
+ </body>
+</topic>
=======================================
--- /dev/null
+++ /trunk/doc/dita/tutorials/tutorial_book.xml Thu Jan 21 06:57:12 2010
@@ -0,0 +1,24 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- This document was created with Syntext Serna Free. --><!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd" []>
+<topic id="template_id">
+ <title>The Tutorial Book</title>
+ <prolog>
+ <author>Jallib Team</author>
+ <publisher>Jallib Group</publisher>
+ </prolog>
+ <body>
+ <p><image href="images/logo.jpg" width="200" align="center"
placement="break"/></p>
+ <section>
+ <title>
+ <b>Have fun with PIC microcontrollers, Jal v2 and Jallib</b>
+ </title>
+ <p><b>Step-by-step tutorials, covering basic features of PIC
microcontrollers, using jalv2 compiler and jallib libraries (version
@VERSION@)</b></p>
+ </section>
+ <p id="firstcontent">This is the online HTML version of "The
Tutorial Book" PDF version. You can also <xref
href="http://jallib.googlecode.com/files/tutorial_bo...@[email protected]"
format="html">download</xref> the PDF version from Jallib download <xref
href="http://code.google.com/p/jallib/downloads/list"
format="html">section</xref>, where you'll also jallib packages needed
to experiment tutorials.</p>
+ <p>We hope you'll enjoy the journey and... have fun !</p>
+ <p>The Jallib Team</p>
+ <section>
+ <title>Table of Content</title>
+<!--keep the following empty, this is a placeholder for generated
TOC--> </section>
+ </body>
+</topic>
=======================================
--- /dev/null
+++ /trunk/doc/dita/tutorials/tutorial_pwm_intro.xml Thu Jan 21 06:57:12
2010
@@ -0,0 +1,34 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
+<topic id="template_id">
+ <title>Pulse Width Modulation (PWM)</title>
+ <prolog>
+ <author>Sébastien Lelong</author>
+ <publisher>Jallib Group</publisher>
+ </prolog>
+ <body>
+ <p id="firstcontent">In the following tutorials, we're going to
(try to) have some fun with PWM. PWM stands for <xref
href="http://en.wikipedia.org/wiki/PWM" format="html">Pulse Width
Modulation</xref>, and is quite weird when you first face this (this was at
least my first feeling). So here's a brief explanation of what it is
about.</p>
+ <section>
+ <title>How does PWM look like ?...</title>
+ <p>PWM is about switching one pin (or more) high and low, at
different frequencies and duty cycles. This is a on/off process. You can
either vary:<ul>
+ <li>the <b>frequency</b>,</li>
+ <li>or the <b>duty cycle</b>, that is the proportion where the
pin will be high</li>
+ </ul><fig>
+ <title>PWM: same duty cycle, different frequencies.</title>
+ <image href="images/pwm_freq.png" placement="break"/>
+ <p><i>Both have a 50% duty cycle (50% on, 50% off), but the
upper one's frequency is twice the bottom</i></p>
+ </fig><fig>
+ <title>PWM: same frequency, different duty cycles</title>
+ <image href="images/pwm_duty.png" placement="break"/>
+ <p><i>Three different duty cycle (10%, 50% and 90%), all at the
same frequency</i></p>
+ </fig></p>
+ <p>But what is PWM for ? What can we do with it ? Many things,
like:<ul>
+ <li>producing variable voltage (to control DC motor speed, for
instance)</li>
+ <li>playing sounds: duty cycle is constant, frequency is
variable</li>
+ <li>playing PCM wave file (PCM is Pulse Code Modulation)</li>
+ <li>...</li>
+ </ul></p>
+ </section>
+ <p>That said, we're now goind to experiment these two major
properties.</p>
+ </body>
+</topic>
=======================================
--- /trunk/doc/dita/tutorials/tutorial_changelog.xml Wed Jan 20 12:26:02
2010
+++ /trunk/doc/dita/tutorials/tutorial_changelog.xml Thu Jan 21 06:57:12
2010
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
-<!-- This document was created with Syntext Serna Free. --><!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd" []>
+<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="template_id">
<title>Changelog</title>
<prolog>
@@ -21,16 +21,20 @@
</thead>
<tbody>
<row>
- <entry>2010/01/15</entry>
- <entry>New ICSP Schematic</entry>
+ <entry>2010/01/21</entry>
+ <entry>Added ADC introduction, re-organized PWM tutorials and
titles</entry>
+ </row>
+ <row>
+ <entry>2010/01/20</entry>
+ <entry>Better quality Images on Getting Started, serial board,
blink a led tutorials.</entry>
</row>
<row>
<entry>2010/01/19</entry>
<entry>Added serial & rs-232 tutorial</entry>
</row>
<row>
- <entry>2010/01/20</entry>
- <entry>Better quality Images on Getting Started, serial board,
blink a led tutorials.</entry>
+ <entry>2010/01/15</entry>
+ <entry>New ICSP Schematic</entry>
</row>
</tbody>
</tgroup>
=======================================
--- /trunk/doc/dita/tutorials/tutorial_pwm1.xml Sun Nov 8 01:04:16 2009
+++ /trunk/doc/dita/tutorials/tutorial_pwm1.xml Thu Jan 21 06:57:12 2010
@@ -1,35 +1,12 @@
<?xml version='1.0' encoding='UTF-8'?>
-<!-- This document was created with Syntext Serna Free. -->
-<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd" []>
+<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="topic-1">
- <title>Having fun with PWM and a LED (part 1)</title>
+ <title>Dimming a LED with PWM</title>
<prolog>
<author>Sébastien Lelong</author>
<publisher>Jallib Group</publisher>
</prolog>
<body>
- <p><xref href="http://en.wikipedia.org/wiki/PWM" format="html">Pulse
Width Modulation</xref>In this "Step-by-Step" tutorial,
we're going to (try to) have some fun with PWM. PWM stands for , and
is quite weird when you first face this (this was at least my first
feeling).</p>
- <section>
- <title>So, how does PWM look like ?...</title>
- <p>PWM is about switching one pin (or more) high and low, at
different frequencies and duty cycles. This is a on/off process. You can
either vary:<ul>
- <li>the <b>frequency</b>,</li>
- <li>or the <b>duty cycle</b>, that is the proportion where the
pin will be high</li>
- </ul><fig>
- <title>PWM: same duty cycle, different frequencies.</title>
- <image href="images/pwm_freq.png" placement="break"/>
- <p><i>Both have a 50% duty cycle (50% on, 50% off), but the
upper one's frequency is twice the bottom</i></p>
- </fig><fig>
- <title>PWM: same frequency, different duty cycles</title>
- <image href="images/pwm_duty.png" placement="break"/>
- <p><i>Three different duty cycle (10%, 50% and 90%), all at the
same frequency</i></p>
- </fig></p>
- <p>But what is PWM for ? What can we do with it ? Many things,
like:<ul>
- <li>producing variable voltage (to control DC motor speed, for
instance)</li>
- <li>playing sounds: duty cycle is constant, frequency is
variable</li>
- <li>playing PCM wave file (PCM is Pulse Code Modulation)</li>
- <li>...</li>
- </ul></p>
- </section>
<section>
<title>One PWM channel + one LED = fun </title>
<p>For now, and for this first part, we're going to see how to
<i>control the brightness of a LED</i>. If simply connected to a pin, it
will light at its max brightness, because the pin is "just" high
(5V).</p>
=======================================
--- /trunk/doc/dita/tutorials/tutorial_pwm2.xml Sun Nov 8 01:04:16 2009
+++ /trunk/doc/dita/tutorials/tutorial_pwm2.xml Thu Jan 21 06:57:12 2010
@@ -1,15 +1,14 @@
<?xml version='1.0' encoding='UTF-8'?>
-<!-- This document was created with Syntext Serna Free. -->
-<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd" []>
+<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="topic-1">
- <title>Having fun with PWM and a piezo buzzer (or a speaker) (part
2)</title>
+ <title>Producing sounds with PWM and a piezo buzzer</title>
<prolog>
<author>Sébastien Lelong</author>
<publisher>Jallib Group</publisher>
</prolog>
<body>
<p>In <xref href="tutorial_pwm1.xml">previous tutorial</xref>, we had
fun by controlling the brightness of a LED, using PWM. This time,
we're going to have even more fun with a <i>piezo buzzer</i>, or a
small <i>speaker</i>.</p>
- <p>If you remember, with PWM, you can either vary the <b>duty
cycle</b> or the <b>frequency</b>. Controlling the brightness of a LED, ie.
produce a variable voltage on the average, can be done by having a
<i>constant frequency</i> (high enough) and <i>vary the duty cycle</i>.
This time, this will be the opposite: we'll have a constant duty
cycle, and vary the frequency.</p>
+ <p>If you <xref href="tutorial_pwm_intro.xml">remember</xref>, with
PWM, you can either vary the <b>duty cycle</b> or the <b>frequency</b>.
Controlling the brightness of a LED, ie. produce a variable voltage on the
average, can be done by having a <i>constant frequency</i> (high enough)
and <i>vary the duty cycle</i>. This time, this will be the opposite:
we'll have a constant duty cycle, and vary the frequency.</p>
<section>
<title>What is a piezo buzzer ? </title>
<p>It's a "component" with a material having
<i>piezoelectric</i> ability. <xref
href="http://en.wikipedia.org/wiki/Piezoelectricity"
format="html">Piezoelectricity</xref> is the ability for a material to
produce voltage when it get distorted. The reverse is also true: <i>when
you produce a voltage, the material gets distorted</i>. When you stop
producing a voltage, it gets back to its original shape. If you're
fast enough with this on/off voltage setting, then <i>the piezo will start
to oscillate</i>, and will <b>produce sound</b>. How sweet...</p>
=======================================
--- /trunk/doc/dita/tutorials/tutorials.ditamap Sun Jan 17 23:35:40 2010
+++ /trunk/doc/dita/tutorials/tutorials.ditamap Thu Jan 21 06:57:12 2010
@@ -11,12 +11,12 @@
<year>2008</year>
</copyrfirst>
<copyrlast>
- <year>2009</year>
+ <year>2010</year>
</copyrlast>
<bookowner>
<organization>Jallib Group</organization>
</bookowner>
- <summary>Step by step tutorials, covering basic features of PIC
microcontrollers, using jalv2 compiler and jallib libraries. (version
0.2)</summary>
+ <summary>Step by step tutorials, covering basic features of PIC
microcontrollers, using jalv2 compiler and jallib libraries. (version
0.3)</summary>
</bookrights>
</bookmeta>
<frontmatter>
@@ -31,11 +31,11 @@
<topicref href="tutorial_serial_communication.xml"/>
</chapter>
<chapter href="tutorial_peripherals.xml">
- <topichead navtitle="Pulse Width Modulation (PWM)">
+ <topicref navtitle="Pulse Width Modulation (PWM)"
href="tutorial_pwm_intro.xml">
<topicref href="tutorial_pwm1.xml"/>
<topicref navtitle="Having fun with PWM and a piezo buzzer (part 2)"
href="tutorial_pwm2.xml"/>
- </topichead>
- <topichead navtitle="Analog-to-Digital Converter (ADC) -- TODO"/>
+ </topicref>
+ <topicref href="tutorial_adc_intro.xml"/>
<topichead navtitle="I²C">
<topicref href="tutorial_i2c1.xml"/>
<topicref href="tutorial_i2c2.xml"/>
--
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.