#include const uint8_t sinTable[128] = {255,255,255,255,254,254,254,253,253,252,251,250,250,249,248, 246,245,244,243,241,240,238,237,235,234,232,230,228,226,224, 222,220,218,215,213,211,208,206,203,201,198,196,193,190,188, 185,182,179,176,173,170,167,165,162,158,155,152,149,146,143, 140,137,134,131,128,124,121,118,115,112,109,106,103,100,97, 93,90,88,85,82,79,76,73,70,67,65,62,59,57,54,52,49,47,44,42, 40,37,35,33,31,29,27,25,23,21,20,18,17,15,14,12,11,10,9,7,6, 5,5,4,3,2,2,1,1,1,0,0,0}; volatile uint8_t timerTicked = 0; uint8_t buttonState = 0; uint32_t sinus(const uint8_t index) { // Avoid timing difference between conditions const uint8_t rIndex = 255 - index; if (index < 128) { return sinTable[index]; } else { return sinTable[rIndex]; } // else } // sinus CY_ISR(timerTick_Handler) { timerTicked = 1; } // ISR int main() { uint32_t a; CyGlobalIntEnable; /* Enable global interrupts. */ timerTick_StartEx(timerTick_Handler); Timer_1_Start(); for(;;) { if (timerTicked) { if (Button_Pin_Read() != buttonState) { // There are only two possibilities, so... buttonState = !buttonState; if (buttonState) { IDAC_1_Stop(); } else { IDAC_1_Start(); } // else timerTicked = 0; } // if } // if (timerTicked) for (a = 0; a < 256; a++) { IDAC_1_SetValue(sinus(a)); CyDelayUs(5); } // for } } // main