Commit ad0bd0a9 authored by Jake Read's avatar Jake Read

pwm cycles working

parent 48d5c0f7
......@@ -11,6 +11,7 @@ Power is bussed to the board with two M3 Screw Terminals. The board includes roo
## Notes
- label lights
- wants one lo-side debug pin!
- might have to go to DRV8320 - newer, available
- CSD88548 is CSD88599 but more amps less volts, use these
......
This diff is collapsed.
......@@ -5485,93 +5485,6 @@ high speed (Philips)</description>
<pinref part="U1" gate="G$1" pin="PA0/AREF"/>
</segment>
</net>
<net name="PWMLO2" class="0">
<segment>
<pinref part="U2" gate="G$1" pin="INL_B"/>
<wire x1="78.74" y1="20.32" x2="60.96" y2="20.32" width="0.1524" layer="91"/>
<label x="60.96" y="20.32" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC2/RXD0"/>
<wire x1="-50.8" y1="66.04" x2="-33.02" y2="66.04" width="0.1524" layer="91"/>
<label x="-48.26" y="66.04" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMLO3" class="0">
<segment>
<pinref part="U2" gate="G$1" pin="INL_C"/>
<wire x1="78.74" y1="15.24" x2="60.96" y2="15.24" width="0.1524" layer="91"/>
<label x="60.96" y="15.24" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC0/SDA"/>
<wire x1="-50.8" y1="71.12" x2="-33.02" y2="71.12" width="0.1524" layer="91"/>
<label x="-48.26" y="71.12" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMLO1" class="0">
<segment>
<pinref part="U2" gate="G$1" pin="INL_A"/>
<wire x1="78.74" y1="25.4" x2="60.96" y2="25.4" width="0.1524" layer="91"/>
<label x="60.96" y="25.4" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC4/SS"/>
<wire x1="-50.8" y1="60.96" x2="-33.02" y2="60.96" width="0.1524" layer="91"/>
<label x="-48.26" y="60.96" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMHI3" class="0">
<segment>
<pinref part="U2" gate="G$1" pin="INH_C"/>
<wire x1="78.74" y1="17.78" x2="60.96" y2="17.78" width="0.1524" layer="91"/>
<label x="60.96" y="17.78" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="J13" gate="G$1" pin="4"/>
<wire x1="40.64" y1="101.6" x2="27.94" y2="101.6" width="0.1524" layer="91"/>
<label x="27.94" y="101.6" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC1/SCL/XCK0"/>
<wire x1="-50.8" y1="68.58" x2="-33.02" y2="68.58" width="0.1524" layer="91"/>
<label x="-48.26" y="68.58" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMHI1" class="0">
<segment>
<pinref part="U2" gate="G$1" pin="INH_A"/>
<wire x1="78.74" y1="27.94" x2="60.96" y2="27.94" width="0.1524" layer="91"/>
<label x="60.96" y="27.94" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="J13" gate="G$1" pin="2"/>
<wire x1="40.64" y1="106.68" x2="27.94" y2="106.68" width="0.1524" layer="91"/>
<label x="27.94" y="106.68" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC5/XCK1/MOSI"/>
<wire x1="-50.8" y1="58.42" x2="-33.02" y2="58.42" width="0.1524" layer="91"/>
<label x="-48.26" y="58.42" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMHI2" class="0">
<segment>
<pinref part="U2" gate="G$1" pin="INH_B"/>
<wire x1="78.74" y1="22.86" x2="60.96" y2="22.86" width="0.1524" layer="91"/>
<label x="60.96" y="22.86" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="J13" gate="G$1" pin="3"/>
<wire x1="40.64" y1="104.14" x2="27.94" y2="104.14" width="0.1524" layer="91"/>
<label x="27.94" y="104.14" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC3/TXD0"/>
<wire x1="-50.8" y1="63.5" x2="-33.02" y2="63.5" width="0.1524" layer="91"/>
<label x="-48.26" y="63.5" size="1.778" layer="95"/>
</segment>
</net>
<net name="V-W" class="0">
<segment>
<pinref part="R37" gate="G$1" pin="2"/>
......@@ -5980,6 +5893,93 @@ high speed (Philips)</description>
<label x="60.96" y="30.48" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMHIU" class="0">
<segment>
<pinref part="U2" gate="G$1" pin="INH_A"/>
<wire x1="78.74" y1="27.94" x2="60.96" y2="27.94" width="0.1524" layer="91"/>
<label x="60.96" y="27.94" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC5/XCK1/MOSI"/>
<wire x1="-50.8" y1="58.42" x2="-33.02" y2="58.42" width="0.1524" layer="91"/>
<label x="-48.26" y="58.42" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="J13" gate="G$1" pin="2"/>
<wire x1="40.64" y1="106.68" x2="27.94" y2="106.68" width="0.1524" layer="91"/>
<label x="27.94" y="106.68" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMLOU" class="0">
<segment>
<pinref part="U2" gate="G$1" pin="INL_A"/>
<wire x1="78.74" y1="25.4" x2="60.96" y2="25.4" width="0.1524" layer="91"/>
<label x="60.96" y="25.4" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC4/SS"/>
<wire x1="-50.8" y1="60.96" x2="-33.02" y2="60.96" width="0.1524" layer="91"/>
<label x="-48.26" y="60.96" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMHIV" class="0">
<segment>
<pinref part="J13" gate="G$1" pin="3"/>
<wire x1="40.64" y1="104.14" x2="27.94" y2="104.14" width="0.1524" layer="91"/>
<label x="27.94" y="104.14" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC3/TXD0"/>
<wire x1="-50.8" y1="63.5" x2="-33.02" y2="63.5" width="0.1524" layer="91"/>
<label x="-48.26" y="63.5" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U2" gate="G$1" pin="INH_B"/>
<wire x1="78.74" y1="22.86" x2="60.96" y2="22.86" width="0.1524" layer="91"/>
<label x="60.96" y="22.86" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMHIW" class="0">
<segment>
<pinref part="J13" gate="G$1" pin="4"/>
<wire x1="40.64" y1="101.6" x2="27.94" y2="101.6" width="0.1524" layer="91"/>
<label x="27.94" y="101.6" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U1" gate="G$1" pin="PC1/SCL/XCK0"/>
<wire x1="-50.8" y1="68.58" x2="-33.02" y2="68.58" width="0.1524" layer="91"/>
<label x="-48.26" y="68.58" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U2" gate="G$1" pin="INH_C"/>
<wire x1="78.74" y1="17.78" x2="60.96" y2="17.78" width="0.1524" layer="91"/>
<label x="60.96" y="17.78" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMLOV" class="0">
<segment>
<pinref part="U1" gate="G$1" pin="PC2/RXD0"/>
<wire x1="-50.8" y1="66.04" x2="-33.02" y2="66.04" width="0.1524" layer="91"/>
<label x="-48.26" y="66.04" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U2" gate="G$1" pin="INL_B"/>
<wire x1="78.74" y1="20.32" x2="60.96" y2="20.32" width="0.1524" layer="91"/>
<label x="60.96" y="20.32" size="1.778" layer="95"/>
</segment>
</net>
<net name="PWMLOW" class="0">
<segment>
<pinref part="U1" gate="G$1" pin="PC0/SDA"/>
<wire x1="-50.8" y1="71.12" x2="-33.02" y2="71.12" width="0.1524" layer="91"/>
<label x="-48.26" y="71.12" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="U2" gate="G$1" pin="INL_C"/>
<wire x1="78.74" y1="15.24" x2="60.96" y2="15.24" width="0.1524" layer="91"/>
<label x="60.96" y="15.24" size="1.778" layer="95"/>
</segment>
</net>
</nets>
</sheet>
</sheets>
......
......@@ -10,3 +10,14 @@ Firmware for the xmega is under development, but you can see [firmware notes for
To get spindles spinning with only a wee amount of c-programming time, I'm going to write a dirty/nasty/simple commutation scheme.
## 3-Channel Hi / Lo Side PWM with AWeX
XMega has some built in functionality for motor / h-bridge drive, namely the AWeX (waveform extension) module that runs on top of the timer/counter system (which runs PWM).
This is set-up in the code, and I've verified I have the write outputs writing to the right outputs (haha). Nice.
![pwm](images/pwms-awex-init-xmega.png)
## 6-Step Commutation
To do this quickly, I'm just going to yoke a timer to a blind 6-step commutation cycle.
\ No newline at end of file
......@@ -59,10 +59,20 @@ pin_t drvDcCal;
pin_t drvFault;
pin_t drvOCTW;
// pwm pins
pin_t lo1;
pin_t hi1;
pin_t lo2;
pin_t hi2;
pin_t lo3;
pin_t hi3;
// controller functions
// bldc_t bldc;
unsigned long timebase;
pin_t tstpin1;
pin_t tstpin2;
#endif /* HARDWARE_H_ */
\ No newline at end of file
......@@ -48,36 +48,82 @@ void encoder_init(void){
spi_start(&spiEncoder, 0);
}
void drv_init(void){
void pwm_periods(uint16_t peru, uint16_t perv, uint16_t perw){
// check overrun
(peru > 1024) ? peru = 1024 : (0);
(perv > 1024) ? perv = 1024 : (0);
(perw > 1024) ? perw = 1024 : (0);
// hi is lo, per xmega, let's undo this
peru = 1024 - peru;
perv = 1024 - perv;
perw = 1024 - perw;
// A: 3, B: 2, C: 1 - channels to board
TCC0.CCABUFL = (uint8_t) perw;
TCC0.CCABUFH = (uint8_t) (perw >> 8);
TCC0.CCBBUFL = (uint8_t) perv;
TCC0.CCBBUFH = (uint8_t) (perv >> 8);
TCC0.CCCBUFL = (uint8_t) peru;
TCC0.CCCBUFH = (uint8_t) (peru >> 8);
}
void pwm_init(void){
//
// setup awex etc
pin_init(&lo1, &PORTC, PIN4_bm, 4, 1);
pin_init(&hi1, &PORTC, PIN5_bm, 5, 1);
pin_init(&lo2, &PORTC, PIN2_bm, 2, 1);
pin_init(&hi2, &PORTC, PIN3_bm, 3, 1);
pin_init(&lo3, &PORTC, PIN0_bm, 0, 1);
pin_init(&hi3, &PORTC, PIN1_bm, 1, 1);
// compare and capture at value
uint16_t per = 1024; // at DIV1, 1024 period is 23.5kHz
// write low first, bc bussing / xmega 8-bit oddities cc datasheet @ 3.11
uint8_t perl = (uint8_t) per;
uint8_t perh = (uint8_t) (per >> 8);
TCC0.CTRLA = TC_CLKSEL_DIV1_gc;
TCC0.PERBUFL = perl;
TCC0.PERBUFH = perh;
// turnt to dual-slope pwm to have center aligned, and eventually sampling on top event
TCC0.CTRLB = TC_WGMODE_DS_T_gc;// | (1 << 7) | (1 << 6) | (1 << 5); // dual slope, and enable channels a, b, c for capture
AWEXC.CTRL = AWEX_DTICCAEN_bm | AWEX_DTICCBEN_bm | AWEX_DTICCCEN_bm;
AWEXC.DTBOTHBUF = 4; // four counts of pwm clock for deadtime
AWEXC.OUTOVEN = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5);
pwm_periods(256, 512, 768);
}
void drv_init(void){
}
void tickers_init(void){
// one 'ticker' to execute steps
// turn on TCC0, do perclk / 8
TCC0.CTRLA = TC_CLKSEL_DIV256_gc;
// sets up two timers
// compare and capture at value
uint16_t pera = 40; // ~ 200us timer to start...
uint16_t pera = 1200;
// write low first, bc bussing / xmega 8-bit oddities cc datasheet @ 3.11
uint8_t peral = (uint8_t) pera;
uint8_t perah = (uint8_t) (pera >> 8);
TCC0.PERBUFL = peral;
TCC0.PERBUFH = perah;
// turn on TCC0
TCD0.CTRLA = TC_CLKSEL_DIV256_gc;
TCD0.PERBUFL = peral;
TCD0.PERBUFH = perah;
// set cca interrupt on
TCC0.INTCTRLA = TC_OVFINTLVL_HI_gc;
TCD0.INTCTRLA = TC_OVFINTLVL_HI_gc;
// another ticker to execute accel
TCC1.CTRLA = TC_CLKSEL_DIV256_gc;
TCC1.PERBUFL = peral;
TCC1.PERBUFH = perah;
TCD1.CTRLA = TC_CLKSEL_DIV256_gc;
TCD1.PERBUFL = peral;
TCD1.PERBUFH = perah;
TCC1.INTCTRLA = TC_OVFINTLVL_HI_gc;
TCD1.INTCTRLA = TC_OVFINTLVL_HI_gc;
}
int main(void)
......@@ -95,8 +141,13 @@ int main(void)
pin_set(&stlerr);
pin_set(&stlclk);
//pin_init(&tstpin1, &PORTC, PIN5_bm, 5, 1);
//pin_init(&tstpin2, &PORTC, PIN3_bm, 3, 1);
tickers_init();
pwm_init();
// runtime globals
uint32_t tck = 0;
......@@ -114,11 +165,16 @@ int main(void)
}
ISR(TCC0_OVF_vect){
//stepper_updatesteps(&stepper);
pin_toggle(&hi1);
}
ISR(TCD0_OVF_vect){
// commutate?
//pin_toggle(&tstpin1);
}
ISR(TCC1_OVF_vect){
//stepper_updateaccel(&stepper);
ISR(TCD1_OVF_vect){
//pin_toggle(&tstpin2);
}
ISR(USARTE1_RXC_vect){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment