cocoa_STM_ver_BIPOLAR

Dependencies:   mbed FastPWM

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "FastPWM.h"
00003 #include "INIT_HW.h"
00004 #include "SPI_EEP_ENC.h"
00005 #include "I2C_AS5510.h"
00006 #include "setting.h"
00007 
00008 // dac & check
00009 DigitalOut check(PC_2);
00010 DigitalOut check_2(PC_3);
00011 AnalogOut dac_1(PA_4);
00012 AnalogOut dac_2(PA_5);
00013 DigitalIn a(PB_7);
00014 DigitalIn b(PB_6);
00015 DigitalIn c(PA_6);
00016 DigitalIn d(PC_9);
00017 
00018 // pwm
00019 float dtc=0;
00020 
00021 // I2C
00022 I2C i2c(PB_3,PB_10); // SDA, SCL (for K22F)
00023 const int i2c_slave_addr1 =  0x56;
00024 unsigned int value; // 10bit output of reading sensor AS5510
00025 
00026 // SPI
00027 SPI eeprom(PB_15, PB_14, PB_13); // EEPROM //(SPI_MOSI, SPI_MISO, SPI_SCK);
00028 DigitalOut eeprom_cs(PB_12);
00029 SPI enc(PC_12,PC_11,PC_10);
00030 DigitalOut enc_cs(PD_2);
00031 
00032 // UART
00033 Serial pc(PA_9,PA_10); //  _ UART
00034 
00035 //CAN
00036 CAN can(PB_8, PB_9, 1000000);
00037 CANMessage msg;
00038 void onMsgReceived()
00039 {
00040     can.read(msg);
00041     pc.printf("Message received: %d\n", msg.data[0]);
00042 }
00043 
00044 
00045 Timer t;
00046 //t.start();
00047 //t.stop();
00048 //pc.printf("The time taken was %f seconds\n",t.read());
00049 int a1;
00050 int i=0;
00051 float y;
00052 
00053 extern "C" void TIM1_UP_TIM10_IRQHandler(void)
00054 {
00055     if (TIM1->SR & TIM_SR_UIF ) {
00056 //        y=0.05*sin(i*0.00001);
00057 //        y= 0.1;
00058 //        if (i>10000){i=0;}
00059 //        y=0.01*i/100000;
00060         y=-0.04683;
00061         //
00062 //        dtc_w = 0.1;
00063 //        dtc_v = 1;
00064         //
00065         
00066         //PIN_V dir
00067         dtc=0.5;
00068         i++;
00069         //ADC
00070         ADC1->CR2  |= 0x40000000;                        // adc _ 12bit
00071 //      a1=ADC1->DR;
00072 //    a1=ADC2->DR;
00073         a1=ADC3->DR;
00074 
00075 //    //pwm
00076         TIM1->CCR1 = (PWM_ARR)*(1.0f-dtc);
00077 //    check = 0;
00078     }
00079     TIM1->SR = 0x0;  // reset the status register
00080 }
00081 
00082 
00083 
00084 int main()
00085 {
00086 
00087     // ADC init
00088     Init_ADC();
00089     // Pwm init
00090     Init_PWM();
00091     TIM1->CR1 ^= TIM_CR1_UDIS;
00092     // CAN
00093     can.attach(&onMsgReceived);
00094     while(1) {
00095         pc.printf("%d\n",a1);
00096 //        msg.data[0]=0xFF&a1;
00097 //        msg.data[1]=0xFF&(a1>>8);
00098 //        can.write(msg);
00099         check_2=0;
00100 //        wait(0.00005f);
00101     }
00102 }