Raspberry Pi MOT HAT Based on STM32F030R8. The clock needs to be changed to 8MHz after export.

Dependencies:   mbed

Committer:
nightseas
Date:
Tue Aug 18 11:03:37 2015 +0000
Revision:
2:cff0fa966e58
Parent:
1:a6bcf44b90df
Child:
3:171f4d0ca77b
Add modified mbed lib into project.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nightseas 0:633cef71e6ba 1 #include "SysConfig.h"
nightseas 0:633cef71e6ba 2
nightseas 1:a6bcf44b90df 3 void SpeedTest(void)
nightseas 1:a6bcf44b90df 4 {
nightseas 1:a6bcf44b90df 5 printf("[Speed Test]\n\rMOT1 = %drpm, MOT2 = %drpm, MOT3 = %drpm, MOT4 = %drpm.\n\r", Mot_GetSpeed(1), Mot_GetSpeed(2), Mot_GetSpeed(3), Mot_GetSpeed(4));
nightseas 1:a6bcf44b90df 6 }
nightseas 1:a6bcf44b90df 7
nightseas 1:a6bcf44b90df 8 void VoltageTest(void)
nightseas 1:a6bcf44b90df 9 {
nightseas 1:a6bcf44b90df 10 printf("[Voltage Test]\n\rVBAT = %.2fV, VDD12V = %.2fV, VDD5V = %.2fV, VDD3V3 = %.2fV.\n\r", Vmon_ReadVolt(1), Vmon_ReadVolt(2), Vmon_ReadVolt(3), Vmon_ReadVolt(4));
nightseas 1:a6bcf44b90df 11 }
nightseas 1:a6bcf44b90df 12
nightseas 1:a6bcf44b90df 13 void MotTest(void)
nightseas 1:a6bcf44b90df 14 {
nightseas 1:a6bcf44b90df 15 int dir, turn;
nightseas 1:a6bcf44b90df 16 printf("\n\r==== Motor Test ====\n\r");
nightseas 1:a6bcf44b90df 17 for(int i=0; i<100; i+=20)
nightseas 1:a6bcf44b90df 18 {
nightseas 1:a6bcf44b90df 19 printf("\n\rMotor speed set to %d%%.\n\r", i);
nightseas 1:a6bcf44b90df 20 printf("-->Motor will move forward.\n\r");
nightseas 1:a6bcf44b90df 21 dir = 'f';
nightseas 1:a6bcf44b90df 22
nightseas 1:a6bcf44b90df 23 printf("---->Motor will move straight.\n\r");
nightseas 1:a6bcf44b90df 24 turn = 'm';
nightseas 1:a6bcf44b90df 25 Mot_Ctrl(dir, turn, (float)i / 100.0);
nightseas 1:a6bcf44b90df 26 SpeedTest();
nightseas 1:a6bcf44b90df 27 VoltageTest();
nightseas 1:a6bcf44b90df 28 LedToggle(0);
nightseas 1:a6bcf44b90df 29 wait(3);
nightseas 1:a6bcf44b90df 30
nightseas 1:a6bcf44b90df 31 printf("---->Motor will turn left.\n\r");
nightseas 1:a6bcf44b90df 32 turn = 'l';
nightseas 1:a6bcf44b90df 33 Mot_Ctrl(dir, turn, (float)i / 100.0);
nightseas 1:a6bcf44b90df 34 SpeedTest();
nightseas 1:a6bcf44b90df 35 VoltageTest();
nightseas 1:a6bcf44b90df 36 LedToggle(0);
nightseas 1:a6bcf44b90df 37 wait(3);
nightseas 1:a6bcf44b90df 38
nightseas 1:a6bcf44b90df 39 printf("---->Motor will turn right.\n\r");
nightseas 1:a6bcf44b90df 40 turn = 'r';
nightseas 1:a6bcf44b90df 41 Mot_Ctrl(dir, turn, (float)i / 100.0);
nightseas 1:a6bcf44b90df 42 SpeedTest();
nightseas 1:a6bcf44b90df 43 VoltageTest();
nightseas 1:a6bcf44b90df 44 LedToggle(0);
nightseas 1:a6bcf44b90df 45 wait(3);
nightseas 1:a6bcf44b90df 46
nightseas 1:a6bcf44b90df 47 printf("-->Motor will move forward.\n\r");
nightseas 1:a6bcf44b90df 48 dir = 'b';
nightseas 1:a6bcf44b90df 49
nightseas 1:a6bcf44b90df 50 printf("---->Motor will move straight.\n\r");
nightseas 1:a6bcf44b90df 51 turn = 'm';
nightseas 1:a6bcf44b90df 52 Mot_Ctrl(dir, turn, (float)i / 100.0);
nightseas 1:a6bcf44b90df 53 SpeedTest();
nightseas 1:a6bcf44b90df 54 VoltageTest();
nightseas 1:a6bcf44b90df 55 LedToggle(0);
nightseas 1:a6bcf44b90df 56 wait(3);
nightseas 1:a6bcf44b90df 57
nightseas 1:a6bcf44b90df 58 printf("---->Motor will turn left.\n\r");
nightseas 1:a6bcf44b90df 59 turn = 'l';
nightseas 1:a6bcf44b90df 60 Mot_Ctrl(dir, turn, (float)i / 100.0);
nightseas 1:a6bcf44b90df 61 SpeedTest();
nightseas 1:a6bcf44b90df 62 VoltageTest();
nightseas 1:a6bcf44b90df 63 LedToggle(0);
nightseas 1:a6bcf44b90df 64 wait(3);
nightseas 1:a6bcf44b90df 65
nightseas 1:a6bcf44b90df 66 printf("---->Motor will turn right.\n\r");
nightseas 1:a6bcf44b90df 67 turn = 'r';
nightseas 1:a6bcf44b90df 68 Mot_Ctrl(dir, turn, (float)i / 100.0);
nightseas 1:a6bcf44b90df 69 SpeedTest();
nightseas 1:a6bcf44b90df 70 VoltageTest();
nightseas 1:a6bcf44b90df 71 LedToggle(0);
nightseas 1:a6bcf44b90df 72 wait(3);
nightseas 1:a6bcf44b90df 73 }
nightseas 1:a6bcf44b90df 74 }
nightseas 1:a6bcf44b90df 75
nightseas 0:633cef71e6ba 76 void SelfTest(void)
nightseas 1:a6bcf44b90df 77 #if 1
nightseas 1:a6bcf44b90df 78 {
nightseas 1:a6bcf44b90df 79 printf("Starting motor velocimeter...\n\r");
nightseas 1:a6bcf44b90df 80 Mot_StartVelocimeter();
nightseas 1:a6bcf44b90df 81 while(1)
nightseas 1:a6bcf44b90df 82 {
nightseas 1:a6bcf44b90df 83 MotTest();
nightseas 1:a6bcf44b90df 84 }
nightseas 1:a6bcf44b90df 85 }
nightseas 1:a6bcf44b90df 86 #elif
nightseas 0:633cef71e6ba 87 {
nightseas 0:633cef71e6ba 88 //Breath LED
nightseas 0:633cef71e6ba 89 int i, j;
nightseas 0:633cef71e6ba 90 led_mb = 0;
nightseas 0:633cef71e6ba 91 while(1)
nightseas 0:633cef71e6ba 92 {
nightseas 0:633cef71e6ba 93 for(j=0;j<=100;j++)
nightseas 0:633cef71e6ba 94 {
nightseas 0:633cef71e6ba 95 for(i=0;i<=100;i++)
nightseas 0:633cef71e6ba 96 {
nightseas 0:633cef71e6ba 97 led_mb = 1;
nightseas 0:633cef71e6ba 98 wait_us(j);
nightseas 0:633cef71e6ba 99 led_mb = 0;
nightseas 0:633cef71e6ba 100 wait_us(100-j);
nightseas 0:633cef71e6ba 101 }
nightseas 0:633cef71e6ba 102 }
nightseas 0:633cef71e6ba 103 for(j=100;j>=0;j--)
nightseas 0:633cef71e6ba 104 {
nightseas 0:633cef71e6ba 105 for(i=0;i<=100;i++)
nightseas 0:633cef71e6ba 106 {
nightseas 0:633cef71e6ba 107 led_mb = 1;
nightseas 0:633cef71e6ba 108 wait_us(j);
nightseas 0:633cef71e6ba 109 led_mb = 0;
nightseas 0:633cef71e6ba 110 wait_us(100-j);
nightseas 0:633cef71e6ba 111 }
nightseas 0:633cef71e6ba 112 }
nightseas 0:633cef71e6ba 113 wait_ms(200);
nightseas 0:633cef71e6ba 114 }
nightseas 1:a6bcf44b90df 115 }
nightseas 1:a6bcf44b90df 116 #endif