![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
asdgas
Dependencies: mbed Eigen FastPWM
main.cpp
- Committer:
- jobuuu
- Date:
- 2019-08-19
- Revision:
- 1:e04e563be5ce
- Parent:
- 0:51c43836c1d7
- Child:
- 2:a1c0a37df760
File content as of revision 1:e04e563be5ce:
#include "mbed.h" #include "FastPWM.h" #include "INIT_HW.h" #include "SPI_EEP_ENC.h" #include "I2C_AS5510.h" #include "setting.h" // dac & check DigitalOut check(PC_2); DigitalOut check_2(PC_3); AnalogOut dac_1(PA_4); AnalogOut dac_2(PA_5); // pwm float dtc_v=0; float dtc_w=0; // I2C I2C i2c(PC_9,PA_8); // SDA, SCL (for K22F) const int i2c_slave_addr1 = 0x56; unsigned int value; // 10bit output of reading sensor AS5510 // SPI SPI eeprom(PB_15, PB_14, PB_13); // EEPROM //(SPI_MOSI, SPI_MISO, SPI_SCK); DigitalOut eeprom_cs(PB_12); SPI enc(PC_12,PC_11,PC_10); DigitalOut enc_cs(PD_2); // UART Serial pc(PA_9,PA_10); // _ UART //CAN CAN can(PB_8, PB_9, 1000000); CANMessage msg; void onMsgReceived() { can.read(msg); pc.printf("Message received: %d\n", msg.data[0]); } //Timer t; //t.start(); //t.stop(); //pc.printf("The time taken was %f seconds\n",t.read()); int a1; float PWM_out; int main() { /******************************************************* *** Initialization ********************************************************/ pc.baud(9600); // 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); // CAN can.attach(&onMsgReceived); // spi _ enc spi_enc_set_init(); msg.len=2; /******************************************************* *** Program is operating! ********************************************************/ 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("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 }