int main (void) { char msg[30]; unsigned char c; int i=0; int counter[3]; ioinit(); //initTimer(); initTimer2(); initPWM(); initLCD(); //initPWM(); USART_Transmit_String("Restarting..\r\n"); wait(10); //LCD_gotoXY(1,0); //LCD_Write("Out-PWM-BC1"); while (1) { unsigned int en, en1; asm("nop"); cli(); en = topup_timer2; en1 = timestamp[0]; sei(); sprintf(msg, "%04x,%04x", en, en1); USART_Transmit_String(msg); LCD_gotoXY(0,0); LCD_Write(msg); } return 0; }
void InitApp(void) { /* Setup analog functionality and port direction */ (PPSUnLock); TRISFbits.TRISF3 = 0; PORTFbits.RF3 = 1; PPSOutput(PPS_RP9, PPS_SCK1OUT); PPSOutput(PPS_RP8, PPS_SDO1); AD1PCFG = 0xFFFF; // Default all pins to digital AD1PCFGLbits.PCFG11 = 0; //Disable digital input on AN11 /* Initialize peripherals */ InitMatrixDisplay(); spi1Init(PRI_PRESCAL_1_1); initHD44780LCD(); initPWM(); initADC(); }
void init_motors() { //setup reset line SET_DDR_PIN_OUTPUT(DDRB, PIN0); //set motor output pins DDRB |= (1<<PINB1)|(1<<PINB2); DDRD |= (1<<PIND5)|(1<<PIND6); configure_motor(&(motors[0]),0,PORTB,PINB1,M1_IDLE_SPEED, M1_OFFSET); configure_motor(&(motors[1]),1,PORTB,PINB2,M2_IDLE_SPEED, M2_OFFSET); configure_motor(&(motors[2]),2,PORTD,PIND5,M3_IDLE_SPEED, M3_OFFSET); configure_motor(&(motors[3]),3,PORTD,PIND6,M4_IDLE_SPEED, M4_OFFSET); initPWM(); calibrate_motors(); //reset motors //MOTORS_OFF; //Reset the RC pulse to zero to simulate throttle low position /*for(int i = 0; i < nMOTORS; i++) { //writeVelocity(0,&(motors[i])); writePWMduty(0,&(motors[i])); }*/ //writePWMduty(0,&(motors[1])); //_delay_ms(50); //MOTORS_ON; }
void AlaLed::initPWM(byte pin) { byte *pins_ = (byte *)malloc(1); pins_[0] = pin; initPWM(1, pins_); }
void alarm() { initPWM(); OC1RS+=0x8F; int j=0; for (j=0;j<32*motor_position;j++) { PORTDCLR = 0x0010; PORTDSET = 0x0002; DelayMotor(); PORTDCLR = 0x0002; PORTDSET = 0x0004; DelayMotor(); PORTDCLR = 0x0004; PORTDSET = 0x0008; DelayMotor(); PORTDCLR = 0x0008; PORTDSET = 0x0010; DelayMotor(); } initTimer2(); start=0; first=1; alm=1; }
void init(void) { initLeds(); initTimer(); initPWM(); initSpi(); LIS302DL_Init(); }
void initilize_motor(){ LPC_PINCON->PINSEL3 |= (2 << 14); // Set pin P1.23 as PWM1.4 LPC_PINCON->PINSEL3 |= (2 << 16); // Set pin P1.23 as PWM1.5 initPWM(200); pwmEn(1); change_direction_withDegree(90,ServoMotors::Top_servo); change_direction_withDegree(90,ServoMotors::Base_servo); }
/* main function */ int main() { OSCSetPBDIV (OSC_PB_DIV_1); //configure PBDIV so PBCLK = SYSCLK initIntGlobal(); initPort(); initCN(); initPWM(); while (1); }
int main( void ) { uint16_t leftLightSensor = 0; uint16_t rightLightSensor = 0; char buffer0[5]; char buffer1[5]; initUSART(); initADC(); initPWM(); while ( 1 ) { /* Start ADC7 conversion */ leftLightSensor = readADC( 7 ); /* Convert 10-bit uint16_t adcValue to ASCII and store in buffer */ itoa( leftLightSensor, buffer0, 10 ); /* Print out leftLightSensor ADC Value */ printString( "ADC Channel 6 (Left CD Sensor): " ); printString( buffer0 ); printString( "\n\n" ); /* Start ADC6 conversion */ rightLightSensor = readADC( 6 ); /* Convert 10-bit uint16_t adcValue to ASCII and store in buffer */ itoa( rightLightSensor, buffer1, 10 ); /* Print out rightLightSensor ADC Value */ printString( "ADC Channel 7 (Right CD Sensor): " ); printString( buffer1 ); printString( "\n\n" ); /* Arch right if rightLightSensor reading is greater than leftLightSensor */ if ( ( rightLightSensor - 100 ) > leftLightSensor ) { leftwheel( 55, 1 ); rightwheel( 35 , 1 ); } /* Arch left if leftLightSensor reading is greater than rightLightSensor */ else if ( ( leftLightSensor - 100 ) > rightLightSensor ) { leftwheel( 35 , 1 ); rightwheel( 45, 1 ); } /* Go forward if both light sensors have the same reading */ else { leftwheel( 35 , 1 ); rightwheel( 35 , 1 ); } _delay_ms( 500 ); } }
void initMotor1(void) { motor1DirectionRegister |= _BV(motor1DirectionPin) ; motor1EnableRegister |= _BV(motor1EnablePin); motor1DirectionPort |= _BV(motor1DirectionPin); motor1EnablePort |= _BV(motor1EnablePin); initPWM(); }
void AlaLedRgb::initPWM(byte pinRed, byte pinGreen, byte pinBlue) { byte *pins_ = (byte *)malloc(3); pins_[0] = pinRed; pins_[1] = pinGreen; pins_[2] = pinBlue; initPWM(1, pins_); }
int main(void) { initDev(); initATD(); initPWM(); while (1){ } }
// create PWMDevice connected to Robovero host with given, channel, period and pulseWidth PWMDevice::PWMDevice(Robovero *host, unsigned int channel, unsigned int period, unsigned int pulse) { pwm_period = period; pwm_pulseWidth = pulse; robo_host = host; pwm_channel = channel; // initialize the device initPWM(); }
void wcycle_init () { initPins (); initClocks (); initFlash (); initUART (); initPWM (); initDHT (); wcycle_pwm_ctl (readFlash()); }
// Pass the list of servos, the list should be in PROGMEM space to save Flash RAM // The specified Timer must implement timer compare interrupts and, if so, it will // ise the timer compare channel A (if there is more than one) void toshibaTB6612FNG_2pin_Init(TOSHIBA_TB6612FNG_2pin_MOTOR_DRIVER* driver, uint32_t freq){ uint32_t deciHertz = 10 * freq; // Make sure each servo is set as an output for(int i= driver->num_motors-1;i>=0;i--){ TOSHIBA_TB6612FNG_2pin_MOTOR* motor = (TOSHIBA_TB6612FNG_2pin_MOTOR*)pgm_read_word(&driver->motors[i]); if(initPWM(motor->pwm1,deciHertz)){ if(initPWM(motor->pwm2, deciHertz)){ // Connect motor to driver motor->actuator.class = &c_motors; } } // Start off braking act_setSpeed(motor,DRIVE_SPEED_BRAKE); // Indicate the motor is connected act_setConnected(motor,TRUE); }
// create PWMDevice connected to Robovero host with the given channel PWMDevice::PWMDevice(Robovero *host, unsigned int channel) { // set the period and pulse width to nominal values pwm_period = 20000; // 20000us = 20ms = 50Hz pwm_pulseWidth = 1520; // 1520us = 1.5ms robo_host = host; pwm_channel = channel; // initialize the device initPWM(); }
void init(void){ TRISA = 0x00; TRISB = 0x00; TRISC = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; ADCON1 = 0x0f; initPWM(); }
int main(void) { initPWM(); initSpiSlave(); sei(); while(1) { OCR1A = data; } }
void initAll(){ SysTick_Config(SystemCoreClock / 1000); lcd_init(); lcd_home(); lcd_cls(); initPWM(PWM_TIME_PERIOD); setServoAngle(0,0); UARTInit(BAUD_RATE); ds1307Init(); eeprom_24aaInit(); eeprom24aaMemoryCheck(); initButtons(); }
void main(void) { /*Variable Definitions*/ struct DC_motor motorL, motorR; //declare two DC_motor structures motorL.power=0; motorL.direction=1; motorL.dutyLowByte=(unsigned char *)(&PDC1L); motorL.dutyHighByte=(unsigned char *)(&PDC1H); motorL.dir_pin=2; motorL.PWMperiod=PWMcycle; motorR.power=0; motorR.direction=1; motorR.dutyLowByte=(unsigned char *)(&PDC0L); motorR.dutyHighByte=(unsigned char *)(&PDC0H); motorR.dir_pin=0; motorR.PWMperiod=PWMcycle; struct DC_motor * m_L; struct DC_motor * m_R; m_L=&motorL; //setup pointer to left motor m_R=&motorR; //setup pointer to right motor /*Oscillator Setup*/ OSCCON = 0x72; //8MHz clock while (!OSCCONbits.IOFS); //wait until stable /*Setup Registers*/ TRISB = 0; initPWM(); //setup PWM registers while (1) { fullSpeedAhead(m_L,m_R); delay_s(1); stop(m_L,m_R); turnLeft(m_L,m_R); delay_s(1); stop(m_L,m_R); turnRight(m_L,m_R); delay_s(1); stop(m_L,m_R); backwards(m_L,m_R); delay_s(1); stop(m_L,m_R); } }
void init() { // Défaut toutes les pattes sont en entrée sauf PCD et PGC (qui sont concervés) TRISA = 0xFFFF; TRISB = TRISB | 0xFFFC; init_osc(); //__builtin_write_OSCCONL(OSCCON & ~(0x40)); // Débloquage des RPIN et RPOR initDebug(); UART_init_asser(); UART_init_xbee(); // initSharp(); initTimer(); initTimerEvite(); initPWM(); //__builtin_write_OSCCONL(OSCCON | 0x40); // Rebloquage des RPIN et RPOR }
// SangSpilling foregår ved å sette registerene A (X, Y) før en kaller opp interpreteren int main(int argc, char **argv) { if((fd_mem = open("/dev/mem", O_RDWR | O_SYNC)) == -1) { printf("Could not get /dev/mem\n"); return -1; } sid_kernel_timer = fopen("/dev/sid_timer", "r"); if (sid_kernel_timer == NULL) { printf("Could not get /dev/sid_timer\n"); return -1; } set_realtime(); printWelcome(); initGPIO(); initPWM(); // sjekk opp argv[1] if (argv[1]) { menu_init(argv[1]); } else { printf("Required parameter - top level directory not specified"); exit(1); } if (argc > 2) { int z = strtol(argv[2], NULL, 10); printf("LCD reinit %d\n", z); lcd_reinit(z, z); } else { lcd_init(); } while(1) { menu_run(); if (inputSidFile != NULL) { int32_t next = c64_play(); next = next * ((float) sh.hz / 1000000.0f); platform_usleep(next); } else { usleep(1000); } } }
int main(void) { char str[32]; int temp_ms, temp_sec; RCONbits.SWDTEN = 0; //disable Watch dog timer initPLL(); while (OSCCONbits.CF == 1); //check clock failed while (OSCCONbits.COSC != 0b011); // Wait for Clock switch to occur while (OSCCONbits.LOCK == 0); //check PLL locked T1_Initial(); PORTS_Test_Initial(); keypad_init(); ADC1_Initial(); initPWM(); InitializeLCM(); LATDbits.LATD11 = 1; /* turn the LCM back light */ int a; LCD_clear(); LCD_start(); delay200usX(2*5000); LCD_clear(); while (1) { /* PWM */ infoPWM(); a = keypad_task(); /* LCD_Cursor_New(0, 12); sprintf(str, "%d",a); putsLCD((unsigned char*)str); *//* if(a==1){P1DC1 = 749; } if(a==2){P1DC1 = 3124; } if(a==3){P1DC1 = 4999; } if(a==4){P1DC1 = 6249; } */ if(a==1){P1DC1 = 1499; } if(a==2){P1DC1 = 6249; } if(a==3){P1DC1 = 9999; } if(a==4){P1DC1 = 12499; } } }
int main(void){ // ----- Initialize ----- // uint16_t xaxis; //PC0 ADC VALUE uint16_t yaxis; //PC1 ADC VALUE DDRB |= (1 <<PB0)|(1<<PB5)|(1<<PB6)|(1<<PB7); PORTC |= (1<<PC2); //THUMBSTICK PIN PULLUP RESISTOR SET initUSART(); initADC(); initPWM(); OCR1B = VERT_MAX_POS; while(1){ xaxis = readADC(PC0); yaxis = readADC(PC1); //X-AXIS 360 DEGREE ROTATION if(xaxis == 514 || xaxis == 515) OCR1A = 1023; else if(xaxis < 514) OCR1A = 180; else OCR1A = rotateRight(xaxis); if(yaxis < 500 && OCR1B > VERT_MIN_POS){ if(yaxis >=300) OCR1B -=LOWSPEED; else if(yaxis >=100) OCR1B -=MEDIUMSPEED; else OCR1B -=HIGHSPEED; }else if(yaxis > 530 && OCR1B < VERT_MAX_POS){ if(yaxis <=700) OCR1B +=LOWSPEED; else if(yaxis <=900) OCR1B +=MEDIUMSPEED; else OCR1B +=HIGHSPEED; } _delay_ms(20); checkJButtonState(); } return(0); }
int main() { // Handle Ctrl-C quit signal(SIGINT, sig_handler); // Edison i2c bus is 6 mraa::I2c *i2c = new mraa::I2c(6); assert(i2c != NULL); initPWM(i2c); while (running) { // Alternate two locations with 2-sec delay setServoPosition(i2c, 0, 0.2); sleep(2.0); setServoPosition(i2c, 0, 0.8); sleep(2.0); } }
int main(void) { wdt_enable(WDTO_4S); // We don't want to hang. // Set up the outputs: DDRB |= _BV(PB5); // LED output on SCK pin DDRC |= _BV(PC5); // Compressor Relay DDRD |= _BV(PD7); // Fan Relay DDRB |= _BV(PB0); // Tank circulation pump Relay led(1); initADC(); initPWM(); resetInputBuffer(); muartInit(); mprintf(PSTR("#Power up!\n")); lcd_init(LCD_DISP_ON); led(0); setState(STATE_OFF); memcpy_P(parameters, (PGM_VOID_P)DEFAULT_PARAMETERS, sizeof(DEFAULT_PARAMETERS)); char frame = 0; updateDisplay(); while(1) { led(ledToggle); ledToggle = ledToggle ? 0 : 1; if ((frame & 15) == 0) { updateDisplay(); } pollInput(); updateStateMachine(); updatePWM(); //_delay_ms(10); wdt_reset(); frame++; } }
int main(void) { /** configure RP9 as output compare pin (PWM) **/ __builtin_write_OSCCONL(OSCCON & 0xBF); // unlock registers to configure PPS RPOR4bits.RP8R = 18; // configure RP9 as OC1 __builtin_write_OSCCONL(OSCCON | 0x40); // lock registers /** configure PWM (initPWM) -- enable timer 3, set period, duty, activate PWM **/ int period = 80; // calculate for desired period based on timer 3 freq int duty = period/2; // duty cycle of 50% initPWM(period, duty); // PWM initialization function int i; while(1) { } return (EXIT_SUCCESS); }
/** @brief The main top level init * * The main init function to be called from main.c before entering the main * loop. This function is simply a delegator to the finer grained special * purpose init functions. */ void init(){ ATOMIC_START(); /* Disable ALL interrupts while we configure the board ready for use */ initPLL(); /* Set up the PLL and use it */ initGPIO(); initPWM(); initADC(); initAllPagedRAM(); /* Copy table and config blocks of data from flash to the paged RAM blocks for fast data lookup */ initVariables(); /* Initialise the rest of the running variables etc */ initFlash(); /* TODO, finalise this */ initECTTimer(); /* TODO move this to inside config in an organised way. Set up the timer module and its various aspects */ // initPITTimer(); /* TODO ditto... */ initSCIStuff(); /* Setup the sci module(s) that we will use. */ initConfiguration(); /* TODO Set user/feature/config up here! */ #ifdef XGATE initXgate(); /* Fred is a legend, for good reason as of now */ #endif initInterrupts(); /* still last, reset timers, enable interrupts here TODO move this to inside config in an organised way. Set up the rest of the individual interrupts */ ATOMIC_END(); /* Re-enable any configured interrupts */ }
int main(void){ SYSTEMConfigPerformance(40000000); initTimer1(); initTimer3(); initPWM(); #ifdef PWM setPwm3(100); setPwm1(0); delayUs(100000); setPwm4(100); setPwm2(0); #endif #ifdef run initADC(); initLCD(); clearLCD(); writeLCD(0b00001111, 0, 50); // enableInterrupts(); disableInterrupts(); while(1){ clearLCD(); IFS0bits.AD1IF = 0; // reset adc thing while(AD1CON1bits.SSRC == 0 ); ADCBufferValue = ADC1BUF0; // get buffer value printVoltage(ADCBufferValue); delayUs(100000); // wait one second leftMotorForward(50); delayUs(100000); // wait one second delayUs(100000); // wait one second rightMotorForward(50); delayUs(100000); // wait one second } #endif return 0; }
int main (void) { // SYSTEMConfigPerformance(40000000); initTMR(); initLCD(); initADC(); initPWM(); int i; while(1) { if (IFS0bits.AD1IF == 1) { analogVal = ADC1BUF0; IFS0bits.AD1IF = 0; getAnalogVoltage(analogVal); } //moveCursorLCD(1,1); //printCharLCD('c'); //getAnalogVoltage(analogVal); } }