void main(void){ init_general();// Set general runtime configuration bits init_gpio_pins(); // Set all I/O pins to low outputs init_oscillator(0);// Initialize oscillator configuration bits init_timer2();// Initialize timer2 (millis) init_adc(NULL); // Initialize ADC module init_termination(NOT_TERMINATING); init_adcs();// Initialize all of the ADC's init_can(); // Initialize CAN canAnalogMillis = canDiagMillis = 0; ADCCON3bits.GSWTRG = 1; // Initial ADC Conversion? STI();// Enable interrupts while(1){ update_analog_channels(); strain_calc(); if(millis - canAnalogMillis >= CAN_ANALOG_INTV){ CANAnalogChannels(); canAnalogMillis = millis; } if(millis - canDiagMillis >= CAN_DIAG_INTV){ CANdiag(); canDiagMillis = millis; } sample_temp(); // Sample internal and external temperature sensors } }
int main(void) { Init_LED(); Init_Motor(); Init_UART5(9600); UART5_Send_String("hehehe"); init_timer(); init_timer2(); config_nvic(); Light_LED2; Light_LED3; gJiffies = 0; while (1) { if (0 <= gJiffies && gJiffies < 100) { //FORWARD; //ENABLE_MOTOR; Light_LED_Both; } else if (100 <= gJiffies && gJiffies < 200) { Dark_LED_Both; //DISABLE_MOTOR; //BACKWARD; } else if (gJiffies >= 200) gJiffies = 0; } }
u64 get_incr_only_count(void) { static u64 incr_cnt = 0; static u32 prev = 0; u32 now, diff; // init condition if (incr_cnt == 0) { init_timer2(); prev = read_u32_cnt(); incr_cnt = (u64) prev; return incr_cnt; } now = read_u32_cnt(); if (now > prev) { diff = now - prev; } else { diff = (0xffffffff - now) + prev + 1; } prev = now; incr_cnt += diff; return incr_cnt; }
static void init_HC_SR04() { init_gpio(); init_timer2(); servo_control_init(); init_usart(); }
void init_pwm(void) { APFCONbits.CCP2SEL = 0; //CCP2 is on RC1 TRISCbits.TRISC2 = 0; //CCP1 pin to output TRISCbits.TRISC1 = 0; //CCP2 pin to output TRISGbits.TRISG0 = 0; //CCP3 pin to output TRISGbits.TRISG3 = 0; //CCP4 pin to output TRISGbits.TRISG4 = 0; //CCP5 pin to output TRISEbits.TRISE6 = 0; //CCP6 pin to output TRISEbits.TRISE5 = 0; //CCP7 pin to output TRISEbits.TRISE4 = 0; //CCP8 pin to output TRISEbits.TRISE3 = 0; //CCP9 pin to output TRISEbits.TRISE2 = 0; //CCP10 pin to output CCP1CONbits.CCP1M = 0b1111; // set CCP1 as PWM mode CCP2CONbits.CCP2M = 0b1111; // set CCP2 as PWM mode CCP3CONbits.CCP3M = 0b1111; // set CCP3 as PWM mode CCP4CONbits.CCP4M = 0b1111; // set CCP4 as PWM mode CCP5CONbits.CCP5M = 0b1111; // set CCP5 as PWM mode CCP6CONbits.CCP6M = 0b1111; // set CCP6 as PWM mode CCP7CONbits.CCP7M = 0b1111; // set CCP7 as PWM mode CCP8CONbits.CCP8M = 0b1111; // set CCP8 as PWM mode CCP9CONbits.CCP9M = 0b1111; // set CCP9 as PWM mode CCP10CONbits.CCP10M = 0b1111; // set CCP10 as PWM mode CCPTMRS0 = 0b00000000; //set CCP4, CCP3, CCP2, CCP1 to reference Timer2 CCPTMRS1 = 0b00000000; //set CCP8, CCP7, CCP6, CCP5 to reference Timer2 CCPTMRS2 = 0b00000000; //set CCP10, CCP9 to reference Timer2 CCPR1 = 50; //set CCP1 Duty Cycle to 50% CCPR2 = 100; //set CCP1 Duty Cycle to 50% CCPR3 = 150; //set CCP1 Duty Cycle to 50% CCPR4 = 200; //set CCP1 Duty Cycle to 50% init_timer2(); init_timer0(); }
int main(void) { CLKPR = 0x80; CLKPR = 0x00; init_ports(); init_timer1(); init_timer2(); init_analog(); TWAR = 1 << 1; TWCR = 0x45; TWCR = (1 << TWEN) | (1 << TWIE) | (1 << TWEA); sei(); state = WAIT_ZCROSS; //state = TEST; while (1) { _delay_ms(10000); } clr_led(); cli(); boot_main(); }
//Initialize all the timers void InitTimers(void) { init_timer1(); init_timer2(); init_timer3(); init_timer4(); init_timer5(); }
void init(void) { DDRB |= (1<<PB1); DDRB &= ~(1<<PB0); PORTB |= (1<<PB0); init_timer1(); init_timer2(); sei(); dauer = tud[data+1]; }
int main ( void ) { uint16_t c = 0; //create a 16 bit storage variable init_stdusart0 (51, DB8 | P_N | SB1); //init usart0 for 19.2kBaud 8N1 (51 is the ubrr value for 19.2kBaud at 16 MHz) printf("AVR Timer2 Testing program\r"); init_timer2 (T2_PRESCALER_8, 32, T2_SOURCE_EXTERNAL); //init timer 2 with a prescaler of 8, a top of 32, and an external clock source on TOSC1 while (1) { //repeat forever c = get_timer2(); //store timer value printf("Current Value of Timer 2: %d\r", c); //print current value _delay_ms(250); //wait 1/4 of a second } return 0; }
int main(void){ init_general();// Set general runtime configuration bits init_gpio_pins();// Set all I/O pins to low outputs init_oscillator(0);// Initialize oscillator configuration bits init_timer2();// Initialize timer2 (millis) int i; while(1){ for(i = 0;i<1000000;i++); PIC_LED_LAT = 1; for(i = 0;i<1000000;i++); PIC_LED_LAT = 0; } return 0; }
void system_init() { GPIO_Digital_Output(&GPIOD_ODR, _GPIO_PINMASK_13); // Set CS pin as output GPIO_Digital_Output(&GPIOC_ODR, _GPIO_PINMASK_2); // Set RST pin as output GPIO_Digital_Output(&GPIOA_ODR, _GPIO_PINMASK_0); // Set PWM pin as output GPIO_Digital_Output(&GPIOA_ODR, _GPIO_PINMASK_4); // Set PWM pin as output // Initialize SPI SPI3_Init_Advanced( _SPI_FPCLK_DIV16, _SPI_MASTER | _SPI_8_BIT | _SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION | _SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1, &_GPIO_MODULE_SPI3_PC10_11_12); s7x10r_init(); init_timer2(); EnableInterrupts(); }
void InitApp(void) { /* Setup analog functionality and port direction */ //IO configuration (pull-up CN interrupts enable // IEC1bits.CNIE=1; // IPC4bits.CNIP=1; /* Initialize peripherals */ init_peripheral_pin_select(); uart1_Initialize(19200); init_timer2(); init_timer3(); init_SPI1(); init_SPI2(); }
int main(void) { init_uart_transmit(); init_timer2(); // Initialize ADC with clock frequency of 1/16th of sysclock (so 62.5 kHz) // A given ADC reading takes 13.5 cycles, so the ADC will sample at a rate of 4.6 kHz. Scope verified! init_adc(16); DDRD |= (1 << PD2); while(1) { // Implement go_to_sleep() here later on... PORTD &= ~(1 << PD2); } }
// Initialize all system peripherals static void system_init() { DisableInterrupts(); GPIO_Digital_Output( &GPIOD_BASE, _GPIO_PINMASK_13 ); /* SPI Init - NOTE* Magneto samples bits on the second clock transition */ SPI3_Init_Advanced( _SPI_FPCLK_DIV16, _SPI_MASTER | _SPI_8_BIT | _SPI_CLK_IDLE_LOW | _SPI_SECOND_CLK_EDGE_TRANSITION | _SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1, &_GPIO_MODULE_SPI3_PC10_11_12 ); // Initialize display tft_initialize(); // Start timer init_timer2(); // Initialize magneto and check for success or failure if( magneto_init( MAGNETO_SPI, 0, 1 ) ) return; }
int main() { stm32_NvicSetup (); Setup_Pll_As_Clock_System(); init_portA(); init_portB(); init_portC(); init_timer2(); init_timer4(); init_timer1(); Setup_Adc(); Adc_On(); init_timer3(); // STM32 setup //GPIOA->ODR |=0x0020; Recule_train_Arriere(); while(1) { } }
int main(void) { int8_t byte_str[4]; // Wird benutzt um hier ein Byte als String abzulegen // LCD Display intialisieren lcd_init(); // Startmeldung ausgeben show_start_message(); // Stepper Initialisieren init_stepper(); // Motor Initialisieren init_motor(); // Steursignale BYTE_READY, SYNC und SOE Initialisieren init_controll_signals(); // Schreibschutz setzen clear_wps(); // Timer0 --> GCR senden init_timer0(); // Tasten Initialisieren init_keys(); // Timer2 --> wird alle 1ms aufgerufen // z.B. zu Tasten entprellen init_timer2(); // Meldung ausgeben, das auf SD Karte gewartet wird lcd_setcursor(0,2); lcd_string("Wait for SD-Karte..."); // SD Karte initialisieren // Partition und Filesystem öffnen // Warten bis alles O.K. ist while(init_sd_card()){} lcd_clear(); view_dir_entry(0,&file_entry); #ifdef DEBUG_MODE lcd_setcursor(0,4); lcd_string("T:"); lcd_setcursor(5,4); lcd_string("M:"); lcd_setcursor(9,4); lcd_string("K:"); lcd_setcursor(2,4); sprintf(byte_str,"%d",akt_half_track >> 1); lcd_string(byte_str); #endif // Interrupts erlauben sei(); while(1) { // Auf Steppermotor aktivität prüfen // und auswerten if(stepper_signal_r_pos != stepper_signal_w_pos) { uint8_t stepper = stepper_signal_puffer[stepper_signal_r_pos++]>>2 | stepper_signal_puffer[stepper_signal_r_pos-1]; switch(stepper) { case 0x30: case 0x40: case 0x90: case 0xE0: // DEC stepper_dec(); stepper_signal_time = 0; stepper_signal = 1; break; case 0x10: case 0x60: case 0xB0: case 0xC0: // INC stepper_inc(); stepper_signal_time = 0; stepper_signal = 1; break; } #ifdef DEBUG_MODE lcd_setcursor(2,4); lcd_string(" "); lcd_setcursor(2,4); sprintf(byte_str,"%d",akt_half_track >> 1); lcd_string(byte_str); #endif } else if(stepper_signal && (stepper_signal_time >= STEPPER_DELAY_TIME))
int main(void) { /* Init */ int pump_timer = 0; int i = 0; uint16_t tzero = 0; DDRD = 0xff; // initialize port B for output LEDs PORTD = 0xff; // all LEDs initially OFF init_timer2(); initIO(); sei(); for (int j=0; j < NUM_CYCLES; j++) { /* Retain for testing: Use to test delay function */ //Delay(120); //while(1) PORTD=0; /* Retain for testing: use to cycle pressure read */ //while(1) //read_pressure(); read_pressure(); close_valve(); tzero = second; // start time for each section of test // 'second' is a global RTC variable /*---- Initial pump cycle ----*/ while ((second - tzero) < PUMP_TIME && pressure < MAX_HI_PRESS) { read_pressure(); start_pump(); if (pressure > (MAX_HI_PRESS + 200)) // overpressure while (error(1)); } stop_pump(); if (pressure < MAX_HI_PRESS) // error if target pressure no reached while (error(2)); /*---- Vacuum dwell starts here ----*/ tzero = second; while ((second - tzero) < DWELL_TIME) { read_pressure(); if (pressure > (MAX_HI_PRESS + 200)) //overpressure while (error(1)); if (pressure < MIN_HI_PRESS) { pump_timer = 0; while (pressure < MAX_HI_PRESS && ((second - tzero) < DWELL_TIME)) { start_pump(); read_pressure(); for (i=0; i<1000; i++) // 1 sec busy-wait delay_ms(1.0); pump_timer++; if (pump_timer >= 120) // don't run pump 120 seconds while (error(3)); if (pressure > (MAX_HI_PRESS + 200)) //overpressure while (error(1)); } stop_pump(); } } stop_pump(); /*---- Bleed cycle start ----*/ open_valve(); tzero = second; while ((second - tzero) < BLEED_TIME && pressure > MAX_LO_PRESS) read_pressure(); if (pressure > MAX_LO_PRESS) while (error(4)); /*---- Ambient pressure dwell ----*/ delay(DWELL_TIME); //lower = pressure & 0x00ff; //upper = (pressure & 0xff00)>>8; //PORTD = lower; //for (i=0; i<1000; i++) _delay_ms(1.0); //Delay(1); //PORTD = upper; //for (i=0; i<1000; i++) _delay_ms(1.0); //while(1); } while(1) // completed successfully without errors! error(0); return 0; }
int main(void) { /****************INITIALIZATIONS*******************/ //other stuff Im experimenting with for SoR uartInit(); // initialize the UART (serial port) uartSetBaudRate(0, 9600); // set UARTE speed, for Bluetooth uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it uartSetBaudRate(2, 57600); // set UARTH speed uartSetBaudRate(3, 57600); // set UARTJ speed, for Blackfin //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx) // initialize rprintf system and configure uart1 (USB) for rprintf rprintfInit(uart1SendByte); configure_ports(); // configure which ports are analog, digital, etc. LED_on(); rprintf("\r\nSystem Warming Up"); // initialize the timer system (comment out ones you don't want) init_timer0(TIMER_CLK_1024); init_timer1(TIMER_CLK_64); init_timer2(TIMER2_CLK_64); init_timer3(TIMER_CLK_64); init_timer4(TIMER_CLK_64); init_timer5(TIMER_CLK_1024); //timer5Init(); a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage int i = 0, j = 0; //let system stabelize for X time for(i=0;i<16;i++) { j=a2dConvert8bit(i);//read each ADC once to get it working accurately delay_cycles(5000); //keep LED on long enough to see Axon reseting rprintf("."); } LED_off(); rprintf("Initialization Complete \r\n"); reset_timer0(); reset_timer1(); reset_timer2(); reset_timer3(); reset_timer4(); reset_timer5(); while(1) { control(); delay_cycles(100); //an optional small delay to prevent crazy oscillations } return 0; }
void init_sensor() { init_porta(); init_timer2(); }
void prvSetupHardware(){ int i, j; //add 1.7s delay for potential power issues delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); uartInit(); // initialize the UART (serial port) uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it doesn't work uartSetBaudRate(2, 38400); // set UARTH speed uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx) rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf configure_ports(); // configure which ports are analog, digital, etc. LED_on(); //rprintf("\r\nSystem Warmed Up"); // initialize the timer system init_timer0(TIMER_CLK_1024); // init_timer1(TIMER_CLK_64); // Timer 1 is initialized by FreeRTOS init_timer2(TIMER2_CLK_64); init_timer3(TIMER_CLK_64); init_timer4(TIMER_CLK_64); init_timer5(TIMER_CLK_64); a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage //let system stabelize for X time for(i=0;i<16;i++) { j=a2dConvert8bit(i);//read each ADC once to get it working accurately delay_cycles(5000); //keep LED on long enough to see Axon reseting rprintf("."); } LED_off(); rprintf("Initialization Complete \r\n"); //reset all timers to zero reset_timer0(); reset_timer1(); reset_timer2(); reset_timer3(); reset_timer4(); reset_timer5(); /********PWM Setup***********/ prvPWMSetup(); }