int main(void) { TRISD = 0xF100; unsigned short ADCReadings[10000]; int i = 0; // initialize timers and SPI initTimers(); initspi(); TMR3 = 0; // Reset timer int duration = 6250; unsigned short sample; unsigned short received; initadc(2); // use channel 2 (AN2 is RB2) while (1) { while(TMR3 < duration){ // wait } sample = readadc(); PORTD = sample; TMR3 = 0; // reset timer if (i < 10000) { ADCReadings[i] = sample; i++; } // send data over SPI received = spi_send_receive(sample-300);//(sample-150); if (PORTDbits.RD8 == 1) { // we received a pulse! playNote(527, 5); } } }
int main() { TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); // If they are present, configure Vbus & Wake-up pins //PIO_InitializeInterrupts(0); //-------- Init parameters -------------- printf("INIT Parameters\n\r"); init_parameters(); //-------- Load parameters from Flash -------------- printf("Load parameters from Flash\n\r"); FLASH_LoadSettings(); //-------- Init UART -------------- printf("USB Seriel INIT\n\r"); samserial_init(); //-------- Init ADC without Autostart -------------- printf("Init ADC\n\r"); initadc(0); //-------- On USB recived byte call this function -------------- printf("Init Callback for USB\n\r"); samserial_setcallback(&usb_characterhandler); //-------- Init Motor driver -------------- printf("Init Motors\n\r"); motor_setup(); //-------- Init Heater I/O -------------- printf("Init Heaters\n\r"); heaters_setup(); //-------- Start SYSTICK (1ms) -------------- printf("Configuring systick.\n\r"); SysTick_Configure(1, BOARD_MCK/1000, SysTick_Handler); //-------- Timer 0 for Stepper -------------- printf("Init Stepper IO\n\r"); stepper_setup(); //Timer for Stepper //-------- Timer 0 for Stepper -------------- printf("Configuring Timer 0 Stepper\n\r"); ConfigureTc0_Stepper(); //Timer for Stepper //-------- Timer 1 for heater PWM -------------- printf("Configuring Timer 1 PWM.\n\r"); ConfigureTc_1(); //-------- Init Planner Values -------------- printf("Plan Init\n\r"); plan_init(); //-------- Check for SD card presence ------- // sdcard_handle_state(); //motor_enaxis(0,1); //motor_enaxis(1,1); while (1) { //uncomment to use//sprinter_mainloop(); //main loop events go here do_periodic(); if(buflen < (BUFSIZE-1)) get_command(); if(buflen > 0) { //-------- Check and execute G-CODE -------------- process_commands(); //-------- Increment G-Code FIFO -------------- buflen = (buflen-1); bufindr++; if(bufindr == BUFSIZE) bufindr = 0; } } }