Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of HHH_MOTOR_TRAP_Polled_TFM by
Revision 7:09d682fdd50e, committed 2021-05-28
- Comitter:
- simontruelove
- Date:
- Fri May 28 13:58:16 2021 +0000
- Parent:
- 6:7a2390be633e
- Commit message:
- 28/05/2021 Latest version of code. Runs happily at 48V 20A but Mosfet 1 usually overheats (potentially due to poor air flow)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Apr 27 07:26:22 2021 +0000
+++ b/main.cpp Fri May 28 13:58:16 2021 +0000
@@ -74,7 +74,7 @@
float OnDuty = 50; //OnDuty is changed by the velocity control loop.
float RPM = 100; //calculated RPM value
float Error = 1; //Error value used in control loop
-float SetPoint = 500; //Velocity Setpoint
+float SetPoint = 48; //Velocity Setpoint
int PWMPRESCALE = (12);
int ControlLoopActive = 0;
@@ -82,7 +82,7 @@
int main()
{
int RevCounter = 0;
- float X = ((float)12 * (float) 60); //used in speed calc, but put here so math is only done once
+ float X = ((float)240 / (float) 60); //used in speed calc, but put here so math is only done once
pc.baud(460800);
NVIC_SetVector(PWM1_IRQn, (uint32_t)&PWM1_IRQHandler); // set the interrupt vector for PWM
@@ -161,7 +161,7 @@
case 3:
Q2 = 0;
- Q4 = 1; //A sink, B supply, C float
+ Q4 = 1; //A sink, B float, C supply
Q6 = 1;
Q8 = 1;
Q10 = 1;
@@ -177,7 +177,7 @@
case 4:
Q2 = 1;
- Q4 = 1; //A sink, B supply, C float
+ Q4 = 1; //A supply, B float, C sink
Q6 = 1;
Q8 = 1;
Q10 = 0;
@@ -188,12 +188,12 @@
Info.Q5= OffDuty;
Info.Q7= OffDuty;
Info.Q9= OffDuty;
- Info.Q11= OffDuty;
+ Info.Q11= OffDuty;
break;
case 6:
Q2 = 1;
- Q4 = 1; //A sink, B supply, C float
+ Q4 = 1; //A supply, B sink, C float
Q6 = 0;
Q8 = 1;
Q10 = 1;
@@ -204,12 +204,12 @@
Info.Q5= OffDuty;
Info.Q7= OffDuty;
Info.Q9= OffDuty;
- Info.Q11= OffDuty;
+ Info.Q11= OffDuty;
break;
case 5:
Q2 = 1;
- Q4 = 1; //A sink, B supply, C float
+ Q4 = 1; //A float, B supply, C sink
Q6 = 1;
Q8 = 1;
Q10 = 0;
@@ -222,6 +222,7 @@
Info.Q9= OffDuty;
Info.Q11= OffDuty;
break;
+
}
SetPWM (Info.Q11,Info.Q9,Info.Q7,Info.Q5,Info.Q3,Info.Q1); //set the PWM values
@@ -232,7 +233,12 @@
if(OnDuty < 3)
OnDuty = 3;
-
+ if (SetPoint > 402)
+ SetPoint = 402;
+
+ if(SetPoint < 4)
+ SetPoint = 4;
+
if(ControlLoopActive == 1)
{
Error = (SetPoint - RPM);
@@ -275,10 +281,12 @@
switch(SerialIn)
{
case 'a':
- SetPoint = SetPoint + 10;
+ SetPoint = SetPoint + 6;
+ pc.printf("Setpoint = %f, \n\r",SetPoint) ;
break;
case 's':
- SetPoint = SetPoint - 10;
+ SetPoint = SetPoint - 6;
+ pc.printf("Setpoint = %f, \n\r",SetPoint) ;
break;
case 'z':
SwitchOverDelay = SwitchOverDelay + 1 ;
@@ -327,13 +335,17 @@
if(OnDuty>97)
OnDuty = 97;
break;
-
+
case 'k':
OnDuty = OnDuty - 1;
- if(OnDuty<4)
- OnDuty = 4;
+ if(OnDuty<3)
+ OnDuty = 3;
break;
+ case 'r':
+ pc.printf("%f \n\r",RPM) ;
+ break;
+
case 'o':
DisplayMenu();
break;
@@ -544,6 +556,7 @@
pc.printf("Press i to decrease PWM prescale\n\r");
pc.printf("Press j to increase PWM Duty\n\r");
pc.printf("Press k to decrease PWM Duty\n\r");
+pc.printf("Press r to display current RPM \n\r");
pc.printf("Press o to display this menu \n\r");
pc.printf("------\n\r");
}
