Dependencies:   mbed-rtos mbed

Fork of rtos-test by Ryuichiro Ohira

Committer:
machines94
Date:
Sat May 14 21:15:12 2016 +0000
Revision:
1:ae213d6a0adf
Electromobility 2016
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
machines94 1:ae213d6a0adf 1 #include "bldc.h"
machines94 1:ae213d6a0adf 2 #include "quad_core.h"
machines94 1:ae213d6a0adf 3 bldc::bldc(I2C* i2c, int addr) {
machines94 1:ae213d6a0adf 4 this->_i2c = new i2c_helper(i2c, addr);
machines94 1:ae213d6a0adf 5 init_cmd();
machines94 1:ae213d6a0adf 6 }
machines94 1:ae213d6a0adf 7
machines94 1:ae213d6a0adf 8 void bldc::duty(char dutyMSB, char dutyLSB) {
machines94 1:ae213d6a0adf 9 this->_i2c->write_message( CODE_DUTY, dutyMSB, dutyLSB, this->cmd);
machines94 1:ae213d6a0adf 10 }
machines94 1:ae213d6a0adf 11
machines94 1:ae213d6a0adf 12 void bldc::init_cmd() {
machines94 1:ae213d6a0adf 13 unsigned short duty = 15; // 0 - 150
machines94 1:ae213d6a0adf 14
machines94 1:ae213d6a0adf 15 unsigned short freq = 11000; // 11 kHz
machines94 1:ae213d6a0adf 16 char direction = 0; // nu intereseaza
machines94 1:ae213d6a0adf 17 unsigned short speed = 20; // freq comutatie intre faze
machines94 1:ae213d6a0adf 18
machines94 1:ae213d6a0adf 19 cmd[0] = speed >> 8;
machines94 1:ae213d6a0adf 20 cmd[1] = speed;
machines94 1:ae213d6a0adf 21
machines94 1:ae213d6a0adf 22 cmd[2] = (char) duty >> 8;
machines94 1:ae213d6a0adf 23 cmd[3] = (char) duty;
machines94 1:ae213d6a0adf 24
machines94 1:ae213d6a0adf 25 cmd[4] = freq >>8;
machines94 1:ae213d6a0adf 26 cmd[5] = freq;
machines94 1:ae213d6a0adf 27
machines94 1:ae213d6a0adf 28 cmd[6] = direction;
machines94 1:ae213d6a0adf 29 }
machines94 1:ae213d6a0adf 30
machines94 1:ae213d6a0adf 31 bldc::~bldc() {
machines94 1:ae213d6a0adf 32 delete this->_i2c;
machines94 1:ae213d6a0adf 33 }