REMAP Buggy Develpment

My Photo
Name:
Location: United Kingdom

Monday, March 13, 2006

PWM and the 89LPC932 CCU

The 89LPC932 includes a capture compare unit (CCU) which can be configured to produce the PWM outputs needed for motor speed control. The CCU is a complex module but its poor documentation means it is not clear how to set it up for this project. These notes describe the steps necessary to configure the CCU to produce PWM outputs.

Clocks

The CCU is driven by PCLK, the peripheral clock. We first need to determine what frequency PCLK is so we need to look at the 89LPC932 clock circuits. The LPC932 has several user selectable clock sources. The source used is programmed into flash memory. The LPC932 fitted to the mcb900 board is programmed to use the on chip RC clock which runs at approximately 7.373MHz. There are no functions in the RAMAP buggy that require a precise clock frequency so it is planned to use the on chip oscillator.

The clock source is divided by a prescaler DIVM (095H) to produce the CPU clock CCLK. The reset value of DIVM is 00H so CCLK equals the on chip oscillator clock frequency at reset. CCLK is divided by 2 to produce PCLK which is therefore running at a frequency of 3.68665MHz if DIZVM is not modified.

CCU Clock System

The core of the CCU is a 16 bit up/down counter. In PWM mode, the clock to this counter is derived as follows:

  1. PCLK is fed to a 4 bit prescaler (PLLDV3:0 in the CCU control register 1 (TCR21 at 0F9H)). The purpose of the prescaler is to produce an output frequency in the range of 0.5MHz to 1.0MHz. Since our PCLK is ~3.6MHz, we need to divide it by 4 to create an input frequency of ~0.9MHz.
  2. The output of the divider feeds a PLL which produces an output frequency that is 32X its input frequency. In our case the output frequency is ~29MHz.
  3. The PLL output feeds a 10 bit prescaler in the form of a free running counter with programmable reload at overflow. The least significant 8 bit of this are in TPCR2L at 0CAH and the top 2 bits are in TPCR2H at 0CBH. The output of this counter feeds the CCU up/down timer.
Note that in all other CCU modes the 10 bit counter is fed directly by PCLK. To set the mode to PWM and start the timer we need to set the TMOD21 and TMOD20 in the CCU control register 0 (TCR20 bits 1:0). Note, Philips recommends the following procedure for setting up PWM:

  • Set up the PWM module without starting the timer
  • Calculate the right value for the PLL prescaler and write it to PLLDV
  • Set PLLEN. Wait until this bit read 1
  • Start the timer by writing to TMOD21 and TMOD20 bits

Analogue to Digital conversion

I have now found a series of excellent application notes on the design of single and dual slope analogue to digital conversion using comparators.. It appears that these will be perfectly adequate for the joystick inputs in this applicatiion. This mean the 89LPC921 microcontroller already fitted to the mcb900 board does not need to be changed.

Wednesday, March 01, 2006

REMAP Buggy Development


This blog is a placeholder for various notes, circuits and code for the kid's powered buggy I am developing for REMAP.

REMAP is a UK charity that develops technical aids for the disabled. Specifically, it creates technical solutions to everyday problems where no off the shelf solution exists. This particular project is intended to help very young disabled children to learn how to control a powered wheelchair. They cannot use a full size one because they are too small to fit safely into it. Small ones they would fit safely in are not available.

I have already obtained a pair of half sized motors (scrapped from a medium sized chair). They are DC permamnent magnet types and normaly operate from 24V batteries. To reduce the maximum available speed, the kid's buggy will be operated from a single 12V battery.

In regular electric wheelchairs a joystick is used to set direction and speed and PWM is used to set motor speed and direction. The kid's buggy will use a standard joystick and a new 12V PWM design all controlled by an 8052 variant. The current plan is to base this on a Keil MCB900 evaluation board (see picture) which uses a Philips P89LPC932 microcontroller (an 8052 variant). This device has PWM output capability but no A/D (for the joystick inputs). It has a couple of comparators that could be used to make an A/D at a push but this is unnecessarily complex and may be unreliable. So it has been decided to replace the 89PLPC832 with a P89LPC935 which does have A/D inputs.

The reasons for choosing this board is that it has a convenient breadboarding area and I just happen to already have one. In addition, the code size will be small enough to use the free tools provided by Keil for it.