void mandelbrot (unsigned char *array) { double x=-2; double y=-2; int col; int row; int i; row = 0; i = 0; while(row < 512) { x=-2; col = 0; while(col<512){ if(stepCounter(x,y) >= MAX_ITERATION){ array[54 + i*3] = 0; array[54 + i*3 +1] = 0; array [54 + i*3 + 2] = 0; } else { array[54 + i*3] = 0; array[54 + i*3 +1] = stepCounter(x,y); array[54 + i*3 + 2] = stepCounter(x,y); } x+=(4.0/512); col++; i++; } printf("\n"); y+=(4.0/512); row++; } }
__attribute__ ((interrupt)) void Fabric_IRQHandler(void) { //previously void Timer1_IRQHandler( void ), using hardware timer now uint32_t time = MYTIMER_getCounterVal(); uint32_t status = MYTIMER_getInterrupt_status(); count--; // Holds next delay period. unsigned int new_step_delay; // Remember the last step delay used when accelerating. static int last_accel_delay; // Counting steps when moving. static unsigned int step_count = 0; // Keep track of remainder from new_step-delay calculation to increase accuracy static unsigned int rest = 0; //set pwm value here for acceleration change //MYTIMER_setCompareVal(srd.step_delay); MYTIMER_setOverflowVal(srd.step_delay); switch(srd.run_state) { case STOP: step_count = 0; rest = 0; MYTIMER_disable(); break; case ACCEL: /*if(!interupt_type) { stepCounter(srd.dir); interupt_type = 1; } else if(interupt_type) { uint32_t gpio_outputs = MSS_GPIO_get_outputs(); gpio_outputs &= ~( MSS_GPIO_0_MASK | MSS_GPIO_1_MASK | MSS_GPIO_2_MASK | MSS_GPIO_3_MASK ); MSS_GPIO_set_outputs( gpio_outputs ); interupt_type = 0; }*/ stepCounter(srd.dir); step_count++; srd.accel_count++; new_step_delay = srd.step_delay - (((2 * (int64_t)srd.step_delay) + rest)/(4 * srd.accel_count + 1)); rest = ((2 * (int64_t)srd.step_delay)+rest)%(4 * srd.accel_count + 1); // Check if we should start deceleration. if(step_count >= srd.decel_start) { srd.accel_count = srd.decel_val; srd.run_state = DECEL; } // Check if we hit max speed. else if(new_step_delay <= srd.min_delay) { last_accel_delay = new_step_delay; new_step_delay = srd.min_delay; rest = 0; srd.run_state = RUN; } break; case RUN: /*if(!interupt_type) { stepCounter(srd.dir); interupt_type = 1; } else if(interupt_type) { uint32_t gpio_outputs = MSS_GPIO_get_outputs(); gpio_outputs &= ~( MSS_GPIO_0_MASK | MSS_GPIO_1_MASK | MSS_GPIO_2_MASK | MSS_GPIO_3_MASK ); MSS_GPIO_set_outputs( gpio_outputs ); interupt_type = 0; }*/ stepCounter(srd.dir); step_count++; new_step_delay = srd.min_delay; // Check if we should start deceleration. if(step_count >= srd.decel_start) { srd.accel_count = srd.decel_val; // Start deceleration with same delay as accel ended with. new_step_delay = last_accel_delay; srd.run_state = DECEL; } break; case DECEL: /*if(!interupt_type) { stepCounter(srd.dir); interupt_type = 1; } else if(interupt_type) { uint32_t gpio_outputs = MSS_GPIO_get_outputs(); gpio_outputs &= ~( MSS_GPIO_0_MASK | MSS_GPIO_1_MASK | MSS_GPIO_2_MASK | MSS_GPIO_3_MASK ); MSS_GPIO_set_outputs( gpio_outputs ); interupt_type = 0; }*/ stepCounter(srd.dir); step_count++; srd.accel_count++; new_step_delay = srd.step_delay - (((2 * (int64_t)srd.step_delay) + rest)/(4 * srd.accel_count + 1)); rest = ((2 * (int64_t)srd.step_delay)+rest)%(4 * srd.accel_count + 1); // Check if we are at last step if(srd.accel_count >= 0){ srd.run_state = STOP; } break; } srd.step_delay = new_step_delay; NVIC_ClearPendingIRQ( Fabric_IRQn ); //MSS_TIM1_clear_irq(); }