cocoa_STM_ver_BIPOLAR

Dependencies:   mbed FastPWM

Files at this revision

API Documentation at this revision

Comitter:
GiJeongKim
Date:
Tue Aug 20 12:35:26 2019 +0000
Parent:
0:51c43836c1d7
Commit message:
abc;

Changed in this revision

INIT_HW/INIT_HW.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
setting.h Show annotated file Show diff for this revision Revisions of this file
diff -r 51c43836c1d7 -r be9b2f6d39c2 INIT_HW/INIT_HW.cpp
--- a/INIT_HW/INIT_HW.cpp	Wed Aug 14 08:13:36 2019 +0000
+++ b/INIT_HW/INIT_HW.cpp	Tue Aug 20 12:35:26 2019 +0000
@@ -31,26 +31,31 @@
 
 void Init_PWM(){
 
-    RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;                         // enable TIM4 clock
-    FastPWM pwm_v(PIN_V);
-    FastPWM pwm_w(PIN_W);
+    RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;                         // enable TIM1 clock
+
+    FastPWM pwm_a(PIN_V);                                       // 단순히 핀 설정용 
+    FastPWM pwm_b(PIN_W);
     
      //ISR Setup     
     
-    NVIC_EnableIRQ(TIM4_IRQn);                         //Enable TIM4 IRQ
+    NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn);                         //Enable TIM1 IRQ
 
-    TIM4->DIER |= TIM_DIER_UIE;                                 // enable update interrupt
-    TIM4->CR1 = 0x40;                                           // CMS = 10, interrupt only when counting up // Center-aligned mode
-    TIM4->CR1 |= TIM_CR1_UDIS;
-    TIM4->CR1 |= TIM_CR1_ARPE;                                  // autoreload on, 
-    TIM4->RCR |= 0x001;                                         // update event once per up/down count of TIM4 
-    TIM4->EGR |= TIM_EGR_UG;
+    TIM1->DIER |= TIM_DIER_UIE;                                 // enable update interrupt
+    TIM1->CR1 = 0x40;                                           // CMS = 10, interrupt only when counting up // Center-aligned mode
+    TIM1->CR1 |= TIM_CR1_UDIS;
+    TIM1->CR1 |= TIM_CR1_ARPE;                                  // autoreload on, 
+    TIM1->RCR |= 0x001;                                         // update event once per up/down count of tim1 
+    TIM1->EGR |= TIM_EGR_UG;
+
+
  
     //PWM Setup
 
-    TIM4->PSC = 0x0;                                            // no prescaler, timer counts up in sync with the peripheral clock
-    TIM4->ARR = PWM_ARR;                                          // set auto reload, 40 khz
-    TIM4->CCER |= ~(TIM_CCER_CC1NP);                            // Interupt when low side is on.
-    TIM4->CR1 |= TIM_CR1_CEN;                                   // enable TIM4
+    TIM1->PSC = 0x0;                                            // no prescaler, timer counts up in sync with the peripheral clock
+    TIM1->ARR = PWM_ARR;                                          // set auto reload, 40 khz
+//    TIM1->CCER |= ~(TIM_CCER_CC1NP);                            // Interupt when low side is on.
+    TIM1->CR1 |= TIM_CR1_CEN;                                   // enable TIM1
     
-}
+    // for complementary 
+    TIM1->CCER|=0b1111;
+    }
\ No newline at end of file
diff -r 51c43836c1d7 -r be9b2f6d39c2 main.cpp
--- a/main.cpp	Wed Aug 14 08:13:36 2019 +0000
+++ b/main.cpp	Tue Aug 20 12:35:26 2019 +0000
@@ -10,13 +10,16 @@
 DigitalOut check_2(PC_3);
 AnalogOut dac_1(PA_4);
 AnalogOut dac_2(PA_5);
+DigitalIn a(PB_7);
+DigitalIn b(PB_6);
+DigitalIn c(PA_6);
+DigitalIn d(PC_9);
 
 // pwm
-float dtc_v=0;
-float dtc_w=0;
+float dtc=0;
 
 // I2C
-I2C i2c(PC_9,PA_8); // SDA, SCL (for K22F)
+I2C i2c(PB_3,PB_10); // SDA, SCL (for K22F)
 const int i2c_slave_addr1 =  0x56;
 unsigned int value; // 10bit output of reading sensor AS5510
 
@@ -47,9 +50,9 @@
 int i=0;
 float y;
 
-extern "C" void TIM4_IRQHandler(void)
+extern "C" void TIM1_UP_TIM10_IRQHandler(void)
 {
-    if (TIM4->SR & TIM_SR_UIF ) {
+    if (TIM1->SR & TIM_SR_UIF ) {
 //        y=0.05*sin(i*0.00001);
 //        y= 0.1;
 //        if (i>10000){i=0;}
@@ -61,41 +64,19 @@
         //
         
         //PIN_V dir
-        
-        if (y>0) {
-            dtc_v=0;
-            dtc_w=y;
-        } else {
-            dtc_v=0;
-            dtc_w=-y;
-        }
+        dtc=0.5;
         i++;
-//    check = 1;
-//    //spi
-//    eeprom.write(0xff);
-//    eeprom.write(0xff);
-////    ready();
-////    read(1);
-//    //i2c
-////    read_field(i2c_slave_addr1);
         //ADC
         ADC1->CR2  |= 0x40000000;                        // adc _ 12bit
 //      a1=ADC1->DR;
 //    a1=ADC2->DR;
         a1=ADC3->DR;
-//    //계산
-//    //
-//    //
-//
-//    //DAC
-//    dac_1 = ADC1->DR;
-//    dac_2 = ADC2->DR;
+
 //    //pwm
-        TIM4->CCR2 = (PWM_ARR)*(1.0f-dtc_v);
-        TIM4->CCR1 = (PWM_ARR)*(1.0f-dtc_w);
+        TIM1->CCR1 = (PWM_ARR)*(1.0f-dtc);
 //    check = 0;
     }
-    TIM4->SR = 0x0;  // reset the status register
+    TIM1->SR = 0x0;  // reset the status register
 }
 
 
@@ -103,43 +84,14 @@
 int main()
 {
 
-    // i2c init
-//    i2c.frequency(400 * 1000);          // 0.4 mHz
-//    wait_ms(2);                         // Power Up wait
-//    look_for_hardware_i2c();            // Hardware present
-//    init_as5510(i2c_slave_addr1);
-//    // spi init
-    eeprom.format(8,3);
-    eeprom.frequency(5000000); //5M
-    enc.format(8,0);
-    enc.frequency(5000000); //5M
     // ADC init
     Init_ADC();
     // Pwm init
     Init_PWM();
-    TIM4->CR1 ^= TIM_CR1_UDIS;
-//    //SPI
-//    spi_eeprom_ready();
-//    spi_eeprom_write(0x1,0x112);
-//    spi_eeprom_ready();
-//    int i = spi_eeprom_read(0x1);
+    TIM1->CR1 ^= TIM_CR1_UDIS;
     // CAN
     can.attach(&onMsgReceived);
-    // spi _ enc
-    spi_enc_set_init();
-    msg.len=2;
     while(1) {
-//        dac_1=0.5;
-//        dac_2=0.1;
-        check_2 = 1;
-        //spi _ eeprom
-//        spi_eeprom_ready();
-//        spi_eeprom_write(0x0001,0xFFFFFFFF);
-//        spi_eeprom_ready();
-//        int a=spi_eeprom_read(0x0001);
-        //spi _ enc
-        int a = spi_enc_read();
-//        read_field(i2c_slave_addr1);
         pc.printf("%d\n",a1);
 //        msg.data[0]=0xFF&a1;
 //        msg.data[1]=0xFF&(a1>>8);
diff -r 51c43836c1d7 -r be9b2f6d39c2 setting.h
--- a/setting.h	Wed Aug 14 08:13:36 2019 +0000
+++ b/setting.h	Tue Aug 20 12:35:26 2019 +0000
@@ -7,12 +7,11 @@
 extern AnalogOut dac_2;
 
 // pwm 
-#define PIN_V PB_7
-#define PIN_W PB_6
+#define PIN_V PA_8
+#define PIN_W PA_7
 //#define PWM_ARR 0x465  // loop 80k, pwm 40k 
 #define PWM_ARR 0x8CA    // loop 40k, pwm 20k
-extern float dtc_v;
-extern float dtc_w;
+extern float dtc;
 
 // I2C
 extern I2C i2c; // SDA, SCL (for K22F)