ST / Mbed 2 deprecated HelloWorld_IHM07M1

Dependencies:   BLDCmotorDriver RateLimiter mbed

Fork of HelloWorld_IHM07M1 by Antonio Vilei

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2016 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 // This example is based on the BLDCmotorDriver motor control library
00018 // by the TVZ Mechatronics Team, University of Applied Sciences Zagreb,
00019 // Professional Study in Mechatronics:
00020 // https://developer.mbed.org/teams/TVZ-Mechatronics-Team/code/BLDCmotorDriver/
00021  
00022 #include <stdio.h>
00023 #include "mbed.h"
00024 #include "RateLimiter.h"
00025 #include "SPN7Driver.h"
00026 // Pin definitions for X-NUCLEO-IHM070M1 with STM32 Nucleo boards
00027 #include "x_nucleo_ihm07m1_targets.h"
00028 
00029 // Instance of the motor driver
00030 SPN7Driver M(
00031              P_IN1, P_IN2, P_IN3, // Logic input pins
00032              P_EN1, P_EN2, P_EN3, // Enable channel pins
00033              P_HALL1, P_HALL2, P_HALL3, // Hall sensors pins
00034              P_FAULT // Fault LED
00035              );
00036              
00037 // Pin to check temperature on the X-NUCLEO-IHM07M1 board
00038 AnalogIn temperature(P_TEMP);
00039 
00040 void checkTemperature()
00041 {
00042     if (temperature > 0.55f){
00043         printf("Overheating... Turning off now\n\r");
00044         M.setDutyCycle(0);
00045         M.coast(); 
00046     }
00047 }
00048 
00049 int main() {
00050     printf("Press 'w' to speed up, 's' to speed down\n\r");
00051     
00052     // Duty cycle value to be used for speed control
00053     // Positive for clockwise; negative for anti-clockwise
00054     float dc = 0.0f;
00055     
00056     Ticker ticker;
00057     ticker.attach(checkTemperature, 1); // Periodic overheating check
00058     
00059     while(true) { 
00060 
00061         char c = getchar();
00062         if((c == 'w') && (dc < 0.9f)) {
00063             dc += 0.1f;
00064             M.setDutyCycle(dc);
00065         }
00066         if((c == 's') && (dc > -0.9f)) {
00067             dc -= 0.1f;
00068             M.setDutyCycle(dc);
00069         }
00070 
00071         printf("Duty Cycle: %1.2f, Sector: %d\n\r",dc, M.getSector());
00072 
00073     }   
00074 }