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 01:44:45 2015 +0000
Revision:
1:a6bcf44b90df
Parent:
0:633cef71e6ba
Child:
2:cff0fa966e58
Commit for project export

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