CQ_KIT_Ver1_5
Dependencies: mbed RateLimiter BLDCmotorDriverCQ_KIT_Ver1_5
Diff: main.cpp
- Revision:
- 2:4ae769d0b112
- Parent:
- 0:24b227524f2d
- Child:
- 3:4c71d3475814
diff -r aa6b6d379be4 -r 4ae769d0b112 main.cpp --- a/main.cpp Mon Jun 01 13:47:55 2015 +0000 +++ b/main.cpp Wed Oct 12 13:15:03 2016 +0000 @@ -1,30 +1,56 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// This example is based on the BLDCmotorDriver motor control library +// by the TVZ Mechatronics Team, University of Applied Sciences Zagreb, +// Professional Study in Mechatronics: +// https://developer.mbed.org/teams/TVZ-Mechatronics-Team/code/BLDCmotorDriver/ + +#include <stdio.h> #include "mbed.h" #include "RateLimiter.h" -#include "BLDCmotorDriver.h" +#include "SPN7Driver.h" +// Pin definitions for X-NUCLEO-IHM070M1 with STM32 Nucleo boards +#include "x_nucleo_ihm07m1_targets.h" -Serial pc(USBTX, USBRX); -float dc = 0.0; -BLDCmotorDriver M(p26, p24, p22, p25, p23, p21, p14, p17, p18, LED1); -DigitalOut EN(p8); -DigitalOut EN_BUCK(p28); +// Instance of the motor driver +SPN7Driver M( + P_IN1, P_IN2, P_IN3, // Logic input pins + P_EN1, P_EN2, P_EN3, // Enable channel pins + P_HALL1, P_HALL2, P_HALL3, // Hall sensors pins + P_FAULT // Fault LED + ); +// Duty cycle value to be used for speed control +float dc = 0.0f; int main() { - EN = 1; - pc.printf("Press 'w' to speed up, 's' to speed down\n\r"); + printf("Press 'w' to speed up, 's' to speed down\n\r"); while(true) { - char c = pc.getc(); - if((c == 'w') && (dc < 0.9)) { - dc += 0.1; - M.setDutyCycle(dc); + char c = getchar(); + if((c == 'w') && (dc < 0.9f)) { + dc += 0.1f; + M.setDutyCycle(dc); } - if((c == 's') && (dc > -0.9)) { - dc -= 0.1; - M.setDutyCycle(dc); - } - - pc.printf("Duty Cycle: %1.2f, Sector: %d\n\r",dc, M.getSector()); - + if((c == 's') && (dc > -0.9f)) { + dc -= 0.1f; + M.setDutyCycle(dc); + } + + printf("Duty Cycle: %1.2f, Sector: %d\n\r",dc, M.getSector()); + } } -