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.
Driver.cpp
00001 #include "DRIVER.hpp" 00002 00003 int Counter_max = 100; 00004 int Counter = 0;//Value for counting the steps in the sine wave 00005 float Sine_vector[100]; 00006 float Returned_Duty_cycle = 0; 00007 #define PI 3.141592653 00008 #define Duty_Cycle_Scaling 1; 00009 //Constructor 00010 00011 DRIVER::DRIVER(PinName N1, PinName N2, PinName N3, PinName N4) : _Pwm_Output(N1),_Control_Pin(N2),_Hall_Effect_Sensor(N3),_Coil_Feedback(N4) 00012 { 00013 _Pwm_Output.period(0.02f);//Period of 20ms for 50Hz 00014 _Pwm_Output.write(0.0f);//Duty cycle of 0 for initialisation 00015 } 00016 DRIVER::~DRIVER(){} //Destructor 00017 00018 00019 //Core Functions 00020 void DRIVER::Test(){printf("Testing driver code\n");} 00021 00022 void DRIVER::Sine_Lookup_Table_Generator() 00023 { 00024 for(int vector_count = 0; vector_count <= Counter_max; vector_count ++) 00025 { 00026 if(vector_count <= (Counter_max/2))//First half 00027 { 00028 Sine_vector[vector_count] = (int)sin(2.0*PI*(float)vector_count/Counter_max); 00029 }else if(vector_count > (Counter_max/2)){ //Second half 00030 Sine_vector[vector_count] = (1.0+sin(2.0*PI*vector_count/Counter_max)); 00031 } 00032 } 00033 } 00034 00035 void DRIVER::Output_Sine_Wave() 00036 { 00037 if(Counter < (Counter_max/2))//First half 00038 { 00039 _Control_Pin = 0; //Control 1 line low 00040 } 00041 else if(Counter > (Counter_max/2)) //Second half 00042 { 00043 _Control_Pin = 1; //Control 1 line high 00044 } 00045 Returned_Duty_cycle = Sine_vector[Counter]; 00046 _Pwm_Output.write(Returned_Duty_cycle); 00047 //returned_duty_cycle = Sine_generator(Counter);//Return the next value to be set in the duty cycle 00048 Counter = Counter +1 ;//Increment Counter 00049 //printf("Counter Value is :%d\n",Counter); 00050 if(Counter == Counter_max)//Reset Statement for when the entire sine wave is completed. 00051 { 00052 Counter = 0;//Reset the counter 00053 } 00054 } 00055 00056 //Setter Functions 00057 //void DRIVER::Set_Pwm_Output(float Period, float Duty_Cycle){_Pwm_Output.period(Period); _Pwm_Output.write(Duty_Cycle);} 00058 void DRIVER::Set_Control_Pin(bool Control_Pin){_Control_Pin = Control_Pin;} 00059 //Getter Functions 00060 float DRIVER::Get_Hall_Effect_Sensor_Value(){return _Hall_Effect_Sensor;} 00061 float DRIVER::Get_Coil_Feedback_Value(){return _Coil_Feedback;}
Generated on Fri Jul 22 2022 04:09:08 by
1.7.2