Kim GiJeong
/
cocoa_STM_ver_BIPOLAR
cocoa_STM_ver_BIPOLAR
Diff: main.cpp
- Revision:
- 1:be9b2f6d39c2
- Parent:
- 0:51c43836c1d7
--- 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);