Download presentation
Presentation is loading. Please wait.
Published byHorace Wheeler Modified over 9 years ago
1
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. Infineon C868 Hands On Training CAPCOM6 Basics
2
Page 2 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/Jansen Contents Aim: Aim: working BLDC motor control application (Hall Mode) 3 Steps 1 st Step: Port Pin control –byte sent through RS232 output on the Port 3 (LEDs) 2 nd Step: CAPCOM6 Modulation test –byte sent through RS232 MCMOUT register 3 rd Step: Hall Sensor mode simulation –byte sent through RS232 CCPOS (Hall sensors) You are now 40 clicks away from BLDC Motor Control
3
Page 3 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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
4
Page 4 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 1 2
5
Page 5 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 3 4 5 6
6
Page 6 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 7 8 9 10 11 12 13
7
Page 7 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 14 15 16 17
8
Page 8 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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” 18 19
9
Page 9 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 P3 P3 = value; break; } stage = 0; break; default: break; } // USER CODE END RI = 0; } NOTE: you can copy paste this into Keil
10
Page 10 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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
11
Page 11 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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
12
Page 12 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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) 20 22 23 24 25 21
13
Page 13 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 26 28 30 31 34 35 32 27 29 33
14
Page 14 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 cycle CC6_vLoadChannelShadowRegister(CC6_CHANNEL_3,(unsigned short)value<<8); CC6_vEnableShadowTransfer(CC6_TIMER_13); break; case 0x01: // set MCMOUTSL : PWM Pattern MCMOUTSL = value; MCMOUTSL |= 0x80;// Shadow transfer request to initiate things break; } stage = 0; break;
15
Page 15 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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
16
Page 16 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 patterns
17
Page 17 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 36 37 39 38 40
18
Page 18 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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=101 0x29,// Current=101 Expected=001 0x0b,// Current=001 Expected=011 0x1a,// Current=011 Expected=010 0x16,// Current=010 Expected=110 0x34// 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 patterns MCMOUTSH = HallPatterns[5]; MCMOUTSL |= 0x80;// Shadow transfer request to initiate things MCMOUTSH |= 0x80; MCMOUTSL = PWMPatterns[0];// load the shadow registers with according patterns MCMOUTSH = HallPatterns[0]; // USER CODE END } // End of function CC6_vInit
19
Page 19 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 value void 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 patterns MCMOUTSL = PWMPatterns[CurrentState]; MCMOUTSH = HallPatterns[CurrentState]; SBUF = CurrentState; // send an acknowledge // USER CODE END ISRH = 0x10; //clear flag ISH_CHE } } // End of function CC6_viNodeI0
20
Page 20 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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 cycle CC6_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;
21
Page 21 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/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
22
Page 22 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/Jansen Step 3: Hall Sensor Mode (simulated) All the patterns are extracted from a real motor pattern: 0x80 0xA0 0x20 0x60 0x40 0xC0 Pisel value :
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.