CQ_KIT_Ver1_5
Dependencies: mbed RateLimiter BLDCmotorDriverCQ_KIT_Ver1_5
main.cpp@11:0120619cdfb7, 2016-10-20 (annotated)
- Committer:
- avilei
- Date:
- Thu Oct 20 14:26:13 2016 +0000
- Revision:
- 11:0120619cdfb7
- Parent:
- 10:5fbe1476624c
- Child:
- 12:33614e1dc638
Fix phase offset and allow clockwise and anti-clockwise spinning
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
avilei | 2:4ae769d0b112 | 1 | /* mbed Microcontroller Library |
avilei | 2:4ae769d0b112 | 2 | * Copyright (c) 2006-2016 ARM Limited |
avilei | 2:4ae769d0b112 | 3 | * |
avilei | 2:4ae769d0b112 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
avilei | 2:4ae769d0b112 | 5 | * you may not use this file except in compliance with the License. |
avilei | 2:4ae769d0b112 | 6 | * You may obtain a copy of the License at |
avilei | 2:4ae769d0b112 | 7 | * |
avilei | 2:4ae769d0b112 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
avilei | 2:4ae769d0b112 | 9 | * |
avilei | 2:4ae769d0b112 | 10 | * Unless required by applicable law or agreed to in writing, software |
avilei | 2:4ae769d0b112 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
avilei | 2:4ae769d0b112 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
avilei | 2:4ae769d0b112 | 13 | * See the License for the specific language governing permissions and |
avilei | 2:4ae769d0b112 | 14 | * limitations under the License. |
avilei | 2:4ae769d0b112 | 15 | */ |
avilei | 2:4ae769d0b112 | 16 | |
avilei | 2:4ae769d0b112 | 17 | // This example is based on the BLDCmotorDriver motor control library |
avilei | 2:4ae769d0b112 | 18 | // by the TVZ Mechatronics Team, University of Applied Sciences Zagreb, |
avilei | 2:4ae769d0b112 | 19 | // Professional Study in Mechatronics: |
avilei | 2:4ae769d0b112 | 20 | // https://developer.mbed.org/teams/TVZ-Mechatronics-Team/code/BLDCmotorDriver/ |
avilei | 2:4ae769d0b112 | 21 | |
avilei | 2:4ae769d0b112 | 22 | #include <stdio.h> |
mslovic | 0:24b227524f2d | 23 | #include "mbed.h" |
mslovic | 0:24b227524f2d | 24 | #include "RateLimiter.h" |
avilei | 2:4ae769d0b112 | 25 | #include "SPN7Driver.h" |
avilei | 2:4ae769d0b112 | 26 | // Pin definitions for X-NUCLEO-IHM070M1 with STM32 Nucleo boards |
avilei | 2:4ae769d0b112 | 27 | #include "x_nucleo_ihm07m1_targets.h" |
mslovic | 0:24b227524f2d | 28 | |
avilei | 2:4ae769d0b112 | 29 | // Instance of the motor driver |
avilei | 2:4ae769d0b112 | 30 | SPN7Driver M( |
avilei | 2:4ae769d0b112 | 31 | P_IN1, P_IN2, P_IN3, // Logic input pins |
avilei | 2:4ae769d0b112 | 32 | P_EN1, P_EN2, P_EN3, // Enable channel pins |
avilei | 2:4ae769d0b112 | 33 | P_HALL1, P_HALL2, P_HALL3, // Hall sensors pins |
avilei | 2:4ae769d0b112 | 34 | P_FAULT // Fault LED |
avilei | 2:4ae769d0b112 | 35 | ); |
avilei | 5:3290e8857120 | 36 | |
avilei | 5:3290e8857120 | 37 | // Pin to check temperature on the X-NUCLEO-IHM07M1 board |
avilei | 10:5fbe1476624c | 38 | AnalogIn temperature(P_TEMP); |
avilei | 5:3290e8857120 | 39 | |
avilei | 5:3290e8857120 | 40 | void checkTemperature() |
avilei | 5:3290e8857120 | 41 | { |
avilei | 10:5fbe1476624c | 42 | if (temperature > 0.55f){ |
avilei | 5:3290e8857120 | 43 | printf("Overheating... Turning off now\n\r"); |
avilei | 5:3290e8857120 | 44 | M.setDutyCycle(0); |
avilei | 5:3290e8857120 | 45 | M.coast(); |
avilei | 5:3290e8857120 | 46 | } |
avilei | 5:3290e8857120 | 47 | } |
mslovic | 0:24b227524f2d | 48 | |
mslovic | 0:24b227524f2d | 49 | int main() { |
avilei | 2:4ae769d0b112 | 50 | printf("Press 'w' to speed up, 's' to speed down\n\r"); |
avilei | 3:4c71d3475814 | 51 | |
avilei | 4:3f63eed73ad1 | 52 | // Duty cycle value to be used for speed control |
avilei | 4:3f63eed73ad1 | 53 | float dc = 0.0f; |
avilei | 5:3290e8857120 | 54 | |
avilei | 5:3290e8857120 | 55 | Ticker ticker; |
avilei | 5:3290e8857120 | 56 | ticker.attach(checkTemperature, 1); // Periodic overheating check |
avilei | 3:4c71d3475814 | 57 | |
mslovic | 0:24b227524f2d | 58 | while(true) { |
mslovic | 0:24b227524f2d | 59 | |
avilei | 2:4ae769d0b112 | 60 | char c = getchar(); |
avilei | 2:4ae769d0b112 | 61 | if((c == 'w') && (dc < 0.9f)) { |
avilei | 2:4ae769d0b112 | 62 | dc += 0.1f; |
avilei | 2:4ae769d0b112 | 63 | M.setDutyCycle(dc); |
mslovic | 0:24b227524f2d | 64 | } |
avilei | 11:0120619cdfb7 | 65 | if((c == 's') && (dc > -0.9f)) { |
avilei | 2:4ae769d0b112 | 66 | dc -= 0.1f; |
avilei | 2:4ae769d0b112 | 67 | M.setDutyCycle(dc); |
avilei | 2:4ae769d0b112 | 68 | } |
avilei | 2:4ae769d0b112 | 69 | |
avilei | 2:4ae769d0b112 | 70 | printf("Duty Cycle: %1.2f, Sector: %d\n\r",dc, M.getSector()); |
avilei | 2:4ae769d0b112 | 71 | |
mslovic | 0:24b227524f2d | 72 | } |
mslovic | 0:24b227524f2d | 73 | } |