Create a gist now

Instantly share code, notes, and snippets.

motor sample 16motor
#include <project.h>
uint8 tick;
uint8 sin_table[] = {100,101,102,104,105,106,107,109,110,111,112,113,115,116,117,118,119,120,121,122,124,125,126,127,128,129,130,131,132,133,134,134,135,136,137,138,139,139,140,141,142,142,143,144,144,145,145,146,146,147,147,147,148,148,149,149,149,149,149,150,150,150,150,150,150,150,150,150,150,150,149,149,149,149,149,148,148,147,147,147,146,146,145,145,144,144,143,142,142,141,140,139,139,138,137,136,135,134,134,133,132,131,130,129,128,127,126,125,124,122,121,120,119,118,117,116,115,113,112,111,110,109,107,106,105,104,102,101,100,99,98,96,95,94,93,91,90,89,88,87,85,84,83,82,81,80,79,78,76,75,74,73,72,71,70,69,68,67,66,66,65,64,63,62,61,61,60,59,58,58,57,56,56,55,55,54,54,53,53,53,52,52,51,51,51,51,51,50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,51,52,52,53,53,53,54,54,55,55,56,56,57,58,58,59,60,61,61,62,63,64,65,66,66,67,68,69,70,71,72,73,74,75,76,78,79,80,81,82,83,84,85,87,88,89,90,91,93,94,95,96,98,99
};
void SysTick_Handler(){
tick++;
Control_Reg_1_Write(1);
Control_Reg_1_Write(0);
PWM_1_WriteCompare1(sin_table[tick]);
PWM_1_WriteCompare2(sin_table[(uint8)(tick+16)]);
PWM_2_WriteCompare1(sin_table[(uint8)(tick+32)]);
PWM_2_WriteCompare2(sin_table[(uint8)(tick+48)]);
PWM_3_WriteCompare1(sin_table[(uint8)(tick+64)]);
PWM_3_WriteCompare2(sin_table[(uint8)(tick+80)]);
PWM_4_WriteCompare1(sin_table[(uint8)(tick+96)]);
PWM_4_WriteCompare2(sin_table[(uint8)(tick+112)]);
PWM_5_WriteCompare1(sin_table[(uint8)(tick+128)]);
PWM_5_WriteCompare2(sin_table[(uint8)(tick+144)]);
PWM_6_WriteCompare1(sin_table[(uint8)(tick+160)]);
PWM_6_WriteCompare2(sin_table[(uint8)(tick+176)]);
PWM_7_WriteCompare1(sin_table[(uint8)(tick+192)]);
PWM_7_WriteCompare2(sin_table[(uint8)(tick+208)]);
PWM_8_WriteCompare1(sin_table[(uint8)(tick+224)]);
PWM_8_WriteCompare2(sin_table[(uint8)(tick+240)]);
PWM_1_Start();
PWM_2_Start();
PWM_3_Start();
PWM_4_Start();
PWM_5_Start();
PWM_6_Start();
PWM_7_Start();
PWM_8_Start();
}
int main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
CyIntSetSysVector(15,SysTick_Handler);
// 20msecごとに割り込み
if (SysTick_Config( (24000000) / 50)) {
while (1); /* Capture error */
}
CyGlobalIntEnable; /* Enable global interrupts. */
for(;;)
{
/* Place your application code here. */
}
}
/* [] END OF FILE */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment