• No results found

Script_XC888_091211

N/A
N/A
Protected

Academic year: 2021

Share "Script_XC888_091211"

Copied!
17
0
0

Loading.... (view fulltext now)

Full text

(1)

Microcontroller

XC888 and ATMega128L

(2)

XC 888

Program structure and Port I/0

C-Programming the XC888 requires to include the Register-Headerfile #include <XC888CLM.h>

and to set the port directions by means of the Portdirection Register Pi_DIR = 0xFF; // Port Pi is set to output (Pi = P0 – P7) Pi_DIR = 0x00; // Port Pi is set to input

Interrupts

The portpins for the IRQ-signal of external interrupts can be selected by the register MODPISEL:

Ext. IR Portpin Portpin

EX0 P0.5 if MODPISEL.1=0 P1.4 if MODPISEL.1=1

EX1 P2.0 if MODPISEL.2=0 P5.0 if MODPISEL.2=1

EX2 P2.1 if MODPISEL.3=0 P5.1 if MODPISEL.3=1

EX3 P1.1 n.a.

EX4 P3.7 n.a.

EX5 P1.5 n.a.

EX6 P4.2 n.a.

At the end of the interrupt serviceroutine of external interrupt j, the respective interrupt flag must be cleared by setting the j-th bit in the register IRCON0 to 0. E.g., at the end of the ISR of ext. IR0 the necessary instruction is:

IRCON0&=~(ubyte)0x01 Serial Interface

(3)

#include <XC888CLM.h> #include <stdio.h> #include"UART.h" void main(void) { ... // Variable declarations UART_vInit();

printf (“Text%d%d”, x,y); // Print string and variables x & y (decl. necess.!) ...

}

Student Exercise: Write a program in C that displays 16 characters from a string of any length. By displaying character 0 .. 15 first, then character 1 .. 16, then character 2 .. 17 an so on, the string seems to move from left to right.

Hints: #include <string.h> additionally for string operations

Don’t forget to copy UART.h and UART.c in your working directory Structure: Declare one character array containing the string embedded in 16

blanks before and 16 blanks after:

char *buffer ={" Merry Christmas and a happy new year "};

Declare another character array for storing 16 characters from the string char buffer2[16];

Get the length of buffer and substract 16 laenge_total=strlen (buffer);

laenge=laenge_total-16;

In a while loop, perform operations as follows: - k=i

- Copy 16 characters from buffer to buffer2 using a for-loop, then print buffer2[j]=buffer[j+i]; //j is loop counter and runs from 0 to 15 printf("%s\r",buffer2);

- i=k

- To get the next 16 characters, increment i

(4)

LCD

The LCD is connected with the XC 888 controller as follows: DB P5

RS P4_6 E P4_5 RW P4_4

The libraries and functions used are: #include <XC888CLM.h> #include <stdio.h> #include"LCD.h" void main(void) { ... // Variable declarations lcd_init(); // Init LCD

lcd_clear(); // Clear display

set_cursor(0,1); // Set Cursor to 1st row, 2nd line

lcd_print("TI-Labor "); // Print string

sprintf(text,"%03d",i); // Coversion (declar. int i; char text[3]; necess.!) lcd_print(text); // Print variable

... }

Student Exercise: Write a program in C, which calculates the time passed since program start by means of timer 0 in mode 2 and displays it on the LCD (or serial window in simulation mode) as h:min:sec.

(5)

AD converter (ADC)

AD converters are used for the acquisition of analog signals, e.g. from sensors. The XC888 has 8 AD-channels connected with the Pins of P2. The acquisition range is 0V to 5V, the digitization width can be set between 8 bit and 10 bit. Typically a digitization width of 10 bit is used.

The digitized value Udig can be calculated from an analog signal Uana according to (R= acquisition range, W = digitization width):

Udig = Uana (2**W)/R

Applied to an acquisition range of R = 0 .. 5V and a digitization width of W = 10 bit, we get:

Udig = 204,5 Uana/V

More than 20 registers are available for controlling the ADC [3]. The most important are:

ADC_GLOBCTR: Global control register Port 2 is set to analog input, if Bit 7 is set to 1

ADC_CHCTRi: Channel control registers, one per channel i (i = 0 .. 7)

The lower two bits define, to which of the 4 (j = 0 .. 3) result register RESRj the result of channel i is written

ADC_CRPR1: Conversion request pending register 1 If bit i is set, conversion for channel i starts

ADC_RESRjL: Lower result register j

If Bit 4 (VF-Bit) has been set after conversion, the result is valid

Bit 6 and Bit 7 contain the 2 lower bits (Bit 0 and Bit 1) of the conversion result ADC_RESRjH: Higher result register j

Contains the 8 higher bits (Bit 3 .. Bit 9) of the conversion result

As for programming, functions provide the proper setting of these registers. First the ADCs to be used must be activated by selecting the channel number ChN by means of the function:

ADC_vStartParReqChNum(ChN);

The ChN is the hex-number resulting from the Byte in which the bits of the corresponding ADC Numbers (0 .. 7) have been set. E.g., ADC 3 is activated by

(6)

ADC_vStartParReqChNum(0x08);

and both, ADC 6 and ADC 7 are activated by ADC_vStartParReqChNum(0xC0);

The result of the ADC with the lower number is the return value of ADC_uwGetResultData0();

The result of the ADC with the higher number is the return value of ADC_uwGetResultData1();

Student Exercise: Write a program which digitizes 2 analog signals through ADC 6 and ADC 7 and displays them on the LCD (or serial window in simulation mode).

Pulse-Width Modulation

For the control of servo motors, PWM (pulse width modulation) signals are used:

(7)

The PWM uses a timer 12 and is activated by CC6_vStartTmr_CC6_TIMER_12();

CC6_vEnableShadowTransfer_CC6_TIMER_12();

The PWM generation for a certain pulse-width ratio is started by means of CC6_vLoadChannelShadowRegister_CC6_CHANNEL_0(pwv);

pwv is the value loaded into the capture and compare register CC60SRH+CC60SRL and calculated as follows

pwv = pulseperiode/(2T12CLK * CLK) – pulsewidth/(2T12CLK * CLK)

For the CLK is 41,6 ns and we choose T12CLK as 3, we get pwv = pulseperiode/(8* 41,6 ns) – pulsewidth /(8* 41,6 ns)

Applying this to a pulse-width ratio of 2,75% (pulseperiode of 20 ms and a pulse width of 0,55 ms) in order to set a motor position of -90°, we get: pwv = 60096 – 0,55ms/(23 * 41,6ns)

= 60096 – 1653 = 58443

= 0xE44B

Hence, the motor position of -90° is set by calling the function

(8)

Student Exercise: Write a program which generates a pulse width modulated signal with a pulse width of 0,1 ms and a pulse periode of 20 ms.

In order to read the motor position, a 50 µs impulse must be sent to the servo motor. The signal length of the motor response is correlated with the motors’ position (550µs = -95°, 2450µs = 95°).

(9)

Atmel ATMega 128L

The Atmel ATMega 128L can control up to 24 servo motors via PWM and provides 8 ADC channels. One application example is the control of the humanoid robot Robonova 1 [4]. By means of appropriate sensors and

intelligent algorithms it can operate autonomously and is a good example for as embedded intelligent system. The programming language is C or Robobasic [5].

(10)

Legs and arms of the humanoid Roboter ROBONOVA are driven by 2 x 5 Servomotors and 2 x 3 Servomotoren, respectively:

:

The motors are organized in groups as follows:

Motor Group Motor number

A – Left leg Motor 0 Motor 1 Motor 2 Motor 3 Motor 4 Motor 5

Foot Lower leg Knee Upper leg hip n.c.*

B – Left arm Motor 6 Motor 7 Motor 8 Motor 9 Motor 10 Motor 11

Shoulder Upper arm Lower arm n.c.* n.c.* Head

C – Right arm Motor 12 Motor 13 Motor 14 Motor 15 Motor 16 Motor 17

Shoulder Upper arm Lower arm n.c.* n.c.* n.c.*

(11)

Proximity sensors:

Anschlussbelegung

Far range GP2D12 Range: d = 12 – 80 cm

d = (6787cm / (UDig -3)) – 4 cm if a 10 Bit ADC is used Near range GP2D120 Range: d = 3 – 40 cm

d = (2914 cm / (UDig +5)) -1 cm if a 10 Bit ADC is used

Sensor function (Far range): Mathematical model of a general 1/d function: UAnalog = (a(d+b)) + c) By regression analysis or 3 values from the sensor function a, b, c are calculated:

d = 12 cm -> UAnalog = 2,0863 V d = 20 cm -> UAnalog = 1,3958 V d = 40 cm -> UAnalog = 0,7682 V -> a = 33,14 Vcm b = 4 cm c = 0,015 V UAnalog = (33,14 Vcm/(d+4 cm)) + 0,015 V)

UDig = UAnalog ((2**DigWidth)/5V) and DigWidth = 10 Bit -> UDig = (6787cm/(d+4cm)) + 3)

(12)

Measured output signals

(13)

Program Example 1

(14)

Program Example 2 Proximity Sensors

(15)

Program Example 3

(16)

Program Example 4 Remote Control

(17)

References

[1] Peter Nauth, Sript_MCTegl_131010 [2] XC800 Users’s manual, Infineon [3] XC866/888CLM Data Sheet, Infineon [4] Robonova-I English user manual

[5] Robobasic English Command Instruction Manual

[6] www.infineon.com

References

Related documents

Mdivani’s professional work and leadership have been recognized by the Missouri Bar Association’s President Award, Association for Women Lawyers of Greater Kansas City

Approved Page 2 of 10 © Commonwealth of Australia, 2013 Service Skills Australia SITXEVT302 Process and monitor event registrations.. Modification

For measurement of solar radiation for natural weathering and accelerated natural weathering, instrumental techniques include the continuous measurement of total solar,

At each selected process stage (scalding, plucking, eviscera- tion, washing, and chilling), 90 carcasses from 30 flocks were sampled and examined for Campylobacter,

 Replace deteriorated shingles or shake in-kind  Consider roof replacement if deterioration is.. substantial

To enhance comprehension, the analysis is presented in two different ways: (1) general analysis of the autonomy (regarding children daily routines) and parental style

Philippines: The study was based on information from 2 service providers Smart and Globe with both offering an initial similar entry-level service charge but with a