Sungwoo Kim
/
HydraulicControlBoard_PostLIGHT_210420
LIGHT2
Diff: main.cpp
- Revision:
- 1:e04e563be5ce
- Parent:
- 0:51c43836c1d7
- Child:
- 2:a1c0a37df760
diff -r 51c43836c1d7 -r e04e563be5ce main.cpp --- a/main.cpp Wed Aug 14 08:13:36 2019 +0000 +++ b/main.cpp Mon Aug 19 08:05:09 2019 +0000 @@ -39,70 +39,20 @@ } -Timer t; +//Timer t; //t.start(); //t.stop(); //pc.printf("The time taken was %f seconds\n",t.read()); int a1; -int i=0; -float y; - -extern "C" void TIM4_IRQHandler(void) -{ - if (TIM4->SR & TIM_SR_UIF ) { -// y=0.05*sin(i*0.00001); -// y= 0.1; -// if (i>10000){i=0;} -// y=0.01*i/100000; - y=-0.04683; - // -// dtc_w = 0.1; -// dtc_v = 1; - // - - //PIN_V dir - - if (y>0) { - dtc_v=0; - dtc_w=y; - } else { - dtc_v=0; - dtc_w=-y; - } - 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); -// check = 0; - } - TIM4->SR = 0x0; // reset the status register -} - - +float PWM_out; int main() { - + /******************************************************* + *** Initialization + ********************************************************/ + + pc.baud(9600); // i2c init // i2c.frequency(400 * 1000); // 0.4 mHz // wait_ms(2); // Power Up wait @@ -128,6 +78,11 @@ // spi _ enc spi_enc_set_init(); msg.len=2; + + + /******************************************************* + *** Program is operating! + ********************************************************/ while(1) { // dac_1=0.5; // dac_2=0.1; @@ -140,11 +95,74 @@ //spi _ enc int a = spi_enc_read(); // read_field(i2c_slave_addr1); - pc.printf("%d\n",a1); + pc.printf("7 \n"); // msg.data[0]=0xFF&a1; // msg.data[1]=0xFF&(a1>>8); // can.write(msg); check_2=0; // wait(0.00005f); } +} + +unsigned int CNT_TMR4 = 0; +extern "C" void TIM4_IRQHandler(void) +{ + if (TIM4->SR & TIM_SR_UIF ) { + /******************************************************* + *** Sensor Read & Data Handling + ********************************************************/ + + //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; + + /******************************************************* + *** Valve Control + ********************************************************/ + +// PWM_out=-0.04683; + PWM_out=-0.95; + + if (PWM_out>0) { + dtc_v=0; + dtc_w=PWM_out; + } else { + dtc_v=0; + dtc_w=-PWM_out; + } + + //pwm + TIM4->CCR2 = (PWM_ARR)*(1.0f-dtc_v); + TIM4->CCR1 = (PWM_ARR)*(1.0f-dtc_w); + + /******************************************************* + *** Data Send (CAN) + ********************************************************/ + + + + + /******************************************************* + *** Timer Counting & etc. + ********************************************************/ + if(CNT_TMR4 == 100000) CNT_TMR4 = 0; + else CNT_TMR4++; + + } + TIM4->SR = 0x0; // reset the status register } \ No newline at end of file