Subject: Atmel programming tricks
From: Rotary Engine
Date: 5/27/2010, 3:53 PM
To: AAA Put this in the To box


 Linux can cut and paste out of pdf files but
 I am not sure that is possible in windows.

 In any event it is a good idea to get the programming docs
 out of the pdf and into text form so you can cut and paste
 comments and commands directly into your program.
 Here is a PWM example.

 snips......


pdf's can be images and or text.  If a pdf is made up of optically
scanned images of text which hasn't been converted by OCR to formatted
text, neither Linux now Windows will allow copy-paste to a text/source
document.  If a pdf is made up of formatted text, both Windows Linux
will allow copy-paste.

Matt-

Thanks Matt. It is obviously text.

*******************************************************************

Here is an updated text file on PWM.
This Pulse Width Modulation generation subject is almost a book.

This stuff is a severe challenge for my low grade moron IQ :)
Particular the section on the pin numbers of the ZX1280n.
I attempted to clarify the situation with this attached kindergarten jpg.
It is multidimensional so I used color.

*******************************************************************************

OpenPWM
 Type          Subroutine
 Invocation  OpenPWM(channel, frequency, mode)
            OpenPWM(channel, frequency, mode, stat)
 Parameter  Method    Type     Description
 channel    ByVal     Byte     The channel to use for PWM generation.
 frequency  ByVal     Single   The desired PWM frequency.
 mode       ByVal     Byte     The desired PWM mode (see discussion below).
 stat       ByRef     Boolean  The variable to receive the status code.

 Discussion
 This subroutine prepares a PWM channel for generating a
 pulse width modulated (PWM) signal. PWM
 generation is performed using one of the CPU’s 16-bit
 timers, the number of which varies depending on
 the ZX model. The table below indicates the available
 channels and the corresponding timer used. See
 the description of PWM() for additional details on the PWM
 channels.

  Supported 16-bit PWM Channels

  ZX Models .......  Timer1      Timer3    Timer4   Timer5

  ZX-1280, ZX-1280n  1, 2, 3     4, 5, 6   7, 8, 9   10, 11, 12

  The frequency parameter specifies the PWM base frequency in
  Hertz.  Since the same frequency and generation mode will
  be used for all PWM channels based on the same timer, it is
  only necessary to call OpenPWM() once to prepare the timer
  for all of the PWM channels that are based on a given
  timer.


 The mode parameter specifies the PWM generation
  mode.  Two modes are supported: Fast PWM mode and
  Phase/Frequency Correct mode.  The constants zxFastPWM and
  zxCorrectPWM, having the values 0 and 1 respectively, may
  be used to specify the mode.


 The Fast PWM mode has a
  maximum frequency of one-half of the CPU clock frequency
  and is intended for fixed-frequency applications.  The
  Phase/Frequency Correct PWM mode has a maximum frequency of
  one-quarter of the CPU clock frequency and may be used when
  the PWM frequency will be changed in the midst of PWM
  signal generation.


 Frequency changes are effected by
  making additional calls to OpenPWM() and the change is
  synchronized so that it takes effect at the beginning of a
  cycle.  The status parameter, if supplied, receives a value
  to indicate success or failure of the call.  A side effect
  of calling OpenPWM() is that the timer busy flag for the
  underlying timer (e.g.


 Register.Timer1Busy) will be set to
  True irrespective of its prior state.  It is recommended
  that the initial call to OpenPWM() be preceded by a call to
  acquire the semaphore for the timer.  This will ensure that
  an existing timer operation will not be disturbed.



 Example
 Call OpenPWM(1, 50.0, zxFastPWM)
 'prepare for 50Hz Fast PWM using channel 1

 Compatibility
 This subroutine is not available in BasicX compatibility mode.

 See Also    ClosePWM, PWM

 PWM
 Type              Subroutine
 Invocation        PWM(channel, dutyCycle)
                   PWM(channel, dutyCycle, status)
 Parameter  Method  Type                 Description
 channel    ByVal   Byte                 The channel to use for PWM generation.
 dutyCycle  ByVal   Single or integral   The desired duty cycle.
 status     ByRef   Boolean              The variable to receive the status value.

 Discussion
 This subroutine begins or modifies the generation of a
 16-bit PWM signal on the specified channel.  The
 channel must have been previously prepared for PWM
 generation by calling OpenPWM().

 PWM generation is performed using one of the CPU’s 16-bit
 timers, the number of which varies depending on
 the ZX model. The table below indicates the output pin for
 each PWM supported channel.


-----------------------------------------------------------------------------------------
                        Output Pins for 16-bit PWM Channel Numbers
------------------------------------------------------------------------
CXhannel Numbers .......1........2.......3.........4.......5........6
ZX-1280, ZX-1280n      24,B.5...25,B.6..26,B.7....5,E.3...6,E.4....7,E.5
----------------------------------------------------------------------
Channel Numbers........7........8.......9........10.......11.......12.......
ZX-1280, ZX-1280n      15,H.3..16,H.4...17,H.5...38,L.3...39,L.4...40,L.5

The duty Cycle parameter specifies the desired duty cycle
of the generated signal, expressing the percentage of time
that the PWM signal will be at thelogic 1 state.

If the
supplied parameter is of type Single, the value is in
percent with a resolution of0.01%.

If the supplied parameter is integral, the units are percent,
i.e., the value 100 means 100%.

Specifying aSingle value that is
negative or any value greater than 100 will have an
undefined effect.

The status parameter, if supplied,
receives a value to indicate success or failure of the call.
If this subroutine is called without a preceding call to
OpenPWM() to prepare the timer, the call will have no effect.

This subroutine may be called multiple times
to effect changes to the PWM signal’s duty cycle while the
signal is being generated.  The change in dutycycle is
synchronized so that it takes effect at the beginning of
the next PWM pulse.

Example
Call   OpenPWM(2, 50.0, zxFastPWM) ' prepare for 50Hz Fast PWM using channel 2
Call   PWM(2, 7.5)                ' generate PWM with 7.5% duty cycle (1.5mS)
Call   Delay(1.0)
Call   PWM(2, 6.25)                ' generate PWM with 6.25% duty cycle (1.25mS)
Compatibility
This subroutine is not available in BasicX compatibility mode.
See Also        ClosePWM, OpenPWM

ClosePWM
Type              Subroutine
Invocation        ClosePWM(channel)
                  ClosePWM(channel, status)
Parameter      Method     Type       Description
channel        ByVal      Byte       The PWM channel to close.
status         ByRef      Boolean    A variable to receive the status code.
Discussion

 The duty Cycle parameter specifies the desired duty cycle
 of the generated signal, expressing the percentage of time
 that the PWM signal will be at the logic 1 state.  If the
 supplied parameter is of type Single, the value is in
 percent with a resolution of0.01%.  If the supplied
 parameter is integral, the units are percent, i.e., the
 value 100 means 100%.  Specifying a Single value that is
 negative or any value greater than 100 will have an
 undefined effect.  The status parameter, if supplied,
 receives a value to indicate success or failure of the call.
 If this subroutine is called without a preceding call
 to OpenPWM() to prepare the timer, the call will have no
 effect.  This subroutine may be called multiple times
 to effect changes to the PWM signal’s duty cycle while the
 signal is being generated.  The change in dutycycle is
 synchronized so that it takes effect at the beginning of
 the next PWM pulse.

Example
Call ClosePWM(1)           ' terminate PWM on channel 1 and 2
Compatibility
This subroutine is not available in BasicX compatibility mode.
See Also          OpenPWM, PWM

ClosePWM8
Type              Subroutine
Invocation        ClosePWM8(channel)
                  ClosePWM8(channel)
Parameter      Method     Type       Description
channel        ByVal      Byte       The 8-bit PWM channel to close.
status         ByRef      Boolean    A variable to receive the status code.
Discussion
 The duty Cycle parameter specifies the desired duty cycle
 of the generated signal, expressing the percentage of time
 that the PWM signal will be at the logic 1 state.  If the
 supplied parameter is of type Single, the value is in
 percent with a resolution of0.01%.  If the supplied
 parameter is integral, the units are percent, i.e., the
 value 100 means 100%.  Specifying a Single value that is
 negative or any value greater than 100 will have an
 undefined effect.  The status parameter, if supplied,
 receives a value to indicate success or failure of the call.
 If this subroutine is called without a preceding call
 to OpenPWM() to prepare the timer, the call will have no
 effect.  This subroutine may be called multiple times
 to effect changes to the PWM signal’s duty cycle while the
 signal is being generated.  The change in dutycycle is
 synchronized so that it takes effect at the beginning of
 the next PWM pulse.

Example
Call ClosePWM8(1)   ' terminate PWM on channel 1 (and channel 2)
Compatibility
This subroutine is not available in BasicX compatibility mode.
See Also          OpenPWM8, PWM8

***********************************************************************
Paul Lamar

-- 
The Rotary Engine NewsLetter. Powered by Linux.
ACRE NL web site. http://www.rotaryeng.net
Youtube key word PaulLamar2
Copyright 1998-2010 All world wide rights reserved.