int main(void) { sleep(5); init_PWM(); FILE *fd; char *data; while(1) { data = malloc(50); fd = fopen("/dev/shm/setariweb", "r"); if(fd < 0) { perror("Settings file open error"); exit(1); } fread(data, 1, 50, fd); data_get(data); if(activ) { release_door(); sleep(5); //at least 5 seconds between feedings } else { usleep(100000); //sleep to avoid massive cpu usage } fclose(fd); free(data); } return 0; }
int main( void ) { int i; uart_init(9600); init_gpio(); init_PWM(); tss_init(); __enable_interrupts(); for( i=0; i<DELAY; i++) ; uart_putstr( "Initialization Complete\r\n" ); // wait for user to press a key uart_putstr( "Press any key:" ); uart_getchar(); TSI0_DATA |= TSI_DATA_SWTS_MASK; while( 1 ) { uart_putnum( tss_pin9, 5 ); // 2^16 = 65536 = 5 digits uart_putstr( "\t" ); uart_putnum( tss_pin10, 5 ); // 2^16 = 65536 = 5 digits uart_putstr( "\r\n" ); for( i=0; i<DELAY; i++); } return 0; }
int main(void) { init_PM(); init_LCD(); init_Potentiometer(); init_CurrentSensor(); init_INTC(); fill_Display(); set_Velocidad(velocidad); set_Direccion(direccion); init_PWM(velocidad,direccion); while (1) { adc_start(&AVR32_ADC); adc_value_pot = adc_get_value(&AVR32_ADC,EXAMPLE_ADC_POTENTIOMETER_CHANNEL); adc_start(&AVR32_ADC); adc_value_current = adc_get_value(&AVR32_ADC,3); set_Duty_Cycle(adc_value_pot); set_Current(adc_value_current); if(bandera ==1){ set_Velocidad(velocidad); set_Direccion(direccion); update_PWM(velocidad, direccion); } delay_ms(400); }//WHILE }//MAIN
//------------------------- void servo_buka(){ //Assignment variabel PWM UNLOCKREG(); SYSCLK->PWRCON.XTL12M_EN=1; DrvSYS_Delay(5000); // Waiting for 12M Xtal stalble SYSCLK->CLKSEL0.HCLK_S=0; LOCKREG(); //init_LCD(); //clear_LCD(); // PWM_No = PWM channel number // PWM_CLKSRC_SEL = 0: 12M, 1:32K, 2:HCLK, 3:22M // PWM_PreScaler : PWM clock is divided by (PreScaler + 1) // PWM_ClockDivider = 0: 1/2, 1: 1/4, 2: 1/8, 3: 1/16, 4: 1 init_PWM(0, 0, 130, 4); // initialize PWM0(GPA12) to output 1MHz square wave Clock = 12000000; PreScaler = 130; ClockDivider = 1; Frequency = 50; //hitime = SERVO_HITIME_MIN; //-------------------------------------- //----------Kodingan inti microservo //hitime=hitime + (SERVO_HITIME_MAX - SERVO_HITIME_MIN)/10; hitime = 125; if (hitime>SERVO_HITIME_MAX) hitime = SERVO_HITIME_MIN; //PWM_FreqOut = PWM_Clock / (PWM_PreScaler + 1) / PWM_ClockDivider / (PWM_CNR + 1) CNR = Clock / Frequency / (PreScaler + 1) / ClockDivider - 1; // Duty Cycle = (CMR0+1) / (CNR0+1) CMR = hitime - 1; //CMR = 20; PWM_Out(0, CNR, CMR); }
int main() { uint8_t refTemp = 30; // reference uint8_t check, prev_check = 0; short up = 1, down = 1; uint16_t adc_in; // ADC value uint8_t temp = 1; // real temperature init_controller(); init_PWM(); lcd_init(); sei(); // turn on interrupts lcd_clrscr(); lcd_puts("Spinning"); Delay_s(2); // 2 seconds delay init_ADC(); refTemp = eeprom_read_byte((uint8_t*)0); if (!(refTemp >= TMIN && refTemp <= TMAX)) refTemp = 30; while(1) { if (C_CHECKBIT(Minus_REF)) down = 0; if (C_CHECKBIT(Minus_REF) == 0 && down ==0) { down = 1; if (refTemp > TMIN) refTemp--; } if (C_CHECKBIT(Plus_REF)) up = 0; if (C_CHECKBIT(Plus_REF) == 0 && up ==0) { up = 1; if (refTemp < TMAX) refTemp++; } eeprom_write_byte ((uint8_t *)0, refTemp); adc_in = ReadADC(0); temp = adc_in/2; lcd_puts2("T%d-R%dC", temp, refTemp); if ((temp - refTemp) > TOL) check = 3; else if ((refTemp - temp) > TOL) check = 1; else check = 2; switch(check) { case 1: if (prev_check == 1) break; setDutyCycle1(); prev_check = 1; break; case 2: if (prev_check == 2) break; setDutyCycle2(); prev_check = 2; break; case 3: if (prev_check == 3) break; setDutyCycle3(); prev_check = 3; break; } } return 1; }
void init_linear_actuator(){ init_PWM(); init_CWCCW(); init_LS(); detect_LS_Timers=xTimerCreate("Detect limit Switch state Polling",( DETECT_LS_POLLING_PERIOD), pdTRUE, ( void * ) 1, detect_LS_Polling); xTimerStart( detect_LS_Timers, 0 ); }
bool BoardSupportPackage::init() { bool result = false; SysTick_Config(SystemCoreClock/BSP_TICKS_PER_SECOND); initRCC(); initGPIO_Power(); initGPIO_Fan(); init_DHT11(); init_SPI(); init_TIM(); init_PWM(); screenInit(); result = true; return result; }
/*! \brief Initializes all configuration variables. */ void Configuration::init() { // MISC Oscillator_Freq = 16000000; //Oscillator frequency in Hz CPUCLK = Oscillator_Freq; PBACLK = Oscillator_Freq; PWMCLK = Oscillator_Freq; ADCCLK = Oscillator_Freq; init_Timer(); init_PWM(); init_Motor(); init_Sensors(); init_UART(); init_StatusLEDs(); }
inline void init(){ // Global initializations uartComms.init(); init_PWM(); init_ADC(); rprintfInit(uartSendByte); // DEBUGprint init // init_DEBUGprint(); // rprintf("*I\n"); // Wait for Eeprom to become available eeprom_busy_wait(); startupDiagnostics(); }
int main(void) { init_PORT(); init_TIMER0(); init_TIMER(); init_EX_INTERRUPT(); init_ADC(); init_USART(); init_PWM(); sei(); while(1) { if(state>3) state = 3; } return 0; }
void main(void){ StateType *Pt; unsigned char sensor; //Set pointer at STRAIGHT Pt = STRAIGHT; //Initialize PWM and Ports init_PWM( ); init_Ports( ); init_PJ7( ); EnableInterrupts; for(;;) { //Only run for 2 laps if(lapCount <= 2) { //Adjust motor every time interval if(adjustMotor == 1) { //Check PT0-PT2 for sensors sensor = PORTA & 0x05; //Move to next state via sensor input Pt = Pt->Next[sensor]; //Set motor output based on state PWMDTY3 = Pt->PWMduty3 ; PWMDTY1 = Pt->PWMduty1 ; //Reset adjust flag adjustMotor == 0; } } else { //Turn off motors PWME = 0x00; } } }
int main() { init_board(); LED_TRIS = 0; blink(100000L, 10, 0); init_timer(512); init_PWM(); init_ADC(6); init_spi_slave(); spi_slave_set_handle_message(link_board_handle_message); TRISFbits.TRISF5 = 0; while(1) { blink(10000L, 1, 1); } }
void wykonaj (int ile_petli, int dlugosc) { int licznik=0; char ch_liczba[3]; pozycjonowanie(); _delay_ms(500); relay_on(); _delay_ms(50); init_LCD(); init_PWM(); _delay_ms(200); int delay = 370; if(dlugosc>MIN_DLUGOSC) delay = delay + (dlugosc-MIN_DLUGOSC)*190; for (licznik=0; licznik<ile_petli; licznik++) { int do_konca = ile_petli-licznik; gen_char(ch_liczba, &do_konca); //wyswietla ile cykli pozostało do konca naswietlania wyswietl_LCD(ch_liczba); kierunek(PRZOD); _delay_ms(delay); //odleglosc dokad dojadą lampy stop(); _delay_ms(2000); pozycjonowanie(); //jezdie do tylu az napotka krancowe _delay_ms(2000); } _delay_ms(1000); wyswietl_LCD("KONIEC PRACY"); _delay_ms(1000); relay_off(); beep(); }
int main(void) { ubBufferIndex = 0; ubLastBufferIndex = 0; init_Osc(); init_PWM(); // PWM Setup init_ADC(); // ADC Setup init_DAC_Comparators(); init_T1(); TRISBbits.TRISB4 = 0; //RB4 as output TRISBbits.TRISB6 = 1; TRISBbits.TRISB7 = 1; // PTCONbits.PTEN = 1; // Enable the PWM // ADCONbits.ADON = 1; // Enable the ADC uiHeaderZeroCount = 0; IEC0bits.T1IE = 1; // uc_Main_Case_Index = 0; while(1) { }; }
int main() { init_LCD(); init_Relay(); init_Switch(); init_Buzzer(); init_LCD(); init_PWM(); sei(); while(1) { stop(); int ile_petli = 0; //wartosc zadana przez uzytkownika int dlugosc = 0; int wait = TAK; wyswietl_LCD("Start -> OK"); _delay_ms(200); wait = TAK; while(wait) if(bit_is_clear(PIN_SWITCH, SWITCH_OK)) wait = NIE; dlugosc = get_distance(); ile_petli = ilosc_petli(); wykonaj(ile_petli, dlugosc); _delay_ms(200); } }
void motor_init() { init_PWM(); }
int sound_tick(int state){ switch(state){ case st_sound_start: state = st_sound_init; break; case st_sound_init: state = st_sound_idle; break; case st_sound_idle: if(!QueueIsEmpty(sound_command_queue)){ if(sound_command_queue->buffer[sound_command_queue->front] == snd_locked){ state = st_sound_lock1; } else if(sound_command_queue->buffer[sound_command_queue->front] == snd_unlocked){ state = st_sound_unlock1; } else if(sound_command_queue->buffer[sound_command_queue->front] == snd_malfunction){ state = st_sound_malfunction1; } QueueDequeue(sound_command_queue); } else { state = st_sound_idle; } break; case st_sound_lock1: state = st_sound_lock2; break; case st_sound_lock2: state = st_sound_lock3; break; case st_sound_lock3: state = st_sound_lock4; break; case st_sound_lock4: state = st_sound_idle; break; case st_sound_unlock1: state = st_sound_unlock2; break; case st_sound_unlock2: state = st_sound_idle; break; case st_sound_malfunction1: state = st_sound_malfunction2; break; case st_sound_malfunction2: state = st_sound_malfunction3; break; case st_sound_malfunction3: state = st_sound_malfunction4; break; case st_sound_malfunction4: if(!QueueIsEmpty(sound_command_queue)){ state = st_sound_idle; } else { state = st_sound_malfunction1; } break; default: state = st_sound_start; break; } switch(state){ case st_sound_init: init_PWM(); break; case st_sound_lock1: set_PWM(3135.96); break; case st_sound_lock2: set_PWM(0); break; case st_sound_lock3: set_PWM(3135.96); break; case st_sound_lock4: set_PWM(0); break; case st_sound_unlock1: set_PWM(3135.96); break; case st_sound_unlock2: set_PWM(0); break; case st_sound_malfunction1: set_PWM(130.81); PORTD |= 0x02; break; case st_sound_malfunction3: set_PWM(0); PORTD &= 0xFD; break; default: break; } return state; }
void init_actuators(void){ (*IOp_DO).port=0; init_PWM(); // V3 board init_DAC(); }