stm32duino/Arduino_Tools

two output channels for PWM inverted problem

paolss opened this issue · 1 comments

Hi I know this is not a place probabbly to rise question like this but cant find answer nowhere....
Basically I want two PWM outputs to be shifted with some dead-time between.. but i just cant set two pwm channels to output at same time. Here is my arduino script for STM32F103CT
#define pin PA0
#define pin2 PA1

#define POT_IN PA4
int PotValue4;
int VB;
int dutyCycle;

//TIM_TypeDef *Instance = TIM1;
//TIM_TypeDef *Instance2 = TIM2;
TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(pin), PinMap_PWM);
uint32_t channel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(pin), PinMap_PWM));
HardwareTimer *MyTim = new HardwareTimer(Instance);

TIM_TypeDef *Instance2 = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(pin2), PinMap_PWM);
uint32_t channel2 = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(pin2), PinMap_PWM));
HardwareTimer *MyTim2 = new HardwareTimer(Instance2);

void Update_IT_callback(void)
{
//float VB = analogRead(POT_IN);
//MyTim->setOverflow(100000, MICROSEC_FORMAT);
//Serial.println("UITC");
}
void Update_IT_callback2(void)
{
//float VB = analogRead(POT_IN);
//MyTim->setOverflow(100000, MICROSEC_FORMAT);
//Serial.println("UITC");
}
void Compare_IT_callback(void)
{
VB = analogRead(POT_IN);
Serial.println(VB);
dutyCycle = map(VB, 0, 900, 50, 10);
//Serial.println(dutyCycle);
//MyTim->setOverflow(dutyCycle, MICROSEC_FORMAT);
MyTim->setCaptureCompare(channel, dutyCycle, PERCENT_COMPARE_FORMAT);
//Serial.println("CITC");
}

void Compare_IT_callback2(void)
{
VB = analogRead(POT_IN);
Serial.println(VB);
dutyCycle = map(VB, 0, 900, 50, 10);
//Serial.println(dutyCycle);
//MyTim->setOverflow(dutyCycle, MICROSEC_FORMAT);
MyTim->setCaptureCompare(channel, dutyCycle, PERCENT_COMPARE_FORMAT);
//Serial.println("CITC");
}
void setup()
{
while(!Serial);
Serial.begin(115200);

delay(2000);
Serial.println("STM32F103C blink and serial test");

pinMode(POT_IN, INPUT);
PotValue4 = analogRead(PA4);

MyTim->setMode(channel, TIMER_OUTPUT_COMPARE_PWM1, pin);
MyTim->setOverflow(100000, HERTZ_FORMAT); // 100000 microseconds = 100 milliseconds
MyTim->setCaptureCompare(channel, 50, PERCENT_COMPARE_FORMAT); // 50%
//MyTim->attachInterrupt(Update_IT_callback);
MyTim->attachInterrupt(channel, Compare_IT_callback);

MyTim2->setMode(channel2, TIMER_OUTPUT_COMPARE_PWM1, pin2);
MyTim2->setOverflow(100000, HERTZ_FORMAT); // 100000 microseconds = 100 milliseconds
MyTim2->setCaptureCompare(channel2, 50, PERCENT_COMPARE_FORMAT); // 50%
//MyTim2->attachInterrupt(Update_IT_callback2);
MyTim2->attachInterrupt(channel, Compare_IT_callback2);

MyTim->resume();

}

void loop()
{
//Serial.println(VB);
}

Hi, it is not the right place to get support. This repository is for tools used by STM32 core.
You should ask to the forum: https://www.stm32duino.com