Closed
Description
There are two bugs here, with regards to the SAMD/E implementation.
First of, the CCBUF, should not be fed with the channel number, but the wo association. I think, correct me if im wrong?
[Edit], I can see it is working with CCBUF and channel number. My mistake.
void writeSAMDDutyCycle(int chaninfo, float dc) {
uint8_t tccn = GetTCNumber(chaninfo);
uint8_t chan = GetTCChannelNumber(chaninfo);
if (tccn<TCC_INST_NUM) {
Tcc* tcc = (Tcc*)GetTC(chaninfo);
Serial.print("Setting PWM CCBUF to : ");
Serial.print(dc, 5);
Serial.print(" for channel : ");
Serial.println(chan); // Should be wo variable
// set via CCBUF
while (TCC1->SYNCBUSY.bit.CC0 > 0 );
tcc->CCBUF[chan].reg = (uint32_t)((SIMPLEFOC_SAMD_PWM_RESOLUTION-1) * dc); // TODO pwm frequency!
// tcc->STATUS.vec.CCBUFV |= (0x1<<chan);
// while ( tcc->SYNCBUSY.bit.STATUS > 0 );
// tcc->CTRLBSET.reg |= TCC_CTRLBSET_CMD(TCC_CTRLBSET_CMD_UPDATE_Val);
// while ( tcc->SYNCBUSY.bit.CTRLB > 0 );
}
else {
// Tc* tc = (Tc*)GetTC(chaninfo);
// //tc->COUNT16.CC[chan].reg = (uint32_t)((SIMPLEFOC_SAMD_PWM_RESOLUTION-1) * dc);
// tc->COUNT8.CC[chan].reg = (uint8_t)((SIMPLEFOC_SAMD_PWM_TC_RESOLUTION-1) * dc);
// while ( tc->COUNT8.STATUS.bit.SYNCBUSY == 1 );
}
}
Danger BUG!
The pwm multiplier, when running open_loop_velocity is around 0.5, no matter which voltage limit I set. This equals 50% duty cycle and potentially a fried controller or motor.
Metadata
Metadata
Assignees
Labels
No labels