page 1 d&c ebv seminar june 2003 motor demo c868 chevillot/jansen june 2003 n e v e r s t o p t...

22
Page 1 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/Jansen June 2003 N e v e r s t o p t h i n k i n g . I n f i n e o n C868 Hands On Training CAPCOM6 Basics

Upload: horace-wheeler

Post on 30-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

June 2003

N e v e r s t o p t h i n k i n g .

Infi

neo

nC868 Hands On Training

CAPCOM6 Basics

Page 2

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Contents

Aim:Aim: working BLDC motor control application (Hall Mode)

3 Steps 1st Step: Port Pin control

– byte sent through RS232 output on the Port 3 (LEDs)

2nd Step: CAPCOM6 Modulation test

– byte sent through RS232 MCMOUT register

3rd Step: Hall Sensor mode simulation

– byte sent through RS232 CCPOS (Hall sensors)

You are now 40 clicks away from BLDC Motor Control

Page 3

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 1: Timer, UART and Port pins

The aim of this exercise is to be able to control the Port 3 through the serial link

You will:– Configure the serial link : serial port and timer 2

– Configure the Port pins

C868 Starter Kit

C868

Se

ria

l Po

rt

Po

rt 3Docklight

Page 4

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 1: Timer, UART and Port pins

Create a directory named „HOT“ and inside another named „Step1“

System Configuration:

Launch Dave and create a new project with „C868_r2“ device

Set Oscillator speed to 10MHz with a prescaler of 15/4

Choose „Small“ Memory Model

1122

Page 5

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 1: Timer, UART and Port pins

Peripheral Configuration:

Disable Watchdog Timer and enable FSM_vInit function

Set Port 3 as output and enable IO_vInit function

33

44

55

66

Page 6

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 1: Timer, UART and Port pins

Serial link Configuration:

Configure the UART:

– Use TxD pin

– Enable Receiver

– Enable Interrupt

– Double Baud Rate (for Timer 2)

– Enable UART_vInit function

Configure Timer 2 for Baudrate generation

– Enable Transmit and Receive Clock

– Set Baudrate value to 0xFF86 (9600 Bauds)

– Enable T2_vInit function

7788

99

1010

1111

1212

1313

Page 7

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 1: Timer, UART and Port pins

You can save your project to the “Step 1” directory

– use the name “hot”

Push The “Generate” button inside Dave

– Dave will generate all the files needed for the project

Double click on Dave project “Hot.dpt”

– this will open Keil Vision

Configure Project Options Target:

– Set Small Memory model

– Set Compact Code Rom Size

– Use On-Chip ROM/RAM

1414

1515

1616

1717

Page 8

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 1: Timer, UART and Port pins

Configure Project Options Output :

– Enable Create HEX File

Configure Project Options Utilities :

– Use External Flash Programming Tool

– Browse for Command Line Tool

– Set Arguments to: (change it for your com port)

BR9600 –COM1 “#H”

1818

1919

Page 9

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 1: Timer, UART and Port pins

Add an infinite loop in the Main routine (main.c) :

Add Serial Link state machine (uart.c) :

This is a simple state machine

which waits for two bytes.

First byte is called “Command”

Second byte is associated data

For Step1 we need 1 command:

0x00 Copy data to Port3

void main(void){ // USER CODE BEGIN (MAIN_Main,2) // USER CODE END MAIN_vInit(); // USER CODE BEGIN (MAIN_Main,3)

while (1){}

// USER CODE END} // End of function main

if (RI) { // USER CODE BEGIN (UART_Isr,3)

static ubyte stage = 0;static ubyte command;ubyte value;switch (stage){

case 0:command = SBUF;stage = 1;break;

case 1:value = SBUF;switch (command){

case 0x00: // set P3P3 = value;break;

}stage = 0;break;

default:break;

}

// USER CODE END RI = 0; }NOTE: you can copy paste this into Keil

Page 10

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 1: Timer, UART and Port pins

You can now compile your program F7 or button

Unplug and re-plug the power supply from your board

Push the Load Button

Launch Docklight and add some commands:

– note that you hace to configure Docklight to use the proper com port

You can now play with the LEDs !

HINT : When you have finished with Docklight, push the STOP button !!

Compile

Load

Options

Page 11

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 2: CAPCOM6 Modulation

The aim of this exercise is to be to control the LEDs using the CAPCOM modulation capabilities

You will:– Configure the CAPCOM6:

Timer 13

Multi-Channel Mode

C868 Starter Kit

C868

Ser

ial P

ort

Docklight

CAPCOM6

MCMOUT

Page 12

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 2: CAPCOM6 Modulation

Create a directory named „Step2“

and copy all the files from Step1

Launch Dave by clicking on „Hot.dav“ file

Port Configuration Disable PORT3 as CAPCOM will use it

– you can also remove the IO_vInit function

CAPCOM6 Configuration Use CC6x and COUT6x as outputs

Enable Timer T13

Select fcpu/128 (we want to be able to see the LEDs blinking)

Set T13 Period to maximum (0xFFFF)

2020

2222

23232424

2525

2121

Page 13

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 2: CAPCOM6 Modulation

CAPCOM6 Configuration (cont.) Enable Multi-Channel Mode

For EACH Channel (0,1 and 2) :

– Set Compare Mode 3

– Enable T13 Modulation for CC6x (Low Side)

– Enable PWM generation by T12 or T13 for CC6x and COUT6x

– Set Passive state to ‘1‘ for CC6x and COUT6x (Low Active Bridge)

For Channel 3, Set Duty-Cycle to 50%

Enable CC6_vInit function

Enable CC6_vEnableShadowTransfer function

Enable CC6_vLoadChannelShadowRegister

2626

2828

3030

31313434

35353232

2727

2929

3333

Page 14

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 2: CAPCOM6 Modulation

You can save your project to the “Step 2” directory

Push The “Generate” button inside Dave

Double click on Dave project “Hot.dpt”

this will open Keil Vision

Modify UART function for new command:For Step2 we need 2 commands:

0x00 Modify Duty-Cycle

0x01 Modify MCMOUT register (modulation)

case 1:value = SBUF;switch (command){

case 0x00: // set duty cycleCC6_vLoadChannelShadowRegister(CC6_CHANNEL_3,(unsigned short)value<<8);CC6_vEnableShadowTransfer(CC6_TIMER_13);break;

case 0x01: // set MCMOUTSL : PWM PatternMCMOUTSL = value;MCMOUTSL |= 0x80; // Shadow transfer request to initiate thingsbreak;

}stage = 0;break;

Page 15

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 2: CAPCOM6 Modulation

Compile the program (F7)

Push The “Generate” button inside Dave

Unplug and re-plug the power supply from your board

Push the Load Button

Launch Docklight and add some commands

You can now play with Step2

– Try different combinations for MCMOUT

Page 16

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 3: Hall Sensor Mode (simulated)

This exercise is the same as Step3. We will simulate the Hall Sensors via the serial link. The PWM patterns will change accordingly.

You will:– Configure the CAPCOM6:

Hall Sensor Mode

– Setup a State Machine for the PWM patternsC868 Starter Kit

C868

Ser

ial P

ort

DocklightCAPCOM6

MCMOUT

PISEL(Hall SensorsSimulation)

Page 17

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 3: Hall Sensor Mode (simulated)

Create a directory named „Step3“

and copy all the files from Step2

Launch Dave by clicking on „Hot.dav“ file

CAPCOM6 Configuration

Use CC6x and CCPOSx as inputs

Enable Internal Simulation

Enable Hall Sensor Mode

– answer yes to the question box

Set Transfer on Correct Hall Event

Enable Correct/Wrong Hall Event Interrupt

In Trap/Interrupt Control Interrupt Configuration:

– Enable Node 0

3636

3737

3939

3838

4040

Page 18

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 2: CAPCOM6 Modulation

You can save your project to the “Step 3” directory

Push The “Generate” button inside Dave

Double click on Dave project “Hot.dpt”

this will open Keil Vision

Add State Machine variables

and initialization in CC6.c

// USER CODE BEGIN (CCU6_General,1)unsigned char code HallPatterns[6]={

0x25, // Current=100 Expected=1010x29, // Current=101 Expected=0010x0b, // Current=001 Expected=0110x1a, // Current=011 Expected=0100x16, // Current=010 Expected=1100x34 // Current=110 Expected=100

};unsigned char code PWMPatterns[6]={

0x24, // U=0 V=- W=+ COUT62/CC62=10 COUT61/CC61=01 COUT60/CC60=00 0x06, // U=+ V=- W=0 COUT62/CC62=00 COUT61/CC61=01 COUT60/CC60=10 0x12, // U=+ V=0 W=- COUT62/CC62=01 COUT61/CC61=00 COUT60/CC60=10 0x18, // U=0 V=+ W=- COUT62/CC62=01 COUT61/CC61=10 COUT60/CC60=00 0x09, // U=- V=+ W=0 COUT62/CC62=00 COUT61/CC61=10 COUT60/CC60=01 0x21 // U=- V=0 W=+ COUT62/CC62=10 COUT61/CC61=00 COUT60/CC60=01

};unsigned char CurrentState;// USER CODE END

// USER CODE BEGIN (Init,3)

CurrentState = 0;MCMOUTSL = PWMPatterns[5]; // load the shadow registers with according patternsMCMOUTSH = HallPatterns[5];MCMOUTSL |= 0x80; // Shadow transfer request to initiate thingsMCMOUTSH |= 0x80;MCMOUTSL = PWMPatterns[0]; // load the shadow registers with according patternsMCMOUTSH = HallPatterns[0]; // USER CODE END} // End of function CC6_vInit

Page 19

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 2: CAPCOM6 Modulation

Add the State Machine Handling in the CC6 interrupt handler :

– This State Machine reloads the

MCMOUT shadow register with the next valuevoid CC6_viNodeI0(void) interrupt CCU6_NodeI0_INT{ // USER CODE BEGIN (NodeI0,2) // USER CODE END

IRCON1 &= ~(ubyte)0x04; // clear INP0

if(ISH & 0x20) //if ISH_WHE { //wrong hall event detection // USER CODE BEGIN (NodeI0,18)

SBUF = 0xff; // send an error // USER CODE END ISRH = 0x20; //clear flag ISH_WHE }

if(ISH & 0x10) //if ISH_CHE { //correct hall event detection // USER CODE BEGIN (NodeI0,16)

CurrentState ++;if (CurrentState>=6)

CurrentState = 0;// load the shadow registers with according patternsMCMOUTSL = PWMPatterns[CurrentState]; MCMOUTSH = HallPatterns[CurrentState];SBUF = CurrentState; // send an acknowledge

// USER CODE END

ISRH = 0x10; //clear flag ISH_CHE }} // End of function CC6_viNodeI0

Page 20

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 2: CAPCOM6 Modulation

Modify UART function for new command:

For Step3 we need commands:

0x00 Modify Duty-Cycle

0x01 Modify PISEL register (Hall Sensor Simulation)

case 1:value = SBUF;switch (command){

case 0x00: // set duty cycleCC6_vLoadChannelShadowRegister(CC6_CHANNEL_3,(unsigned short)value<<8);CC6_vEnableShadowTransfer(CC6_TIMER_13);break;

case 0x01: // set P1: CCPOS...P1 = value;break;

}stage = 0;break;

Page 21

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 3: Hall Sensor Mode (simulated)

Compile the program (F7)

Push The “Generate” button inside Dave

Unplug and re-plug the power supply from your board

Push the Load Button

Launch Docklight and add some commands

You can now play with Step3

– Try different combinations for PISEL

Page 22

D&C EBV Seminar June 2003

Motor Demo C868Chevillot/Jansen

Step 3: Hall Sensor Mode (simulated)

All the patterns are extracted from a real motor pattern:

0x80 0xA0 0x20 0x60 0x40 0xC0Pisel value :