#include "p30f3011.h" #include "svm3011 v1.2.h"
|
|
- Helena McCormick
- 6 years ago
- Views:
Transcription
1 // // File: sinusoidal BLDC v1.2.c // // Written By: Jorge Zambada, Microchip Technology // // The following files should be included in the MPLAB project: // // sinusoidalbldc v1.2.c -- Main source code file // SVM.c -- Space Vector Modulation file // SVM.h // p30f3011.gld -- Linker script file // // // Revision History // // July/5/ first version // November/18/ Review // Jun/2012 manual controll of volt and Phase(ccw-0-cw),-> svm(volt,angle) // August/ F3011 and 3 MODE's of test operation // // // Phase_Zero set by PotZ at AN1 P3, Press SWITCH_S2 to set it again. // //Switch // Mode 0: PotAI at AN3 P4 = Refspeed open loop. // // Mode 1: PotAI at AN3 P4 = Phase (0-360 ), PotV at AN3 P2 = Power // 'Brake' at "Hals" to see Hall positions at trace t view. // // Mode 2: PotAI at AN1 P2 = Refspeed closed loop, PotV at AN3 P2 = PhaseADD. // // #include "p30f3011.h" #include "svm3011 v1.2.h" // Device Configuration _FOSC(CSW_FSCM_OFF & XT_PLL8); //_FWDT(WDT_OFF); //_FBORPOR(PBOR_ON & BORV_20 & PWRT_64 & MCLR_EN); // typedef signed int SFRAC16;
2 #define CLOSED_LOOP // if defined the speed controller will be enabled #define FCY // xtal = 5Mhz; PLLx16 -> 20 MIPS #define FPWM // 20 khz, so that no audible noise is present. #define _10MILLISEC 1000 // Used as a timeout with no hall effect sensors // transitions and Forcing steps according to the // actual position of the motor #define _100MILLISEC // after this time has elapsed, the motor is // consider stalled and it's stopped // In the sinewave generation algorithm we need an offset to be added to the // pointer when energizing the motor in CCW. This is done to compensate an // asymetry of the sinewave int PhaseOffset = 10500; // These Phase values represent the base Phase value of the sinewave for each // one of the sectors (each sector is a translation of the hall effect sensors // reading //#define PHASE_ZERO //0xDFF2 //#define PHASE_ZERO //0xD548 //#define PHASE_ZERO //0xB552 //#define PHASE_ONE ((PHASE_ZERO /6 + 1) % 65536) //#define PHASE_TWO ((PHASE_ONE /6 + 1) % 65536) //#define PHASE_THREE ((PHASE_TWO /6) % 65536) //#define PHASE_FOUR ((PHASE_THREE /6 + 1) % 65536) //#define PHASE_FIVE ((PHASE_FOUR /6 + 1) % 65536) #define THREE_PHASE (65536/2) // Constants used for properly energizing the motor depending on the // rotor's position //const int PhaseValues[6] = //PHASE_ZERO, PHASE_ONE, PHASE_TWO, PHASE_THREE, PHASE_FOUR, PHASE_FIVE; unsigned int PHASE_ZERO; unsigned int PHASE_ONE; unsigned int PHASE_TWO; unsigned int PHASE_THREE; unsigned int PHASE_FOUR; unsigned int PHASE_FIVE; unsigned int PhaseValues[6];
3 #define HALLA 1 // Connected to RB4 IC7 P6 #define HALLB 2 // Connected to RD1 IC2 P18 #define HALLC 4 // Connected to RB5 IC8 P7 #define CW 0 // Counter Clock Wise direction #define CCW 1 // Clock Wise direction #define SWITCH_S2 (!PORTCbits.RC14) // P16 Push button S2 #define SW_M PORTD // mode switch #define SW_M_IO TRISDbits.TRISD0 // P23 Test mode sw position (out/in) #define off = 0 #define on = 1 char n=0; unsigned int t[50]; void trace(unsigned int); unsigned int pd; unsigned int pi; int PositionCounter = 0; // This is the maximum value that may be passed to the SVM // function without overmodulation. This limit is equivalent // to 0.866, which is sqrt(3)/2. #define VOLTS_LIMIT // minimum to hold motor in position ad zero speed #define VOLTS_minimum 4500 // Period Calculation // Period = (TMRClock * 60) / (RPM * Motor_Poles) // For example> // Motor_Poles = 10 // RPM = 6000 (Max Speed) // Period = ((20,000,000 / 64) * 60) / (6000 * 10) = // RPM = 60 (Min Speed) // Period = ((20,000,000 / 64) * 60) / (60 * 10) = #define MINPERIOD 313 // For 6000 max rpm and 10 poles motor //#define MAXPERIOD // For 60 min rpm and 10 poles motor //#define MAXPERIOD // For 60 min rpm and 10 poles motor #define MAXPERIOD // Use this MACRO when using floats to initialize signed 16-bit fractional // variables #define SFloat_To_SFrac16(Float_Value) \ ((Float_Value < 0.0)? (SFRAC16)(32768 * (Float_Value) - 0.5) \ : (SFRAC16)(32767 * (Float_Value) + 0.5)) void ICD(void); void InitADC(void); // Initialization of ADC used for Speed & power
4 Command void InitMCPWM(void); // Initialization for PWM at 20kHz, Center aligned, // Complementary mode with 500 ns of deadtime void InitTMR1(void); // Initialization for TIMER1 used for speed control // and motor stalled protection void InitTMR3(void); // Initialization for TIMER3 used as a timebase // for the two input capture channels void InitUserInt(void); // This function initializes all ports // (inputs and outputs) for the application void InitICandCN(void); // Initializes input captures and change notification, // used for the hall sensor inputs void RunMotor(void); // This function initializes all variables // and interrupts used for starting and running // the motor void StopMotor(void); // This function clears all flags, and stops anything // related to motor control, and also disables PWMs void SpeedControl(void); // This function contains all ASM and C operations // for doing the PID Control loop for the speed void Halls(void); // Commen Hall funtion void ForceCommutation(void); // When motor is to slow to generate interrupts // on halls, this function forces a commutation void ChargeBootstraps(void); // At the begining of the motor operation, the // bootstrap caps are charged with this function // Flags used for the application struct unsigned MotorRunning :1; // This bit is 1 if motor running unsigned unused :15; Flags; unsigned int Phase; // This variable is incremented by the PWM interrupt // in order to generate a proper sinewave. Its value // is incremented by a value of PhaseInc, which // represents the frequency of the generated sinewave unsigned int PastPhase; signed int PhaseInc; // Delta increments of the Phase variable, calculated // in the TIMER1 interrupt (each 1 ms) and used in // the PWM interrupt (each 50 us) unsigned int HallValue; // This variable holds the hall sensor input readings unsigned int Sector; // This variables holds present sector value, which is // the rotor position unsigned int LastSector; // This variable holds the last sector value. This // is critical to filter slow slew rate on the Hall // effect sensors hardware
5 unsigned int MotorSlowCounter = 0; // This variable gets incremented each // 1 ms, and is cleared everytime a new // sector is detected. Used for // ForceCommutation and MotorStalled // protection functions // This array translates the hall state value read from the digital I/O to the // proper sector. Hall values of 0 or 7 represent illegal values and therefore // return -1. char SectorTable[] = -1,4,2,3,0,5,1,-1; char Mode = 0; char ICI = 0; char ICN = 0; unsigned int PhaseD = 0; unsigned int PhaseDC = 0; unsigned int Hoek; unsigned int HoekDecm; unsigned char Current_Direction; // Current mechanical motor direction of // rotation Calculated in halls interrupts unsigned char Required_Direction; // Required mechanical motor direction of // rotation, will have the same sign as the // ControlOutput variable from the Speed // Controller // Variables containing the Period of half an electrical cycle, which is an // interrupt each edge of one of the hall sensor input unsigned int PastCapture, ActualCapture, Period; // Used as a temporal variable to perform a fractional divide operation in // assembly SFRAC16 _MINPERIOD = MINPERIOD - 1; SFRAC16 PotAI,PhaseAdd; int PotV; unsigned int PotZ; SFRAC16 MotorI; currenr I on AN1 // Motor SFRAC16 MeasuredSpeed, RefSpeed; // Actual and Desired speeds for the PID // controller, that will generate the error SFRAC16 ControlOutput = 0; // Controller output, used as a voltage output, // use its sign for the required direction // Absolute PID gains used by the controller. Position form implementation of
6 // a digital PID. See SpeedControl subroutine for details SFRAC16 Kp = SFloat_To_SFrac16(0.2); // P Gain SFRAC16 Ki = SFloat_To_SFrac16(0.02); // I Gain SFRAC16 Kd = SFloat_To_SFrac16(0.000); // D Gain // Constants used by the PID controller, since a MAC operation is used, the // PID structure is changed (See SpeedControl() Comments) SFRAC16 ControlDifference[3] \ attribute (( space (xmemory), aligned (4))); SFRAC16 PIDCoefficients[3] \ attribute (( space (ymemory), aligned (4))); Function: void attribute (( interrupt )) _T1Interrupt (void) PreCondition: The motor is running and is generating hall effect sensors interrupts. Also, the actual direction of the motor used in this interrupt is assumed to be previously calculated. In this ISR the Period, Phase Increment and MeasuredSpeed are calculated based on the input capture of one of the halls. The speed controller is also called in this ISR to generate a new output voltage (ControlOutput). The Phase Advance is calculated based on the maximum allowed phase advance (MAX_PH_ADV) and the actual speed of the motor. The last thing done in this ISR is the forced commutation, which happens each time the motor doesn't generate a new hall interrupt after a programmed period of time. If the timeout for generating hall ISR is too much (i.e. 100 ms) the motor is then stopped. Note: The MeasuredSpeed Calculation is made in assembly to take advantage of the signed fractional division. void attribute ((interrupt, no_auto_psv)) _T1Interrupt (void) IFS0bits.T1IF = 0; //PORTD = 0x08; // debug p19 Period = ActualCapture - PastCapture; // This is an UNsigned substraction
7 // to get the Period between one // hall effect sensor transition // These operations limit the Period value to a range from 60 to 6000 rpm if (Period < (unsigned int)minperiod) // MINPERIOD or 6000 rpm Period = MINPERIOD; else if (Period > (unsigned int)maxperiod) // MAXPERIOD or 60 rpm Period = MAXPERIOD; // PhaseInc is a value added to the Phase variable to generate the sine // voltages. 1 electrical degree corresponds to a PhaseInc value of 184, // since the pointer to the sine table is a 16bit value, where 360 Elec // Degrees represents in the pointer. // builtin_divud(long Value, Int Value) is a function of the compiler // to do Long over Integer divisions. PhaseInc = builtin_divud(170667ul, Period); // Phase increment is used // pi = builtin_divud(512000ul, Period); // by the PWM isr (SVM) // This subroutine in assembly calculates the MeasuredSpeed using // fractional division. These operations in assembly perform the following // formula: // MINPERIOD (in fractional) // MeasuredSpeed = // Period (in fractional) // asm volatile("repeat #17\n\t" "divf %1,%2\n\t" "mov w0,%0" : /* output */ "=g"(measuredspeed) : /* input */ "r"(_minperiod), "e"(period) : /* clobber */ "w0"); // MeasuredSpeed sign adjustment based on current motor direction of // rotation if (Current_Direction == CCW) MeasuredSpeed = -MeasuredSpeed; // The following values represent the MeasuredSpeed values from the // previous operations: // // CONDITION RPM SFRAC16 SINT HEX // Max Speed CW -> 6000 RPM -> > > 0x7F97
8 // Min Speed CW -> 60 RPM -> > 327 -> 0x0147 // Min Speed CCW -> -60 RPM -> > > 0xFEB9 // Max Speed CCW -> RPM -> > > 0x8069 SpeedControl(); // Speed PID controller is called here. It will use // MeasuredSpeed, RefSpeed, some buffers and will generate // the new ControlOutput, which represents a new amplitude // of the sinewave that will be generated by the SVM // subroutine. MotorSlowCounter++; // We increment a timeout variable to see if the // motor is too slow (not generating hall effect // sensors interrupts frequently enough) or if // the motor is stalled. This variable is cleared // in halls ISRs if ((MotorSlowCounter % _10MILLISEC) == 0) ForceCommutation(); // Force Commutation if no hall sensor changes // have occured in specified timeout. else if (MotorSlowCounter >= _100MILLISEC) // StopMotor(); // Stop motor is no hall changes have occured in // specified timeout //PORTD &= 0x07; //debug p19 Function: void attribute (( interrupt )) _IC2Interrupt (void) PreCondition: The inputs of the hall effect sensors should have low pass filters. A simple RC network works. This interrupt represent Hall A ISR. Hall A -> RB3 -> CN5. This is generated by the input change notification CN5. The purpose of this ISR is to Calculate the actual
9 mechanical direction of rotation of the motor, and to adjust the Phase variable depending on the sector the rotor is in. Note 1: The sector is validated in order to avoid any spurious interrupt due to a slow slew rate on the halls inputs due to hardware filtering. Note 2: For Phase adjustment in CCW, an offset is added to compensate non-symetries in the sine table used. void attribute ((interrupt, no_auto_psv)) _IC2Interrupt (void) IFS0bits.IC2IF = 0; // Clear interrupt flag // Read halls HallValue = (unsigned int)(((portb >> 3) & 0x0006) ((PORTD >> 1) & 0x0001)); Sector = SectorTable[HallValue]; // Get Sector from table // This MUST be done for getting around the HW slow rate if (Sector!= LastSector) // Calculate Hall period corresponding to half an electrical cycle PastCapture = ActualCapture; ActualCapture = IC2BUF; IC2BUF; IC2BUF; IC2BUF; ICN = 2; // Motor current direction is computed based on Sector if ((Sector == 5) (Sector == 2)) Current_Direction = CCW; else Current_Direction = CW; Halls(); Function: void attribute (( interrupt )) _IC7Interrupt (void) PreCondition: The inputs of the hall effect sensors should have low pass filters. A simple RC network works.
10 This interrupt represent Hall B ISR. Hall B -> RB4 -> IC7. This is generated by the input Capture Channel IC7. The purpose of this ISR is to Calculate the actual Period between hall effect sensor transitions, calculate the actual mechanical direction of rotation of the motor, and also to adjust the Phase variable depending on the sector the rotor is in. Note 1: The sector is validated in order to avoid any spurious interrupt due to a slow slew rate on the halls inputs due to hardware filtering. Note 2: For Phase adjustment in CCW, an offset is added to compensate non-symetries in the sine table used. void attribute ((interrupt, no_auto_psv)) _IC7Interrupt (void) IFS1bits.IC7IF = 0; // Cleat interrupt flag // Read halls HallValue = (unsigned int)(((portb >> 3) & 0x0006) ((PORTD >> 1) & 0x0001)); Sector = SectorTable[HallValue]; // Get Sector from table // This MUST be done for getting around the HW slow rate if (Sector!= LastSector) // Calculate Hall period corresponding to half an electrical cycle PastCapture = ActualCapture; ActualCapture = IC7BUF; IC7BUF; IC7BUF; IC7BUF; // Motor current direction is computed based on Sector if ((Sector == 3) (Sector == 0)) Current_Direction = CCW; else Current_Direction = CW;
11 ICN = 7; Halls(); Function: void attribute (( interrupt )) _IC8Interrupt (void) PreCondition: The inputs of the hall effect sensors should have low pass filters. A simple RC network works. This interrupt represent Hall C ISR. Hall C -> RB5 -> IC8. This is generated by the input Capture Channel IC8. The purpose of this ISR is to Calculate the actual mechanical direction of rotation of the motor, and to adjust the Phase variable depending on the sector the rotor is in. Note 1: The sector is validated in order to avoid any spurious interrupt due to a slow slew rate on the halls inputs due to hardware filtering. Note 2: For Phase adjustment in CCW, an offset is added to compensate non-symetries in the sine table used. void attribute ((interrupt, no_auto_psv)) _IC8Interrupt (void) IFS1bits.IC8IF = 0; // Cleat interrupt flag // Read halls HallValue = (unsigned int)(((portb >> 3) & 0x0006) ((PORTD >> 1) & 0x0001)); Sector = SectorTable[HallValue]; // Get Sector from table // This MUST be done for getting around the HW slow rate if (Sector!= LastSector) // Calculate Hall period corresponding to half an electrical cycle PastCapture = ActualCapture; ActualCapture = IC8BUF;
12 ICN = 8; IC8BUF; IC8BUF; IC8BUF; // Motor current direction is computed based on Sector if ((Sector == 1) (Sector == 4)) Current_Direction = CCW; else Current_Direction = CW; Halls(); Function: void attribute (( interrupt )) _PWMInterrupt (void) PreCondition: in this ISR the sinewave is generated. If the current motor direction of rotation is different from the required direction then the motor is operated in braking mode and step commutation is performed. Once both directions are equal then the sinewave is fed into the motor windings. Note: void attribute ((interrupt, no_auto_psv)) _PWMInterrupt (void) IFS2bits.PWMIF = 0; // Clear interrupt flag //PORTD = 0x04; //debug p22 if (Required_Direction == CW) if (Current_Direction == CW) Phase += PhaseInc; // Increment Phase if CW to generate the // sinewave only if both directions are equal
13 applied generate else // If Required_Direction is CW (forward) POSITIVE voltage is SVM(ControlOutput, Phase); if (Current_Direction == CCW) Phase -= PhaseInc; // Decrement Phase if CCW to // the sinewave only if both // directions are equal // If Required_Direction is CCW (reverse) NEGATIVE voltage is applied SVM(-(ControlOutput+1), Phase); //PORTD &= 0x0B; //debug p22 Function: void attribute (( interrupt )) _ADCInterrupt (void) PreCondition: The ADC interrupt loads the reference speed (RefSpeed) with the respective value of the POT. The value will be a signed fractional value, so it doesn't need any scaling. Note: void attribute ((interrupt, no_auto_psv)) _ADCInterrupt (void) IFS0bits.ADIF = 0; // Clear interrupt flag //PORTD = 0x02; //debug p18 PotAI = ADCBUF3; PotZ = ADCBUF2;
14 PotV = ADCBUF1; if (Mode < 1) //MODE 0 // Phase = Incremented by PotAI. // // RefSpeed = PotV. RefSpeed = PotAI; PhaseAdd = PotV / 16; else if (Mode < 2) // MODE 1 // Phase = potai. // // RefSpeed = PotV. Phase = PotAI; RefSpeed = PotV / 2; RefSpeed += 0x4000; PhaseAdd = 0; else // MODE 2 // Phase = Incremented by PotAI, // // RefSpeed = related to Angle Increment. RefSpeed = PotAI; PhaseAdd = PotV / 16; // PhaseAdd = 0; //PORTD &= 0x0D; //debug p18 Function: int main(void) PreCondition: main function of the application. Peripherals are initialized, and then, depending on the motor status
15 (running or stopped) and if the push button is pressed, the motor is started or stopped. All other operations and state machines are performed with interrupts. Note: int main(void) int D2; int xx; for(;;) InitUserInt(); // Initialize User Interface I/Os Mode = 0; InitADC(); // Initialize ADC to be signed fractional // set Sector Zero InitTMR1(); // Initialize TMR1 for 1 ms periodic ISR InitTMR3(); // Initialize TMR3 for timebase of capture InitICandCN(); // Initialize Hall sensor inputs ISRs InitMCPWM(); // Initialize 20 khz, center aligned, 500 ns of // deadtime RunMotor(); while (!SWITCH_S2) // 3 positions: off=0v, open, on=5v if (SW_M & 0x01) // Test Mode switch // = on SW_M_IO = 0; // set to output SW_M &= 0x0E; // force off SW_M_IO =1; // set to input xx = D2; // wait to setle xx = D2; // wait to setle xx = D2; // wait to setle xx = D2; // wait to setle if (SW_M & 0x01) // Read again // Still on = realy on Incremented by PotI, // RefSpeed = related to Angle Increment. if (Mode!= 2) Mode = 2; // Phase =
16 to off, thus = open Incremented by PotI. else // Changed if (Mode!= 0) Mode = 0; // Phase = // Refspeed = PotV. to on, thus = open Incremented by PotI. else // = off SW_M_IO =0; // set to output SW_M = 0x01; // force on SW_M_IO =1; // set to input xx = D2; // wait to setle xx = D2; // wait to setle xx = D2; // wait to setle xx = D2; // wait to setle if (SW_M & 0x01) // Read again // Changed if (Mode!= 0) Mode = 0; // Phase = // Refspeed = PotV. realy off return 0; StopMotor(); else // Still off = if (Mode!= 1) Mode = 1;
17 Function: void ChargeBootstraps(void) PreCondition: In the topology used, it is necessary to charge the bootstrap caps each time the motor is energized for the first time after an undetermined amount of time. ChargeBootstraps subroutine turns ON the lower transistors for 10 ms to ensure voltage on these caps, and then it transfers the control of the outputs to the PWM module. Note: void ChargeBootstraps(void) unsigned int i; OVDCON = 0x0015; // Turn ON low side transistors to charge for (i = 0; i < 33330; i++) // 10 ms Delay at 20 MIPs ; PWMCON2bits.UDIS = 1; PDC1 = PTPER; // Initialize as 0 voltage PDC2 = PTPER; // Initialize as 0 voltage PDC3 = PTPER; // Initialize as 0 voltage OVDCON = 0x3F00; // Configure PWM0-5 to be governed by PWM module PWMCON2bits.UDIS = 0; Function: PreCondition: void RunMotor(void)
18 Call this subroutine when first trying to run the motor and the motor is previously stopped. RunMotor will charge bootstrap caps, will initialize application variables, and will enable all ISRs. Note: void RunMotor(void) ChargeBootstraps(); // init variables ControlDifference[0] = 0; // Error at K (most recent) ControlDifference[1] = 0; // Error at K-1 ControlDifference[2] = 0; // Error at K-2 (least recent) PIDCoefficients[0] = Kp + Ki + Kd; // Modified coefficient for using MACs PIDCoefficients[1] = -(Kp + 2*Kd); // Modified coefficient for using MACs PIDCoefficients[2] = Kd; // Modified coefficient for using MACs TMR1 = 0; // Reset timer 1 for speed control TMR3 = 0; // Reset timer 3 for speed measurement ActualCapture = MAXPERIOD; // Initialize captures for minimum speed //(60 RPMs) PastCapture = 0; 0x0001)); // Initialize direction with required direction // Remember that ADC is not stopped. // Read halls HallValue = (unsigned int)(((portb >> 3) & 0x0006) ((PORTD >> 1) & LastSector = Sector = SectorTable[HallValue]; // variable // Initialize Sector // RefSpeed's sign will determine if the motor should be run at CW // (+RefSpeed) or CCW (-RefSpeed) ONLY at start up, since when the motor // has started, the required direction will be set by the control output // variable to be able to operate in the four quadrants if (RefSpeed < 0) ControlOutput = 0; // Initial output voltage
19 else Current_Direction = Required_Direction = CCW; Phase = PhaseValues[(Sector + 3) % 6] + PhaseOffset; ControlOutput = 0; // Initial output voltage Current_Direction = Required_Direction = CW; Phase = PhaseValues[Sector]; MotorSlowCounter = 0; // Reset motor stalled protection counter // Set initial Phase increment with minimum value. This will change if a // costing operation is required by the application PhaseInc = builtin_divud(512000ul, MAXPERIOD); // Clear all interrupts flags IFS0bits.T1IF = 0; // Clear timer 1 flag IFS0bits.IC2IF = 0; // Clear interrupt flag IFS1bits.IC7IF = 0; // Clear interrupt flag IFS1bits.IC8IF = 0; // Clear interrupt flag IFS2bits.PWMIF = 0; // Clear interrupt flag // enable all interrupts asm volatile ("DISI #0x3FFF"); IEC0bits.T1IE = 1; // Enable interrupts for timer 1 IEC0bits.IC2IE = 1; // Enable interrupts on IC2 IEC1bits.IC7IE = 1; // Enable interrupts on IC7 IEC1bits.IC8IE = 1; // Enable interrupts on IC8 IEC2bits.PWMIE = 1; // Enable PWM interrupts DISICNT = 0; Flags.MotorRunning = 1; if (Mode!= 1) //debug trace(sector 0xCF00); trace (Phase); Hoek = Phase / 182; HoekDecm = Hoek / 100 << 8; Hoek = Hoek % 100; HoekDecm = Hoek / 10 << 4; HoekDecm = Hoek % 10; trace (HoekDecm); n=n; // Indicate that the motor is running
20 Function: PreCondition: void StopMotor(void) Call this subroutine whenever the user want to stop the motor. This subroutine will clear interrupts properly, and will also turn OFF all PWM channels. Note: void StopMotor(void) OVDCON = 0x0000; // turn OFF every transistor // disable all interrupts asm volatile ("DISI #0x3FFF"); IEC0bits.T1IE = 0; // Disable interrupts for timer 1 IEC0bits.IC2IE = 0; // Disable interrupts on IC2 IEC1bits.IC7IE = 0; // Disable interrupts on IC7 IEC1bits.IC8IE = 0; // Disable interrupts on IC8 IEC2bits.PWMIE = 0; // Disable PWM interrupts DISICNT = 0; Flags.MotorRunning = 0; // Indicate that the motor has been stopped Function: void SpeedControl(void) PreCondition: This subroutine implements a PID in assembly using the MAC instruction of the dspic.
21 Note: /* ---- Proportional Output Kp Reference --- Speed Integral + Control Error Ki Output Output Plant Z^(-1) Measured Deriv Speed Output - Kd * (1 - Z^(-1)) ControlOutput(K) = ControlOutput(K-1) + ControlDifference(K) * (Kp + Ki + Kd) + ControlDifference(K-1) * (-Ki - 2*Kd) + ControlDifference(K-2) * Kd Using PIDCoefficients: PIDCoefficients[0] = Kp + Ki + Kd PIDCoefficients[1] = -(Kp + 2*Kd) PIDCoefficients[2] = Kd and leting: ControlOutput -> ControlOutput(K) and ControlOutput(K-1) ControlDifference[0] -> ControlDifference(K) ControlDifference[1] -> ControlDifference(K-1) ControlDifference[2] -> ControlDifference(K-2) ControlOutput = ControlOutput + ControlDifference[0] * PIDCoefficients[0] + ControlDifference[1] * PIDCoefficients[1] + ControlDifference[2] * PIDCoefficients[2]
22 This was implemented using Assembly with signed fractional and saturation enabled with MAC instruction */ void SpeedControl(void) SFRAC16 *ControlDifferencePtr = ControlDifference; SFRAC16 *PIDCoefficientsPtr = PIDCoefficients; SFRAC16 x_prefetch; SFRAC16 y_prefetch; register int reg_a asm("a"); register int reg_b asm("b"); CORCONbits.SATA = 1; // Enable Saturation on Acc A #if C30_VERSION == 320 #error "This Demo is not supported with v3.20" #endif #if C30_VERSION < 320 reg_a = builtin_lac(refspeed,0); reg_b = builtin_lac(measuredspeed,0); reg_a = builtin_subab(); *ControlDifferencePtr = builtin_sac(reg_a,0); reg_a = builtin_movsac(&controldifferenceptr, &x_prefetch, 2, &PIDCoefficientsPtr, &y_prefetch, 2, 0); reg_a = builtin_lac(controloutput, 0); reg_a = builtin_mac(x_prefetch,y_prefetch, &ControlDifferencePtr, &x_prefetch, 2, &PIDCoefficientsPtr, &y_prefetch, 2, 0); reg_a = builtin_mac(x_prefetch,y_prefetch, &ControlDifferencePtr, &x_prefetch, 2, &PIDCoefficientsPtr, &y_prefetch, 2, 0); reg_a = builtin_mac(x_prefetch,y_prefetch, &ControlDifferencePtr, &x_prefetch, 2, &PIDCoefficientsPtr, &y_prefetch, 2, 0); ControlOutput = builtin_sac(reg_a, 0); #else reg_a = builtin_lac(refspeed,0); reg_b = builtin_lac(measuredspeed,0); reg_a = builtin_subab(reg_a,reg_b); *ControlDifferencePtr = builtin_sac(reg_a,0);
23 reg_b); reg_a = builtin_movsac(&controldifferenceptr, &x_prefetch, 2, &PIDCoefficientsPtr, &y_prefetch, 2, 0, reg_a = builtin_lac(controloutput, 0); reg_a = builtin_mac(reg_a,x_prefetch,y_prefetch, &ControlDifferencePtr, &x_prefetch, 2, &PIDCoefficientsPtr, &y_prefetch, 2, 0, reg_b); reg_a = builtin_mac(reg_a,x_prefetch,y_prefetch, &ControlDifferencePtr, &x_prefetch, 2, &PIDCoefficientsPtr, &y_prefetch, 2, 0, reg_b); reg_a = builtin_mac(reg_a,x_prefetch,y_prefetch, &ControlDifferencePtr, &x_prefetch, 2, &PIDCoefficientsPtr, &y_prefetch, 2, 0, reg_b); ControlOutput = builtin_sac(reg_a, 0); #endif CORCONbits.SATA = 0; // Disable Saturation on Acc A // Store last 2 errors ControlDifference[2] = ControlDifference[1]; ControlDifference[1] = ControlDifference[0]; // If CLOSED_LOOP is undefined (running open loop) overide ControlOutput // with value read from the external potentiometer if (Mode!= 2) ControlOutput = RefSpeed; // ControlOutput will determine the motor required direction if (ControlOutput < 0) Required_Direction = CCW; else Required_Direction = CW; //trace(phase); Function void Halls(voip) Overview Commen Hall funtion * void Halls(void) // Since a new sector is detected, clear variable that counts // the slow time
24 //trace (MotorSlowCounter); MotorSlowCounter = 0; if (Mode!= 2) //debug trace(sector 0xCc00); //debug trace(phase); PastPhase = Phase; Hoek = Phase / 182; HoekDecm = Hoek / 100 << 8; Hoek = Hoek % 100; HoekDecm = Hoek / 10 << 4; HoekDecm = Hoek % 10; trace (HoekDecm); if (Mode == 1) Required_Direction = Current_Direction; // Motor commutation is actually based on the required direction, not // the current dir. This allows driving the motor in four quadrants if (Mode!= 1) if (Required_Direction == CW) PositionCounter += 1; Phase = PhaseValues[Sector]; Phase += PhaseAdd; else PositionCounter -= 1; // For CCW an offset must be added to compensate difference in // symmetry of the sine table used for CW and CCW Phase = PhaseValues[(Sector + 3) % 6] + PhaseOffset; Phase -= PhaseAdd; if (Mode!= 2) //debug trace(phase); Hoek = Phase / 182; HoekDecm = Hoek / 100 << 8; Hoek = Hoek % 100; HoekDecm = Hoek / 10 << 4; HoekDecm = Hoek % 10; trace (HoekDecm); if (Current_Direction == 0) Hoek = (Phase - PastPhase + PhaseInc) / 182;
25 else Hoek = (PastPhase - Phase - PhaseInc) / 182; HoekDecm = Hoek / 100 << 8; Hoek = Hoek % 100; HoekDecm = Hoek / 10 << 4; HoekDecm = Hoek % 10; trace (HoekDecm); //debug ICD(); //debug LastSector = Sector; // Update last sector Function: void ForceCommutation(void) PreCondition: This function is called each time the motor doesn't generate hall change interrupt, which means that the motor running too slow or is stalled. If it is stalled, the motor is stopped, but if it is only slow, this function is called and forces a commutation based on the actual hall sensor position and the required direction of rotation. Note: void ForceCommutation(void) // Read halls HallValue = (unsigned int)(((portb >> 3) & 0x0006) ((PORTD >> 1) & 0x0001)); Sector = SectorTable[HallValue]; // Read sector based on halls if (Sector!= -1) // If the sector is invalid don't do anything table // Depending on the required direction, a new phase is fetched if (Required_Direction == CW) // Motor is required to run forward, so read directly the
26 Phase = PhaseValues[Sector]; else // Motor is required to run reverse, so calculate new phase and // add offset to compensate asymmetries Phase = PhaseValues[(Sector + 3) % 6] + PhaseOffset; Function: void InitADC(void) PreCondition: Below is the code required to setup the ADC registers for: void InitADC(void) unsigned int i; ADPCFG = 0x0030; ADCON1 = 0x036E; conversion // Open loop // RB4, RB5 are digital // PWM starts // Signed fractional conversions ADCON2 = 0x0200; // DD,SS, scan 0,1,2,3, int after 4conv ADCON3 = 0x000E; // Sample time 1Tad, conv clock 3Tcy ADCHS = 0x0006; // CH0 = AN6 = // CH1 = AN0 = PotV // CH2 = AN1 = PotZ
27 // CH3 = AN2 = PotAI ADCON1bits.ADON = 1; // turn ADC ON //read potz ADCON1 = 0x0002; // Sampel on for (i = 0; i < 33330; i++) // 10 ms Delay at 20 MIPs ; ADCON1 = 0xFFFD; // Sampel off while (!ADCON1bits.DONE); PotZ = ADCBUF2; PhaseValues[0] = PotZ; PhaseValues[1] = ((PhaseValues[0] /6 + 1) % 65536); PhaseValues[2] = ((PhaseValues[1] /6 + 1) % 65536); PhaseValues[3] = ((PhaseValues[2] /6) % 65536); PhaseValues[4] = ((PhaseValues[3] /6 + 1) % 65536); PhaseValues[5] = ((PhaseValues[4] /6 + 1) % 65536); IFS0bits.ADIF = 0; IEC0bits.ADIE = 1; // Clear ISR flag // Enable interrupts Function: void InitMCPWM(void) PreCondition: InitMCPWM, intializes the PWM as follows: 1. FPWM = hz 2. Complementary PWMs with center aligned 3. Set Duty Cycle to 0 for complementary, which is half the period 4. Set ADC to be triggered by PWM special trigger 5. Configure deadtime to be 500 ns Note:
28 void InitMCPWM(void) TRISE = 0x0100; // PWM pins as outputs, and FLTA as input PTPER = (FCY/FPWM - 1) >> 1; // Compute Period based on CPU speed and them as // required PWM frequency (see defines) OVDCON = 0x0000; // Disable all PWM outputs. DTCON1 = 0x0008; // ~500 ns of dead time PWMCON1 = 0x0077; // Enable PWM output pins and configure // complementary mode PDC1 = PTPER; // Initialize as 0 voltage PDC2 = PTPER; // Initialize as 0 voltage PDC3 = PTPER; // Initialize as 0 voltage SEVTCMP = 1; // Enable triggering for ADC PWMCON2 = 0x0F02; // 16 postscale values, for achieving 20 khz PTCON = 0x8002; // start PWM as center aligned mode Function: void InitICandCN(void) PreCondition: Configure Hall sensor inputs, one change notification and two input captures. on IC7 the actual capture value is used for further period calculation Note: void InitICandCN(void) //Hall A -> IC2. Hall A is used for Speed commutation. //Hall B -> IC7. Hall B is used for Speed measurement and commutation. //Hall C -> IC8. Hall C is only used for commutation. TRISB = 0x30; TRISD = 0x02; // Ensure that hall connections are inputs // Ensure that hall connections are inputs
29 // Init Input Capture 2 IC2CON = 0x0001; // Input capture every edge with interrupts and TMR3 IFS0bits.IC2IF = 0; // Clear interrupt flag // Init Input Capture 7 IC7CON = 0x0001; // Input capture every edge with interrupts and TMR3 IFS1bits.IC7IF = 0; // Clear interrupt flag // Init Input Capture 8 IC8CON = 0x0001; // Input capture every edge with interrupts and TMR3 IFS1bits.IC8IF = 0; // Clear interrupt flag Function: void InitTMR1(void) PreCondition: Initialization of timer 1 as a periodic interrupt each 1 ms for speed control, motor stalled protection which includes: forced commutation if the motor is too slow, or motor stopped if the motor is stalled. Note: void InitTMR1(void) T1CON = 0x0020; // internal Tcy/64 clock TMR1 = 0; PR1 = 313; // 1 ms interrupts for 20 MIPS T1CONbits.TON = 1; // turn on timer 1
30 Function: PreCondition: void InitTMR3(void) Initialization of timer 3 as the timebase for the capture channels for calculating the period of the halls. Note: void InitTMR3(void) T3CON = 0x0020; // internal Tcy/64 clock TMR3 = 0; PR3 = 0xFFFF; T3CONbits.TON = 1; // turn on timer 3 Function: void InitUserInt(void) PreCondition: Initialization of the IOs used by the application. The IOs for the PWM and for the ADC are initialized in their respective peripheral initialization subroutine. Note: void InitUserInt(void) TRISC = 0x4000; // S2/RC14 as input
31 TRISD = 0x0000; //debug // Analog pin for POT already initialized in ADC init subroutine PORTF = 0x0008; // RS232 Initial values TRISF = 0xFFF7; // TX as output void ICD(void) Mode = Mode; Mode = Mode; void trace(unsigned int v) t[n] = v; if (v == 0) v = v; v = v; n += 1; if (n > 50) n=n; n = 0; // End of SinusoidalBLDC v1.2.c
#define CLOSED_LOOP // if defined the speed controller will be enabled #undef PHASE_ADVANCE // for extended speed ranges this should be defined
// File: sinusoidalbldc DJ1.c // // Written By: Jorge Zambada, Microchip Technology // Changed By: Douwe Jippes, d.jippes@hccnet.nl (HI6sim) // // The following files should be included in the MPLAB project:
More informationdspic Interrupts The Interrupt Control and Staus Registers are :- ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 1
dspic Interrupts The dspic30f4012 has 30 interrupt sources which 3 are external interrupts and 4 processor exception traps. There are 8 user selectable priority levels for each interrupt source. These
More informationTimer0..Timer3. Interrupt Description Input Conditions Enable Flag
Timer0..Timer3 Timers are pretty useful: likewise, Microchip provides four different timers for you to use. Like all interrupts, you have to Enable the interrupt, Set the conditions of the interrupt, and
More informationMicroprocessors B (17.384) Spring Lecture Outline
Microprocessors B (17.384) Spring 2013 Lecture Outline Class # 04 February 12, 2013 Dohn Bowden 1 Today s Lecture Administrative Microcontroller Hardware and/or Interface Programming/Software Lab Homework
More informationREPORT MICROCHIP CONTROLLER UNITS AND DIGITAL TECHNICS PRACTICING. Student : Đỗ Thành Trung Student Number : Class : 14146CL2 CONTENT :
REPORT CONTENT : MICROCHIP CONTROLLER UNITS AND DIGITAL TECHNICS PRACTICING Lecturer : Student : Mst. Bùi Hà Đức Đỗ Thành Trung Student Number : 14146279 Class : 14146CL2 Ho Chi Minh city, 26 th October
More informationMore Fun with Timer Interrupts
More Fun with Timer Interrupts Chords Objective: Play a musical chord each time you press a button: Button RC0 RC1 RC2 Timer Timer0 Timer1 Timer3 RB0 A3 C4 E4 RB1 B3 D4 F4 RB2 C4 E4 G4 Calculations: Assume
More informationMicrocontroller Overview
Microcontroller Overview Microprocessors/Microcontrollers/DSP Microcontroller components Bus Memory CPU Peripherals Programming Microcontrollers vs. µproc. and DSP Microprocessors High-speed information
More informationAN-8205 AMC Library Hall Interface Summary AMC Introduction
www.fairchildsemi.com AMC Library Hall Interface Summary The FCM8531 is an application-specific parallel-core processor for motor control that consists of an Advanced Motor Controller (AMC) processor and
More informationInterrupts. Embedded Systems Interfacing. 08 September 2011
08 September 2011 An iterrupt is an internal or external event that forces a hardware call to a specified function called an interrupt service routine Interrupt enable must be set (initialization) The
More informationUNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2013
Introduction Reading Concepts UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2013 Lab 2 Bouncing LEDs In this lab, you will
More informationECE Homework #10
Timer 0/1/2/3 ECE 376 - Homework #10 Timer 0/1/2/3, INT Interrupts. Due Wednesday, November 14th, 2018 1) Write a program which uses INT and Timer 0/1/2/3 interrupts to play the cord C#major for 1.000
More informationAnalog Output with a Digital to Analog Converter
Analog Output with a Digital to Analog Converter Matthew Beckler beck0778@umn.edu EE2361 Lab 007 April 5, 2006 Abstract Without help, microcontrollers can have great trouble creating analog signals. Approximations
More information/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */
/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */ /*the speed the cell which are less dense can float and the cell that are denser can sink*/ /*the user has five
More informationFunctional block diagram AD53x1 (Analog Devices)
Objectives - To read the A/D converter and turn the converted digital value back into an analogue voltage using an external D/A converter. The entire cycle including ADC and DAC is to be run at a fixed
More informationMPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine
MPLAB SIM MPLAB IDE Software Simulation Engine 2004 Microchip Technology Incorporated MPLAB SIM Software Simulation Engine Slide 1 Welcome to this web seminar on MPLAB SIM, the software simulator that
More informationTable of Figures Figure 1. High resolution PWM based DAC...2 Figure 2. Connecting the high resolution buck converter...8
HR_PWM_DAC_DRV Texas Instruments C2000 DSP System Applications Group Table of contents 1 Overview...2 2 Module Properties...2 3 Module Input and Output Definitions...3 3.1 Module inputs...3 3.2 Module
More informationTimer1 Capture Mode:
Timer1 Capture Mode: Interrupt Description Input Conditions Enable Flag Timer 1 Trigger after N events N = 1.. 2 19 100ns to 0.52 sec RC0 TMR1CS = 1 TMR1IF Timer 1 Capture Mode 1 Timer 1 Capture Mode 2
More informationIntroduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.
Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform www.sierraradio.net www.hamstack.com Topics Introduction Hardware options Software development HamStack project
More informationSection 16. Analog-to-Digital Converter (ADC)
16 HIGHLIGHTS Section 16. Analog-to-Digital er (ADC) This section of the manual contains the following major topics: Analog-to-Digital er (ADC) 16.1 Introduction... 16-2 16.2 Control Registers... 16-6
More informationSpeed Control of a DC Motor using Digital Control
Speed Control of a DC Motor using Digital Control The scope of this project is threefold. The first part of the project is to control an LCD display and use it as part of a digital tachometer. Secondly,
More informationKOLLMORGEN. SERVOSTAR CD. SERCOS IDN Manual M-SS rev. F. Solutions by D A N A H E R M O T I O N
KOLLMORGEN www.danahermotion.com SERVOSTAR CD Solutions by D A N A H E R M O T I O N SERCOS IDN Manual M-SS-017-05 rev. F Revision History Revision Edition Date Reason for Revision 1 05/01/1999 Initial
More informationNubotics Device Interface DLL
Nubotics Device Interface DLL ver-1.1 Generated by Doxygen 1.5.5 Mon Mar 2 17:01:02 2009 Contents Chapter 1 Module Index 1.1 Modules Here is a list of all modules: Initialization Functions.............................??
More informationSection 38. Direct Memory Access (DMA) (Part III)
Section 38. Direct Memory Access () (Part III) HIGHLIGHTS This section of the manual contains the following topics 38.1 Introduction... 38-2 38.2 Registers... 38-3 38.3 Block Diagram... 38-12 38.4 Data
More informationTimer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:
Background: Timer2 Interrupts The execution time for routines sometimes needs to be set. This chapter loops at several ways to set the sampling rate. Example: Write a routine which increments an 8-bit
More informationFirmware Revision History
www.danahermotion.com CD SynqNet Firmware Revision History Updated December 14, 2005 Firmware Revision History Page 2 of 15 Table Of Contents BASE VERSION: 1.1.9... 4 VERSION 1.1.9D... 4 VERSION 1.2.0...
More informationBME 4900 Page 1 of 2. Meeting 2: Personal Progress Report 12/2/09 Team 12 with Drew Seils. Semester One Week Two
BME 4900 Page 1 of 2 Semester One Week Two These past two saw a lot of progress with the Revo stationary bike project. During Thanksgiving break Shane spent most of his time doing research for the power
More information2G Actuator Communications Protocol Document Rotary & Linear Actuators
2752 Capitol Drive Suite #103 Sun Prairie, WI 53590 2150080 2G Actuator Packets - Rotary & Linear Revision AI Date 4/25/2018 2G Actuator Communications Protocol Document Rotary & Linear Actuators DOCUMENT
More informationEmbedded systems. Exercise session 3. Microcontroller Programming Lab Preparation
Embedded systems Exercise session 3 Microcontroller Programming Lab Preparation Communications Contact Mail : michael.fonder@ulg.ac.be Office : 1.82a, Montefiore Website for the exercise sessions and the
More information12.1. Unit 12. Exceptions & Interrupts
12.1 Unit 12 Exceptions & Interrupts 12.2 Disclaimer 1 This is just an introduction to the topic of interrupts. You are not meant to master these right now but just start to use them We will cover more
More informationC and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)
C and Embedded Systems A µp-based system used in a device (i.e, a car engine) performing control and monitoring functions is referred to as an embedded system. The embedded system is invisible to the user
More informationSquareWear Programming Reference 1.0 Oct 10, 2012
Content: 1. Overview 2. Basic Data Types 3. Pin Functions 4. main() and initsquarewear() 5. Digital Input/Output 6. Analog Input/PWM Output 7. Timing, Delay, Reset, and Sleep 8. USB Serial Functions 9.
More informationET-PIC 24 WEB-V1. o Central Processing Unit (CPU) o System. o nanowatt Power Managed Modes. o Analog Features
ET-PIC 24 WEB-V1 ET-PIC 24 WEB-V1 is PIC Board Microcontroller from Microchip that uses 16 Bit No.PIC24FJ128GA008 Microcontroller for processing data and develops board. The remarkable specification of
More informationCprE 288 Introduction to Embedded Systems (Timers/Input Capture) Instructors: Dr. Phillip Jones
CprE 288 Introduction to Embedded Systems (Timers/Input Capture) Instructors: Dr. Phillip Jones 1 Announcements HW 4, Due Wed 6/13 Quiz 5 (15 min): Wed 6/13, Textbook reading: Section 9.1, 9.2 (your one-side
More informationLab 6 - Bouncing LEDs Commit ID Form:
UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE-13/L: COMPUTER SYSTEMS AND C PROGRAMMING Lab 6 - Bouncing LEDs Commit ID Form: http://goo.gl/forms/eas2rzcsl7 Introduction
More informationSERIES PM130EH POWERMETERS COMMUNICATIONS REFERENCE GUIDE
SERIES PM130EH POWERMETERS COMMUNICATIONS ASCII Communications Protocol REFERENCE GUIDE Every effort has been made to ensure that the material herein is complete and accurate. However, the manufacturer
More informationEECS 373 Midterm 2 Fall 2018
EECS 373 Midterm 2 Fall 2018 Name: unique name: Sign the honor code: I have neither given nor received aid on this exam nor observed anyone else doing so. Nor did I discuss this exam with anyone after
More informatione-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text
e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text In this lecture embedded C program for interrupt handling
More informationUNCA CSCI 255 Exam 3 Fall 2011
UNCA CSCI 255 Exam 3 Fall 2011 This is a closed book and closed notes exam. Laptops, cell phones, and any other electronic storage or communication devices may not be used during this exam. Name: KEY If
More information21. PID control The theory of PID control
1 21. PID control The PID (Proportional Integral Differential) controller is a basic building block in regulation. It can be implemented in many different ways, this example will show you how to code it
More informationReminder: tutorials start next week!
Previous lecture recap! Metrics of computer architecture! Fundamental ways of improving performance: parallelism, locality, focus on the common case! Amdahl s Law: speedup proportional only to the affected
More informationC:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c
C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c / FileName: problem1cunningham.c Processor: PIC18F4520 Compiler: MPLAB C18 v.3.06 This file does the following...
More informationdspic Elmer 166 An introduction to using the dspic John J. McDonough, WB8RCR
dspic Elmer 166 An introduction to using the dspic John J. McDonough, WB8RCR Elmer 166 dspic Elmer 166 An introduction to using the dspic Edition 1 Author John J. McDonough, WB8RCR wb8rcr@arrl.net The
More informationMotors I Automation I Energy I Transmission & Distribution I Coatings. SoftPLC CFW100. User Manual
Motors I Automation I Energy I Transmission & Distribution I Coatings SoftPLC CFW User Manual SoftPLC User Manual Series: CFW Language: English Document Number: 2965849 / 2 Publication Date: /24 Contents
More informationAccurate Time and Interrupts
Accurate Time and Interrupts Matthew Beckler beck0778@umn.edu EE2361 Lab Section 007 March 7, 2006 Abstract In this lab, we create a very accurate digital clock using one of the microcontroller s timers.
More informationCANopen. stepim. Reference Manual. Manual Revision: 1.3 Firmware Version:
CApen Reference Manual stepim Manual Revision: 1.3 Firmware Version: 0.0.2.85 Revision History Document Revision Date Remarks 1.3 Mar. 2016 Update. Firmware 0.0.2.85 1.2 28 Feb. 2016 Update. Firmware
More informationNXShield Interface Specifications
NXShield Advanced Development Guide v1.0 NXShield Interface Specifications Power Specs: NXShield can be powered from external power supply. Max Power Rating: 10.5 Volts DC Minimum 6.6 Volts DC needed to
More informationINTERFACING HARDWARE WITH MICROCONTROLLER
INTERFACING HARDWARE WITH MICROCONTROLLER P.Raghavendra Prasad Final Yr EEE What is a Microcontroller? A microcontroller (or MCU) is acomputer-on-a-chip. It is a type of microprocessor emphasizing self-
More informationUNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017
TW30 UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017 MICROPROCESSOR BASED SYSTEMS MODULE NO: EEM7016 Date: Wednesday 17 May
More informationIntroduction to the MC9S12 Hardware Subsystems
Setting and clearing bits in C Using pointers in C o Program to count the number of negative numbers in an area of memory Introduction to the MC9S12 Hardware Subsystems o The MC9S12 timer subsystem Operators
More informationSignature: 1. (10 points) Basic Microcontroller Concepts
EE 109 Practice Final Exam Last name: First name: Signature: The practice final is one hour, ten minutes long, closed book, closed notes, calculators allowed. To receive full credit on a question show
More informationTable of Contents COMPANY PROFILE 1-1 SECTION 1. INTRODUCTION 1-1
COMPANY PROFILE 1-1 SECTION 1. INTRODUCTION 1-1 Introduction... 1-2 Manual Objective... 1-3 Device Structure... 1-4 Development Support... 1-6 Device Varieties... 1-7 Style and Symbol Conventions... 1-12
More informationEL6483: Brief Overview of C Programming Language
EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions
More informationEmbedded assembly is more useful. Embedded assembly places an assembly function inside a C program and can be used with the ARM Cortex M0 processor.
EE 354 Fall 2015 ARM Lecture 4 Assembly Language, Floating Point, PWM The ARM Cortex M0 processor supports only the thumb2 assembly language instruction set. This instruction set consists of fifty 16-bit
More informationSANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1
SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1 Subject: Microcontroller and Interfacing (151001) Class: B.E.Sem V (EC-I & II) Q-1 Explain RISC
More informationEE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.
More on Programming the 9S12 in C Huang Sections 5.2 through 5.4 Introduction to the MC9S12 Hardware Subsystems Huang Sections 8.2-8.6 ECT_16B8C Block User Guide A summary of MC9S12 hardware subsystems
More informationUnderstanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,
Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices, CISC and RISC processors etc. Knows the architecture and
More informationCOMMUNICATION MODBUS PROTOCOL
COMMUNICATION MODBUS PROTOCOL CE4DT36 CONTO D4 Pd (3-single phase) PR134 20/10/2016 Pag. 1/11 Contents 1.0 ABSTRACT... 2 2.0 DATA MESSAGE DESCRIPTION... 3 2.1 Parameters description... 3 2.2 Data format...
More information11010 SBC 16-bit Architecture, C30 & Standard Peripherals Hand Out
11010 SBC 16-bit Architecture, C30 & Standard Peripherals Hand Out 2005 Microchip Technology Incorporated. All Rights Reserved Page 1 MPLAB Navigation Quick ways to find functions or variables in MPLAB
More informationUniversity of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory
University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory 0907334 6 Experiment 6:Timers Objectives To become familiar with hardware timing
More informationEE 354 Fall 2013 Lecture 9 The Sampling Process and Evaluation of Difference Equations
EE 354 Fall 2013 Lecture 9 The Sampling Process and Evaluation of Difference Equations Digital Signal Processing (DSP) is centered around the idea that you can convert an analog signal to a digital signal
More informationBy the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab
By the end of Class Pseudo-code for Lab 1-2 due as part of prelab Homework #5 on website due before next class Outline Introduce Lab 1-2 Counting Timers on C8051 Interrupts Laboratory Worksheet #05 Copy
More informationUM0708 User manual. STM8Sxxx three-phase BLDC motor control software library V1.0. Introduction
User manual STM8Sxxx three-phase BLDC motor control software library V1.0 Introduction This user manual describes the brushless direct current motor (BLDC) scalar software library, a scalar control firmware
More informationCOMMUNICATION MODBUS PROTOCOL
COMMUNICATION MODBUS PROTOCOL CE4DMID31 / CE4DMID21 CONTO D4 Pd MID PR123 20/10/2016 Pag. 1/9 Contents 1.0 ABSTRACT... 2 2.0 DATA MESSAGE DESCRIPTION... 3 2.1 Parameters description... 3 2.2 Data format...
More informationFujitsu Microelectronics Europe Application Note MCU-AN E-V10 F²MC-FR FAMILY 32-BIT MICROCONTROLLER MB91460 RELOAD TIMER APPLICATION NOTE
Fujitsu Microelectronics Europe Application Note MCU-AN-300060-E-V10 F²MC-FR FAMILY 32-BIT MICROCONTROLLER MB91460 RELOAD TIMER APPLICATION NOTE Revision History Revision History Date 2008-03-26 V1.0,
More informationModern Robotics Inc. Sensor Documentation
Sensor Documentation Version 1.0.1 September 9, 2016 Contents 1. Document Control... 3 2. Introduction... 4 3. Three-Wire Analog & Digital Sensors... 5 3.1. Program Control Button (45-2002)... 6 3.2. Optical
More informationTeam 8: Robert Blake Craig Goliber Alanna Ocampo
Team 8: Robert Blake Craig Goliber Alanna Ocampo Objective of the design CAD Presentation Microcontroller Implementation PCB Design Design Limitations Conclusion Problem: Design a centrifuge which was
More informationTPMC Channel Serial Interface RS232/RS422. Version 1.0. User Manual. Issue August 2014
The Embedded I/O Company TPMC461 8 Channel Serial Interface RS232/RS422 Version 1.0 User Manual Issue 1.0.6 August 2014 TEWS TECHNOLOGIES GmbH Am Bahnhof 7 25469 Halstenbek, Germany www.tews.com Phone:
More information#include <stdio.h> // // Global CONSTANTS
Distance.c Author: Baylor Electromechanical Systems Operates on an external 18.432 MHz oscillator. Target: Cygnal Educational Development Board / C8051F020 Tool chain: KEIL C51 6.03 / KEIL EVAL C51 Utilizes
More informationEmbedded Systems Module. 6EJ505. C Tutorial 3: using the ICD3 rev tjw
Embedded Systems Module. 6EJ505 C Tutorial 3: using the ICD3 rev. 27.9.16 tjw Images are reproduced from Reference 1. Microchip permits the use of its images for educational purposes. Main Learning Points
More informationdspic30f6010 Family Silicon Errata and Data Sheet Clarification (1) Revision ID for Silicon Revision (2)
dspic30f6010 Family Silicon Errata and Data Sheet Clarification The dspic30f6010 family devices that you have received conform functionally to the current Device Data Sheet (DS70119E), except for the anomalies
More information// and verify that there is a sine wave with frequency <FREQUENCY> and
F330DC_IDA0_SineWave.c Copyright 2006 Silicon Laboratories, Inc. http:www.silabs.com Program Description: This program outputs a sine wave using IDA0. IDA0's output is scheduled to update at a rate determined
More informationTPMC Channel Serial Interface RS232/RS422. Version 1.0. User Manual. Issue August 2014
The Embedded I/O Company TPMC460 16 Channel Serial Interface RS232/RS422 Version 1.0 User Manual Issue 1.0.6 August 2014 TEWS TECHNOLOGIES GmbH Am Bahnhof 7 25469 Halstenbek, Germany www.tews.com Phone:
More informationMTRX3700 Mechatronics
MTRX3700 Mechatronics 3 2015 PIC18F452 Software Exercises David Rye You are to work in a group of two students to write, debug and demonstrate a series of small assembly language and C programs that meet
More informationFuel Injection Control for a 12 Cylinder Formula 1 Engine
Microcontrollers ApNote AP1635 o additional file APXXXX01.EXE available Consequently, the C166 finds many applications in areas such as motor control and automotive engine management where the production
More informationDEV-1 HamStack Development Board
Sierra Radio Systems DEV-1 HamStack Development Board Reference Manual Version 1.0 Contents Introduction Hardware Compiler overview Program structure Code examples Sample projects For more information,
More informationPCI-HPDI32A-COS User Manual
PCI-HPDI32A-COS User Manual Preliminary 8302A Whitesburg Drive Huntsville, AL 35802 Phone: (256) 880-8787 Fax: (256) 880-8788 URL: www.generalstandards.com E-mail: support@generalstandards.com User Manual
More information8051 Microcontroller
8051 Microcontroller The 8051, Motorola and PIC families are the 3 leading sellers in the microcontroller market. The 8051 microcontroller was originally developed by Intel in the late 1970 s. Today many
More informationCS/ECE 5780/6780: Embedded System Design
CS/ECE 5780/6780: Embedded System Design John Regehr Lecture 2: 68HC12 Architecture & Lab 1 Introduction Duff s Device void foo (int x, int *y, int *z) { switch (x % 8) { case 0: do { *y++ = *z++; case
More informationLVD Digital Servo Drive
Digital Servo Drive CApen Reference Manual Revision 2.0 Revision History Document Revision Date Remarks 2.0 Mar. 2012 1.0 Oct. 2011 Initial release Hardware Revision Firmware Revision Software Revision
More informationdigital I/O lines which can be configured as inputs or as outputs; the output driver can be either opencollector/open-drain
Microcontroller Programming I MP5-1 Microcontroller Programming I MP5-2 week lecture topics 5 Microcontroller Programming I - Digital I/O - A/D converter - Simple serial communication (RS-232, polling)
More information(Embedded) Systems Programming Overview
System Programming Issues EE 357 Unit 10a (Embedded) Systems Programming Overview Embedded systems programming g have different design requirements than general purpose computers like PC s I/O Electro-mechanical
More informationHuman Response Timer
Human Response Timer Matthew Beckler beck0778@umn.edu EE2361 Lab Section 007 March 29, 2006 Abstract In this lab, we create a very useful application, a human response timer. The user s reaction time is
More informationTMCC160 TMCL FIRMWARE MANUAL
motioncookie SYSTEM IN A PACKAGE motioncookie TMCC160 TMCL FIRMWARE MANUAL TMCC160 TMCL Firmware Version 2.09 2015-NOV-25 Document Revision 1.0 2015-DEC-04 The TMCL Firmware is used in combination with
More informationOption H Motion Library Version Dec Firmware Version 2.40, Rev G4, Opt 1
33 South La Patera Lane Santa Barbara, CA 93117-3214 ph (805) 681-3300 fax (805) 681-3311 tech@motioneng.com www.motioneng.com Release Note DSP Series Sinusoidal Commutation v2.0b4 Option H001-0022 Motion
More informationDepartment of Electronics and Instrumentation Engineering Question Bank
www.examquestionpaper.in Department of Electronics and Instrumentation Engineering Question Bank SUBJECT CODE / NAME: ET7102 / MICROCONTROLLER BASED SYSTEM DESIGN BRANCH : M.E. (C&I) YEAR / SEM : I / I
More informationrobotics / mechatronics; the velocity of a DC motor
Embedded Control Applications I MP9-1 Embedded Control Applications I MP9-2 week lecture topics 9 Embedded Control Applications I - DC motor speed control: Potentiometer µc PWM - Output of clear text log
More informationPIC Microcontroller Introduction
PIC Microcontroller Introduction The real name of this microcontroller is PICmicro (Peripheral Interface Controller), but it is better known as PIC. Its first ancestor was designed in 1975 by General Instruments.
More informationLOW VOLTAGE BLDC MOTOR CONTROLLER
DESCRIPTION The D113-024D10/036D10/050D05 are members of a DSP based low voltage brushless DC motor controller family. The controllers are for controlling the brushless DC motor with or without Hall position
More informationIntroduction to Embedded Systems
Stefan Kowalewski, 4. November 25 Introduction to Embedded Systems Part 2: Microcontrollers. Basics 2. Structure/elements 3. Digital I/O 4. Interrupts 5. Timers/Counters Introduction to Embedded Systems
More informationMicrocontrollers. Fig. 1 gives a comparison of a microprocessor system and a microcontroller system.
Syllabus: : Introduction to, 8051 Microcontroller Architecture and an example of Microcontroller based stepper motor control system (only Block Diagram approach). (5 Hours) Introduction to A microcontroller
More informationMicrocontroller Introduction
Microcontroller Introduction Embedded Systems 2-1 Data Formats for the Renesas Microcontroller Byte Word 8 bits signed & unsigned unsigned range 0 to 255 unsigned char a; 16 bits signed & unsigned unsigned
More information8032 MCU + Soft Modules. c = rcvdata; // get the keyboard scan code
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 { 0x25, 0x66 }, // "4" { 0x2E, 0x6D }, // "5" { 0x36, 0x7D }, // "6" { 0x3D, 0x07 }, // "7" { 0x3E, 0x7F }, // "8" { 0x46,
More informationAPPLICATION NOTE /20/02 Getting started using IPM240-5E with a brushless motor
Problem: For new users of an intelligent drive, starting to implement a motion control application can be a quite complex task. You need to know how to hook-up the components of the motion system, to configure
More informationHistory of the Microprocessor. ECE/CS 5780/6780: Embedded System Design. Microcontrollers. First Microprocessors. MC9S12C32 Block Diagram
History of the Microprocessor ECE/CS 5780/6780: Embedded System Design Chris J. Myers Lecture 1: 68HC12 In 1968, Bob Noyce and Gordon Moore left Fairchild Semiconductor and formed Integrated Electronics
More informationMotors I Automation I Energy I Transmission & Distribution I Coatings. SoftPLC CFW500. User s Manual
Motors I Automation I Energy I Transmission & Distribution I Coatings SoftPLC CFW5 User s Manual SoftPLC Manual Series: CFW5 Language: English Document Number: 2299985 / Publication Date: 6/25 Summary
More informationAFRecorder 4800R Serial Port Programming Interface Description For Software Version 9.5 (Last Revision )
AFRecorder 4800R Serial Port Programming Interface Description For Software Version 9.5 (Last Revision 8-27-08) Changes from Version 9.2 1. The communication baud rate is raised to 9600. 2. Testing with
More informationAppendix A: Data Registers
Appendix A: Data Registers Data registers can be dedicated to a specific purpose, optionally dedicated or continuously available for user data. They can be designated as Read Only or Read & Write. Data
More informationUsing peripherals on the MSP430 (if time)
Today's Plan: Announcements Review Activities 1&2 Programming in C Using peripherals on the MSP430 (if time) Activity 3 Announcements: Midterm coming on Feb 9. Will need to write simple programs in C and/or
More informationLogosol AC/DC Intelligent Servo Drive LS-173E Doc # / Rev. F, 12/16/2009
Features Motors supported: - Panasonic A and S series motors - Brushless 60/120 commutated - Brush-commutated (DC) - Motors with index coded commutation Output current - 12A peak, 8A continuous - 20A peak,
More informationEmbedded Software TI2726 B. 4. Interrupts. Koen Langendoen. Embedded Software Group
Embedded Software 4. Interrupts TI2726 B Koen Langendoen Embedded Software Group What is an Interrupt? Asynchronous signal from hardware Synchronous signal from software Indicates the need for attention
More information