void analogReference(uint8_t type) { if (type) { // internal reference requested if (!analog_reference_internal) { analog_reference_internal = 1; if (calibrating) { ADC0_SC3 = 0; // cancel cal #ifdef HAS_KINETIS_ADC1 ADC1_SC3 = 0; // cancel cal #endif } analog_init(); } } else { // vcc or external reference requested if (analog_reference_internal) { analog_reference_internal = 0; if (calibrating) { ADC0_SC3 = 0; // cancel cal #ifdef HAS_KINETIS_ADC1 ADC1_SC3 = 0; // cancel cal #endif } analog_init(); } } }
void in_update_analogs(void) { int *nubp[2] = { in_a1, in_a2 }; struct input_absinfo ainfo; int i, fd, v, ret; if (!analog_init_done) analog_init(); for (i = 0; i < 2; i++) { fd = fdnub[i]; if (fd < 0) continue; ret = ioctl(fd, EVIOCGABS(ABS_X), &ainfo); if (ret == -1) { perror("ioctl"); continue; } v = ainfo.value / 2 + 127; nubp[i][0] = v < 0 ? 0 : v; ret = ioctl(fd, EVIOCGABS(ABS_Y), &ainfo); if (ret == -1) { perror("ioctl"); continue; } v = ainfo.value / 2 + 127; nubp[i][1] = v < 0 ? 0 : v; } //printf("%4d %4d %4d %4d\n", in_a1[0], in_a1[1], in_a2[0], in_a2[1]); }
void line_init() { if (!(nibobee_initialization & NIBOBEE_ANALOG_INITIALIZED)) { analog_init(); } line_readPersistent(); activate_output_bit(IO_LINE_EN); }
void init(void) { // set up watchdog wd_init(); // set up serial serial_init(); // set up inputs and outputs io_init(); // set up timers timer_init(); // read PID settings from EEPROM heater_init(); // set up default feedrate current_position.F = startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z; // start up analog read interrupt loop, if anything uses analog as determined by ANALOG_MASK in your config.h analog_init(); // set up temperature inputs temp_init(); // enable interrupts sei(); // reset watchdog wd_reset(); // say hi to host serial_writestr_P(PSTR("Start\nok\n")); }
void analogReadRes(unsigned int bits) { unsigned int config; if (bits >= 13) { if (bits > 16) bits = 16; config = 16; } else if (bits >= 11) { config = 12; } else if (bits >= 9) { config = 10; } else { config = 8; } analog_right_shift = config - bits; if (config != analog_config_bits) { analog_config_bits = config; if (calibrating) { ADC0_SC3 = 0; // cancel cal #ifdef HAS_KINETIS_ADC1 ADC1_SC3 = 0; #endif } analog_init(); } }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); const GPoint center = grect_center_point(&bounds); //Load bitmap image background_layer = layer_create(bounds); layer_set_update_proc(background_layer, background_layer_update); layer_add_child(window_layer, background_layer); custom_font_text = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BOXY_TEXT_20)); custom_font_outline = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BOXY_OUTLINE_20)); //Add analog hands analog_init(my_window); // Render layer ontop for cool transparency render_layer = layer_create(bounds); layer_set_update_proc(render_layer, render_layer_update); layer_add_child(window_layer, render_layer); //Force time update time_t current_time = time(NULL); struct tm *current_tm = localtime(¤t_time); tick_handler(current_tm, MINUTE_UNIT | DAY_UNIT); //Setup tick time handler tick_timer_service_subscribe((MINUTE_UNIT), tick_handler); }
int main (void) { mode_pointer = &mode_time; //assigns the mode_pointer initially to time mode pwm_init(); timer_init(); analog_init(); pinchange_init(); power_register_init(); sei(); // global set enable interrupts while(1) { PRR &= ~(1<<PRADC); //turns on the ADC comparator PORTA |= (1<<MODE_SELECT_POWER); //turn on to power pot ADCSRA |= (1<<ADSC); // starts AtoD conversion by flipping ADC Start Conversion bit in AD Control and Status Register A while(ADCSRA & (1<<ADSC)); // loops while waiting for ADC to finish PORTA &= ~(1<<MODE_SELECT_POWER); //turn pot back off to conserve power PRR |= (1<<PRADC); //shuts down the ADC and comparator (*mode_pointer)(); //uses a pointer to call the function for the specific mode sleep_cpu(); //just hang out and wait for interrupts } return 1; }
void analogReference(uint8_t type) { if (type) { // internal reference requested if (!analog_reference_internal) { analog_reference_internal = 1; if (calibrating) ADC0_SC3 = 0; // cancel cal analog_init(); } } else { // vcc or external reference requested if (analog_reference_internal) { analog_reference_internal = 0; if (calibrating) ADC0_SC3 = 0; // cancel cal analog_init(); } } }
int main(void) { analogvalue_t delay; setup(); setup_timer0(); // setup_int0(); // display_off(&display); setup_timer2(); analog_init(&delay); potentiometer_read(&delay); display_set(&display, delay.v); display_on(&display, 1); /* if ((PIND & _BV(PIN_SW1)) == 0) */ /* pin = PIN_LED_RED; */ for (;;) { if ((PIND & _BV(PIN_BUTTON2)) == 0) { PORTB &= _BV(PIN_LED); } else { PORTB |= _BV(PIN_LED); } /* if ((PIND & _BV(PIN_SW1)) == 0) { long tmax = 1000L * delay.v; while (micros() - t0 < tmax) ; PORTD |= _BV(pin); } else { PORTD &= ~_BV(pin); enable_int0(); } if ((PIND & _BV(PIN_SW2)) == 0) { settle_on_low(&PIND, PIN_SW2); loop_until_bit_is_set(PIND, PIN_SW2); display_toggle(&display); } */ potentiometer_read(&delay); if (delay.v != display.value) { display_set(&display, delay.v); } } return 0; }
int main() { #if defined(PIC32_PINGUINO) || defined(PIC32_PINGUINO_OTG) TRISDbits.TRISD9=1; // because PORTB is shared with SDA on Olimex board TRISDbits.TRISD10=1; // because PORTB is shared with SCL on Olimex board #endif SystemConfig(80000000); // default clock frequency is 80Mhz // default peripheral freq. is 40MHz (cf. system.c) // All pins of PORTB as digital IOs #ifdef __32MX220F032D__ ANSELA = 0; ANSELB = 0; ANSELC = 0; #else AD1PCFG = 0xFFFF; #endif #ifdef __ANALOG__ analog_init(); #endif #ifdef __MILLIS__ millis_init(); #endif #ifdef __PWM__ PWM_init(); #endif #ifdef __USBCDC CDC_init(); #endif #ifdef __RTCC__ RTCC_init(); #endif setup(); while (1) { #ifdef __USBCDC CDCTxService(); #endif loop(); } return(0); }
/// Startup code, run when we come out of reset void init(void) { halInit(); chSysInit(); #if defined(PORT_LED1) && defined(PIN_LED1) palSetPadMode(PORT_LED1, PIN_LED1, PAL_MODE_OUTPUT_PUSHPULL); #endif #if defined(PORT_LED2) && defined(PIN_LED2) palSetPadMode(PORT_LED2, PIN_LED2, PAL_MODE_OUTPUT_PUSHPULL); #endif // set up watchdog wd_init(); // set up serial serial_init(); // set up G-code parsing gcode_init(); // set up inputs and outputs io_init(); // set up timers timer_init(); // read PID settings from EEPROM heater_init(); // set up dda dda_init(); // start up analog read interrupt loop, // if any of the temp sensors in your config.h use analog interface analog_init(); // set up temperature inputs temp_init(); // enable interrupts enable_irq(); // reset watchdog wd_reset(); // say hi to host serial_writestr_P(PSTR("start\nok\n")); }
int main() { // default peripheral freq. is CPUCoreFrequency / 2 (cf. system.c) #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__) SystemConfig(40000000); // default clock frequency is 40Mhz #else SystemConfig(80000000); // default clock frequency is 80Mhz #endif IOsetSpecial(); IOsetDigital(); IOsetRemap(); #ifdef __ANALOG__ analog_init(); #endif #ifdef __MILLIS__ millis_init(); #endif #ifdef __PWM__ PWM_init(); #endif #ifdef __USBCDC CDC_init(); #endif #ifdef __RTCC__ RTCC_init(); #endif setup(); while (1) { #ifdef __USBCDC #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__) USB_Service( ); #else CDCTxService(); #endif #endif loop(); } return(0); }
void init(void) { analog_init(); anemometer_init(); //battery_init(); lcd_init(); cbi(DDRD, PD2); //DDRD = 0x00; sbi(EICRA, ISC00); sbi(EICRA, ISC01); sbi(EIMSK, INT0); sei(); }
void CTMU_init() { /// Setup CTMU module //CTMUCON - CTMU Control register CTMUCONH = 0x00; // make sure CTMU is disabled CTMUCONL = 0b10010000; // CTMU enable, Enables edge delay generation //CTMUICON - CTMU Current Control Register CTMUICON = 0x01; // Nominal current output = Base current level /// Setup AD converter analog_init(); }
static inline void main_init( void ) { hw_init(); sys_time_init(); led_init(); comm_init(COMM_TELEMETRY); /* add rx callback so we can send ALTIMETER_RESET messages */ comm_add_rx_callback(COMM_TELEMETRY, comm_autopilot_message_received); analog_init(); analog_enable_channel(ANALOG_CHANNEL_PRESSURE); altimeter_init(); int_enable(); }
int main() { _delay_ms(1000); beginSerial(BAUD); i2c_init(); as_init(); analog_init(); motor_init(); sei(); printString("MotorAssay ready."); // Shit goes here printString("MotorAssay done."); return(0); }
int main() { _delay_ms(100); gc_init(); sp_init(); i2c_init(); as_init(); motor_init(); boom_init(); analog_init(); sei(); printPgmString(PSTR("Shuttleboom!\n\r")); for(;;){sp_process(); sleep_mode();} return(0); }
static inline void autopilot_main_init( void ) { hw_init(); sys_time_init(); led_init(); supervision_init(); actuators_init(ACTUATOR_BANK_MOTORS); #if BOMB_ENABLED bomb_init_servo(RADIO_FMS, 0, 0); #endif rc_init(); #if HARDWARE_ENABLED_GPS gps_init(); #else comm_init(COMM_0); comm_add_tx_callback(COMM_0, comm_autopilot_message_send); comm_add_rx_callback(COMM_0, comm_autopilot_message_received); #endif comm_init(COMM_TELEMETRY); comm_add_tx_callback(COMM_TELEMETRY, comm_autopilot_message_send); comm_add_rx_callback(COMM_TELEMETRY, comm_autopilot_message_received); analog_init(); analog_enable_channel(ANALOG_CHANNEL_BATTERY); analog_enable_channel(ANALOG_CHANNEL_PRESSURE); altimeter_init(); imu_init(); autopilot_init(); ahrs_init(); ins_init(); fms_init(); int_enable(); }
void pinguino_main(void) { PIE1=0; PIE2=0; ADCON1=0x0F; #ifdef __USB__ PIE2bits.USBIE = 1; INTCON = 0xC0; #endif setup(); #ifdef ANALOG analog_init(); #endif #ifdef MILLIS millis_init(); #endif #ifdef SERVOSLIBRARY servos_init(); #endif #ifdef __USBCDC init_CDC(); PIE2bits.USBIE = 1; INTCON = 0xC0; #endif #ifdef __SERIAL__ INTCONbits.PEIE=1; INTCONbits.GIE=1; #endif #ifdef MILLIS INTCONbits.TMR0IE=1; INTCONbits.GIE=1; #endif #ifdef SERVOSLIBRARY INTCONbits.PEIE=1; INTCONbits.GIE=1; #endif while (1) { loop(); } }
/// Startup code, run when we come out of reset void init(void) { // set up watchdog wd_init(); // set up serial serial_init(); // set up G-code parsing gcode_init(); // set up inputs and outputs io_init(); // set up timers timer_init(); // read PID settings from EEPROM heater_init(); // set up dda dda_init(); // start up analog read interrupt loop, // if any of the temp sensors in your config.h use analog interface analog_init(); // set up temperature inputs temp_init(); // enable interrupts sei(); // reset watchdog wd_reset(); // prepare the power supply power_init(); // say hi to host serial_writestr_P(PSTR("start\nok\n")); }
void main() { stdout = &mystdio; stderr = &mystdio; stdin = &mystdio; analog_init(); serial_init(); timer_init(); sei(); printf_P(PSTR("start\n")); for (;;) { // read serial if (serial_rxchars()) serial_getline(); // read SDCARD if (state_flags & STATE_READ_SD) { if (file.fs == &fatfs) { UINT i; do { if (f_read(&file, &c, 1, &i) == FR_OK) { if (i) gcode_parse_char(c); } else i = 0; } while ((i != 0) && (c >= 32)); } } loopstuff(); }; }
void sim_report_temptables(int sensor) { int i ; temp_sensor_t s, first = sensor, last = sensor+1 ; // sensor is a specific sensor or -1 for "all sensors" if (sensor == -1) { first = 0; last = NUM_TEMP_SENSORS; } sei(); analog_init(); printf("; Temperature sensor test %d\n", sensor); for (s = first; s < last; s++ ) { printf("; Sensor %d\n", s); for (i = 0 ; i < 1024 ; i++ ) { analog_read_value = i ; temp_sensor_tick() ; uint16_t temp = temp_get(s); printf("%d %.2f\n", i, ((float)temp)/4 ) ; } } }
int main (void){ timer_init(); uint8_t analog_pins[1] = {5}; analog_init(analog_pins, 1, ANALOG_INTERNAL); matrix_init(); matrix_set_mode(MATRIX_MODE_2BIT); setup(); while (1) { for (uint8_t x = 0; x < MATRIX_WIDTH; x++){ for (uint8_t y = 0; y < MATRIX_HEIGHT; y++){ uint8_t count = get_neighbor_count(x, y); uint8_t alive = get_pixel(x, y); if (alive) { if (count < 2) set_scratch(x, y, 0x00); else if (count <= 3){ if (alive == GRN_1) { set_scratch(x, y, GRN_2); } if (alive == GRN_2) { set_scratch(x, y, GRN_3); } if (alive == GRN_3) { set_scratch(x, y, GRN_3 | RED_1); } else if (alive == (GRN_3 | RED_1)) { set_scratch(x, y, GRN_3 | RED_2); } else if (alive == (GRN_3 | RED_2)) { set_scratch(x, y, GRN_3 | RED_3); } else if (alive == (GRN_3 | RED_3)) { set_scratch(x, y, GRN_2 | RED_3); } else if (alive == (GRN_2 | RED_3)) { set_scratch(x, y, GRN_1 | RED_3); } else if (alive == (GRN_1 | RED_3)) { set_scratch(x, y, RED_3); } else if (alive == (RED_3)) { set_scratch(x, y, RED_2); } else if (alive == (RED_2)) { set_scratch(x, y, RED_1); } } else if (count > 3) set_scratch(x, y, 0x00); } else if (count == 3){ set_scratch(x, y, GRN_1); } } } flush(); matrix_write_buffer(); //Store board hash for (uint8_t i = RECENT_HASH_COUNT - 1; i > 0; i--){ recent_hashes[i] = recent_hashes[i - 1]; } recent_hashes[0] = get_board_hash(); uint8_t matches = 0; for (uint8_t i = 0; i < RECENT_HASH_COUNT; i++){ for (uint8_t j = i + 1; j < RECENT_HASH_COUNT; j++){ if (recent_hashes[i] == recent_hashes[j]) matches++; } } if (matches == 0) recent_hash_match_count = 0; else recent_hash_match_count++; if (recent_hash_match_count >= RECENT_HASH_MATCH_COUNT){ setup(); } _delay_ms(70); } }
/* Constructor * Point the registers to the correct ADC module * Copy the correct channel2sc1a * Call init * The very long initializer list could be shorter using some kind of struct? */ ADC_Module::ADC_Module(uint8_t ADC_number, const uint8_t* const a_channel2sc1a, const uint8_t* const a_channel2sc1a_diff) : ADC_num(ADC_number) , channel2sc1a(a_channel2sc1a) , channel2sc1a_diff(a_channel2sc1a_diff) , adc_offset((uint32_t)0x20000) , ADC_SC1A(&ADC0_SC1A + adc_offset*ADC_num) , ADC_SC1B(&ADC0_SC1B + adc_offset*ADC_num) , ADC_CFG1(&ADC0_CFG1 + adc_offset*ADC_num) , ADC_CFG2(&ADC0_CFG2 + adc_offset*ADC_num) , ADC_RA(&ADC0_RA + adc_offset*ADC_num) , ADC_RB(&ADC0_RB + adc_offset*ADC_num) , ADC_CV1(&ADC0_CV1 + adc_offset*ADC_num) , ADC_CV2(&ADC0_CV2 + adc_offset*ADC_num) , ADC_SC2(&ADC0_SC2 + adc_offset*ADC_num) , ADC_SC3(&ADC0_SC3 + adc_offset*ADC_num) , ADC_PGA(&ADC0_PGA + adc_offset*ADC_num) , ADC_OFS(&ADC0_OFS + adc_offset*ADC_num) , ADC_PG(&ADC0_PG + adc_offset*ADC_num) , ADC_MG(&ADC0_MG + adc_offset*ADC_num) , ADC_CLPD(&ADC0_CLPD + adc_offset*ADC_num) , ADC_CLPS(&ADC0_CLPS + adc_offset*ADC_num) , ADC_CLP4(&ADC0_CLP4 + adc_offset*ADC_num) , ADC_CLP3(&ADC0_CLP3 + adc_offset*ADC_num) , ADC_CLP2(&ADC0_CLP2 + adc_offset*ADC_num) , ADC_CLP1(&ADC0_CLP1 + adc_offset*ADC_num) , ADC_CLP0(&ADC0_CLP0 + adc_offset*ADC_num) , ADC_CLMD(&ADC0_CLMD + adc_offset*ADC_num) , ADC_CLMS(&ADC0_CLMS + adc_offset*ADC_num) , ADC_CLM4(&ADC0_CLM4 + adc_offset*ADC_num) , ADC_CLM3(&ADC0_CLM3 + adc_offset*ADC_num) , ADC_CLM2(&ADC0_CLM2 + adc_offset*ADC_num) , ADC_CLM1(&ADC0_CLM1 + adc_offset*ADC_num) , ADC_CLM0(&ADC0_CLM0 + adc_offset*ADC_num) , PDB0_CHnC1(&PDB0_CH0C1 + ADC_num*0xA) { // ADC0 or ADC1? //ADC_num = ADC_number; // point the control registers to the correct addresses // use bitband where necessary //uint32_t adc_offset = (uint32_t)0x20000; //ADC_SC1A = &ADC0_SC1A + adc_offset*ADC_num; // ADC_SC1A_coco = adc_bitband((uint32_t)ADC_SC1A, 7); // conversion complete // ADC_SC1A_aien = adc_bitband((uint32_t)ADC_SC1A, 6); // interrupts enabled //ADC_SC1B = &ADC0_SC1B + adc_offset*ADC_num; //ADC_CFG1 = &ADC0_CFG1 + adc_offset*ADC_num; // ADC_CFG1_adlpc = adc_bitband((uint32_t)ADC_CFG1, 7); // low power conf. // ADC_CFG1_adiv1 = adc_bitband((uint32_t)ADC_CFG1, 6); // divide input clock // ADC_CFG1_adiv0 = adc_bitband((uint32_t)ADC_CFG1, 5); // // ADC_CFG1_adlsmp = adc_bitband((uint32_t)ADC_CFG1, 4); // low sampling speed // ADC_CFG1_mode1 = adc_bitband((uint32_t)ADC_CFG1, 3); // resolution mode // ADC_CFG1_mode0 = adc_bitband((uint32_t)ADC_CFG1, 2); // // ADC_CFG1_adiclk1 = adc_bitband((uint32_t)ADC_CFG1, 1); // input clock // ADC_CFG1_adiclk0 = adc_bitband((uint32_t)ADC_CFG1, 0); // //ADC_CFG2 = &ADC0_CFG2 + adc_offset*ADC_num; // ADC_CFG2_muxsel = adc_bitband((uint32_t)ADC_CFG2, 4); // mux to select a or b channels // ADC_CFG2_adacken = adc_bitband((uint32_t)ADC_CFG2, 3); // enable the async. clock // ADC_CFG2_adhsc = adc_bitband((uint32_t)ADC_CFG2, 2); // high-speed config: add 2 ADCK // ADC_CFG2_adlsts1 = adc_bitband((uint32_t)ADC_CFG2, 1); // loger sampling time // ADC_CFG2_adlsts0 = adc_bitband((uint32_t)ADC_CFG2, 0); //ADC_RA = &ADC0_RA + adc_offset*ADC_num; //ADC_RB = &ADC0_RB + adc_offset*ADC_num; //ADC_CV1 = &ADC0_CV1 + adc_offset*ADC_num; //ADC_CV2 = &ADC0_CV2 + adc_offset*ADC_num; //ADC_SC2 = &ADC0_SC2 + adc_offset*ADC_num; // ADC_SC2_adact = adc_bitband((uint32_t)ADC_SC2, 7); // conversion active // ADC_SC2_cfe = adc_bitband((uint32_t)ADC_SC2, 5); // compare function enable, greater than and range enable // ADC_SC2_cfgt = adc_bitband((uint32_t)ADC_SC2, 4); // ADC_SC2_cren = adc_bitband((uint32_t)ADC_SC2, 3); // ADC_SC2_dma = adc_bitband((uint32_t)ADC_SC2, 2); // dma enable // ADC_SC2_ref = adc_bitband((uint32_t)ADC_SC2, 0); // refsel only uses bit 0, not really bit 1. //ADC_SC3 = &ADC0_SC3 + adc_offset*ADC_num; // ADC_SC3_cal = adc_bitband((uint32_t)ADC_SC3, 7); // start/stop calibration // ADC_SC3_calf = adc_bitband((uint32_t)ADC_SC3, 6); // calibration failed flag // ADC_SC3_adco = adc_bitband((uint32_t)ADC_SC3, 3); // continuous conversion // ADC_SC3_avge = adc_bitband((uint32_t)ADC_SC3, 2); // enable averages bit // ADC_SC3_avgs1 = adc_bitband((uint32_t)ADC_SC3, 1); // num of averages bits // ADC_SC3_avgs0 = adc_bitband((uint32_t)ADC_SC3, 0); //ADC_PGA = &ADC0_PGA + adc_offset*ADC_num; // ADC_PGA_pgaen = adc_bitband((uint32_t)ADC_PGA, 23); // enable pga // ADC_OFS = &ADC0_OFS + adc_offset*ADC_num; // ADC_PG = &ADC0_PG + adc_offset*ADC_num; // ADC_MG = &ADC0_MG + adc_offset*ADC_num; // ADC_CLPD = &ADC0_CLPD + adc_offset*ADC_num; // ADC_CLPS = &ADC0_CLPS + adc_offset*ADC_num; // ADC_CLP4 = &ADC0_CLP4 + adc_offset*ADC_num; // ADC_CLP3 = &ADC0_CLP3 + adc_offset*ADC_num; // ADC_CLP2 = &ADC0_CLP2 + adc_offset*ADC_num; // ADC_CLP1 = &ADC0_CLP1 + adc_offset*ADC_num; // ADC_CLP0 = &ADC0_CLP0 + adc_offset*ADC_num; // ADC_CLMD = &ADC0_CLMD + adc_offset*ADC_num; // ADC_CLMS = &ADC0_CLMS + adc_offset*ADC_num; // ADC_CLM4 = &ADC0_CLM4 + adc_offset*ADC_num; // ADC_CLM3 = &ADC0_CLM3 + adc_offset*ADC_num; // ADC_CLM2 = &ADC0_CLM2 + adc_offset*ADC_num; // ADC_CLM1 = &ADC0_CLM1 + adc_offset*ADC_num; // ADC_CLM0 = &ADC0_CLM0 + adc_offset*ADC_num; IRQ_ADC = IRQ_ADC0 + ADC_num*1; // pointer to channel2sc1a //channel2sc1a = a_channel2sc1a; //channel2sc1a_diff = a_channel2sc1a_diff; // call our init analog_init(); }
// Application entry point called from bootloader v4.x void main(void) #endif { #if defined(__18f25k50) || defined(__18f45k50) || \ defined(__18f26j50) || defined(__18f46j50) || \ defined(__18f26j53) || defined(__18f46j53) || \ defined(__18f27j53) || defined(__18f47j53) u16 pll_startup_counter = 600; #endif /// ---------------------------------------------------------------- /// If we start from a Power-on reset, set NOT_POR bit to 1 /// ---------------------------------------------------------------- if (RCONbits.NOT_POR == 0) { RCON |= 0b10010011; // set all reset flag // enable priority levels on interrupts } /// ---------------------------------------------------------------- /// Disables all interrupt /// ---------------------------------------------------------------- //INTCONbits.GIEH = 0; // Disables all HP interrupts //INTCONbits.GIEL = 0; // Disables all LP interrupts /// ---------------------------------------------------------------- /// Perform a loop for some processors until their frequency is stable /// ---------------------------------------------------------------- #if defined(__18f2455) || defined(__18f4455) || \ defined(__18f2550) || defined(__18f4550) // If Internal Oscillator is used if (OSCCONbits.SCS > 0x01) // wait INTOSC frequency is stable (IOFS=1) while (!OSCCONbits.IOFS); // PLL is enabled by Config. Bits #elif defined(__18f25k50) || defined(__18f45k50) // If Internal Oscillator is used if (OSCCONbits.SCS > 0x01) // wait HFINTOSC frequency is stable (HFIOFS=1) while (!OSCCONbits.HFIOFS); // Enable the PLL and wait 2+ms until the PLL locks OSCCON2bits.PLLEN = 1; OSCTUNEbits.SPLLMULT = 1; // 1=3xPLL, 0=4xPLL while (pll_startup_counter--); #elif defined(__18f26j50) || defined(__18f46j50) // If Internal Oscillator is used // if (OSCCONbits.SCS > 0x02) // Seems there is no time to wait // Enable the PLL and wait 2+ms until the PLL locks OSCTUNEbits.PLLEN = 1; while (pll_startup_counter--); #elif defined(__18f26j53) || defined(__18f46j53) || \ defined(__18f27j53) || defined(__18f47j53) // If Internal Oscillator is used if (OSCCONbits.SCS > 0x02) // wait INTOSC frequency is stable (FLTS=1) while(!OSCCONbits.FLTS); // Enable the PLL and wait 2+ms until the PLL locks OSCTUNEbits.PLLEN = 1; while (pll_startup_counter--); #endif /// ---------------------------------------------------------------- /// I/O init /// ---------------------------------------------------------------- IO_init(); IO_digital(); #if defined(__18f26j50) || defined(__18f46j50) || \ defined(__18f26j53) || defined(__18f46j53) || \ defined(__18f27j53) || defined(__18f47j53) IO_remap(); #endif /// ---------------------------------------------------------------- /// Various Init. /// ---------------------------------------------------------------- #ifdef __USB__ usb_init(); #endif #ifdef __USBCDC CDC_init(); #endif #ifdef __USBBULK bulk_init(); #endif #if defined(ANALOGREFERENCE) || defined(ANALOGREAD) analog_init(); #endif #ifdef ANALOGWRITE analogwrite_init(); #endif #ifdef __MILLIS__ // Use Timer 0 millis_init(); #endif #ifdef SERVOSLIBRARY // Use Timer 1 servos_init(); #endif #ifdef __PS2KEYB__ keyboard_init() #endif //////////////////////////////////////////////////////////////////////// setup(); //////////////////////////////////////////////////////////////////////// #if defined(TMR0INT) || defined(TMR1INT) || \ defined(TMR2INT) || defined(TMR3INT) || \ defined(TMR4INT) || defined(TMR5INT) || \ defined(TMR6INT) || defined(TMR8INT) IntTimerStart(); // Enable all defined timers interrupts // at the same time #endif #ifdef ON_EVENT //IntInit(); INTCONbits.GIEH = 1; // Enable global HP interrupts INTCONbits.GIEL = 1; // Enable global LP interrupts #endif while (1) { //////////////////////////////////////////////////////////////////////// loop(); //////////////////////////////////////////////////////////////////////// } }
/* Constructor * Point the registers to the correct ADC module * Copy the correct channel2sc1a and sc1a2channel * Call init */ ADC_Module::ADC_Module(uint8_t ADC_number) { // ADC0 or ADC1? ADC_num = ADC_number; // point the control registers to the correct addresses // use bitband where necessary uint32_t adc_offset = (uint32_t)0x20000; ADC_SC1A = &ADC0_SC1A + adc_offset*ADC_num; ADC_SC1A_coco = adc_bitband((uint32_t)ADC_SC1A, 7); // conversion complete ADC_SC1A_aien = adc_bitband((uint32_t)ADC_SC1A, 6); // interrupts enabled ADC_SC1B = &ADC0_SC1B + adc_offset*ADC_num; ADC_CFG1 = &ADC0_CFG1 + adc_offset*ADC_num; ADC_CFG1_adlpc = adc_bitband((uint32_t)ADC_CFG1, 7); // low power conf. ADC_CFG1_adiv1 = adc_bitband((uint32_t)ADC_CFG1, 6); // divide input clock ADC_CFG1_adiv0 = adc_bitband((uint32_t)ADC_CFG1, 5); // ADC_CFG1_adlsmp = adc_bitband((uint32_t)ADC_CFG1, 4); // low sampling speed ADC_CFG1_mode1 = adc_bitband((uint32_t)ADC_CFG1, 3); // resolution mode ADC_CFG1_mode0 = adc_bitband((uint32_t)ADC_CFG1, 2); // ADC_CFG1_adiclk1 = adc_bitband((uint32_t)ADC_CFG1, 1); // input clock ADC_CFG1_adiclk0 = adc_bitband((uint32_t)ADC_CFG1, 0); // ADC_CFG2 = &ADC0_CFG2 + adc_offset*ADC_num; ADC_CFG2_muxsel = adc_bitband((uint32_t)ADC_CFG2, 4); // mux to select a or b channels ADC_CFG2_adacken = adc_bitband((uint32_t)ADC_CFG2, 3); // enable the async. clock ADC_CFG2_adhsc = adc_bitband((uint32_t)ADC_CFG2, 2); // high-speed config: add 2 ADCK ADC_CFG2_adlsts1 = adc_bitband((uint32_t)ADC_CFG2, 1); // loger sampling time ADC_CFG2_adlsts0 = adc_bitband((uint32_t)ADC_CFG2, 0); ADC_RA = &ADC0_RA + adc_offset*ADC_num; ADC_RB = &ADC0_RB + adc_offset*ADC_num; ADC_CV1 = &ADC0_CV1 + adc_offset*ADC_num; ADC_CV2 = &ADC0_CV2 + adc_offset*ADC_num; ADC_SC2 = &ADC0_SC2 + adc_offset*ADC_num; ADC_SC2_adact = adc_bitband((uint32_t)ADC_SC2, 7); // conversion active ADC_SC2_cfe = adc_bitband((uint32_t)ADC_SC2, 5); // compare function enable, greater than and range enable ADC_SC2_cfgt = adc_bitband((uint32_t)ADC_SC2, 4); ADC_SC2_cren = adc_bitband((uint32_t)ADC_SC2, 3); ADC_SC2_dma = adc_bitband((uint32_t)ADC_SC2, 2); // dma enable ADC_SC2_ref = adc_bitband((uint32_t)ADC_SC2, 0); // refsel only uses bit 0, not really bit 1. ADC_SC3 = &ADC0_SC3 + adc_offset*ADC_num; ADC_SC3_cal = adc_bitband((uint32_t)ADC_SC3, 7); // start/stop calibration ADC_SC3_calf = adc_bitband((uint32_t)ADC_SC3, 6); // calibration failed flag ADC_SC3_adco = adc_bitband((uint32_t)ADC_SC3, 3); // continuous conversion ADC_SC3_avge = adc_bitband((uint32_t)ADC_SC3, 2); // enable averages bit ADC_SC3_avgs0 = adc_bitband((uint32_t)ADC_SC3, 0); // num of averages bits ADC_SC3_avgs1 = adc_bitband((uint32_t)ADC_SC3, 1); ADC_PGA = &ADC0_PGA + adc_offset*ADC_num; ADC_PGA_pgaen = adc_bitband((uint32_t)ADC_PGA, 23); // enable pga ADC_OFS = &ADC0_OFS + adc_offset*ADC_num; ADC_PG = &ADC0_PG + adc_offset*ADC_num; ADC_MG = &ADC0_MG + adc_offset*ADC_num; ADC_CLPD = &ADC0_CLPD + adc_offset*ADC_num; ADC_CLPS = &ADC0_CLPS + adc_offset*ADC_num; ADC_CLP4 = &ADC0_CLP4 + adc_offset*ADC_num; ADC_CLP3 = &ADC0_CLP3 + adc_offset*ADC_num; ADC_CLP2 = &ADC0_CLP2 + adc_offset*ADC_num; ADC_CLP1 = &ADC0_CLP1 + adc_offset*ADC_num; ADC_CLP0 = &ADC0_CLP0 + adc_offset*ADC_num; ADC_CLMD = &ADC0_CLMD + adc_offset*ADC_num; ADC_CLMS = &ADC0_CLMS + adc_offset*ADC_num; ADC_CLM4 = &ADC0_CLM4 + adc_offset*ADC_num; ADC_CLM3 = &ADC0_CLM3 + adc_offset*ADC_num; ADC_CLM2 = &ADC0_CLM2 + adc_offset*ADC_num; ADC_CLM1 = &ADC0_CLM1 + adc_offset*ADC_num; ADC_CLM0 = &ADC0_CLM0 + adc_offset*ADC_num; // copy the correct version of channel2sc1a and sc1a2channel depending on the ADC module this instance is: #if defined(__MK20DX128__) // Tennsy 3.0, only ADC0 memcpy(&channel2sc1a, &ADC::channel2sc1aADC0, sizeof(channel2sc1a)); memcpy(&sc1a2channel, &ADC::sc1a2channelADC0, sizeof(sc1a2channel)); #elif defined(__MK20DX256__) // Teensy 3.1: can be ADC0 or ADC1 if(ADC_num==0) { // ADC0 memcpy(&channel2sc1a, &ADC::channel2sc1aADC0, sizeof(channel2sc1a)); memcpy(&sc1a2channel, &ADC::sc1a2channelADC0, sizeof(sc1a2channel)); } else { // ADC1 memcpy(&channel2sc1a, &ADC::channel2sc1aADC1, sizeof(channel2sc1a)); memcpy(&sc1a2channel, &ADC::sc1a2channelADC1, sizeof(sc1a2channel)); } #endif // call our init analog_init(); }
int main(void) { int test_mode; int vm_present; int i; unsigned int seed; // Needs to be called ASAP as rf need a looooooong time to wake up. // This function is just sending a pulse over the SCL line. rf_wakeup(); clock_set_speed(16000000UL,16); setup_pps(); setup_io(); leds_init(); CHARGE_500MA = 0; // Switch back to 100mA charge. // Switch on one led to say we are powered on leds_set(LED_BATTERY_0, 32); // Enable the poweroff softirq. _INT3IF = 0; _INT3IP = 1; _INT3IE = 1; // Sound must be enabled before analog, as // The analog interrupt callback into sound processing ... // But must be initialised _after_ leds as it use one led IO for enabling amp. sound_init(); tone_init(); // Init tone generator pwm_motor_init(); pid_motor_init(); // We need the settings for the horizontal prox. load_settings_from_flash(); for (i = 0; i < 2; i++) { // Settings is definitely wrong.... if(settings.mot256[i] <= 0) settings.mot256[i] = 256; // 1024 (AD resolution is 10 bits) * 256 / 9 fits in signed 16 bits. if (settings.mot256[i] < 9) settings.mot256[i] = 9; } // This is the horizontal prox. Vertical one are handled by the ADC // but ADC sync the motor mesurment with the prox, so we don't pullute it with noise ... timer_init(TIMER_IR_COMM, 0,-1); // The period will be changed later. prox_init(PRIO_SENSORS); // Same priority as analog (maybe should be at 7 ...) // Warning: We cannot use the SD before the analog init as some pin are on the analog port. analog_init(TIMER_ANALOG, PRIO_SENSORS); wait_valid_vbat(); log_init(); // We will need to read vbat to be sure we can flash. ntc_init(ntc_callback, PRIO_1KHZ); // i2c_init(I2C_3); i2c_init_master(I2C_3, 400000, PRIO_I2C); I2C3CON = 0x9000; mma7660_init(I2C_3, MMA7660_DEFAULT_ADDRESS, acc_cb, 0); mma7660_set_mode(MMA7660_120HZ, 1); rc5_init(TIMER_RC5, rc5_callback, PRIO_RC5); sd_init(); timer_init(TIMER_1KHZ, 1000, 6); timer_enable_interrupt(TIMER_1KHZ, timer_1khz, PRIO_1KHZ); rf_init(I2C_3); timer_enable(TIMER_1KHZ); sd_log_file(); vm_present = init_aseba_and_fifo(); if(vm_present) log_analyse_bytecode(); vmVariables.fwversion[0] = FW_VERSION; vmVariables.fwversion[1] = FW_VARIANT; // SD file is more important than internal flash if(!sd_load_aseba_code()) { log_set_flag(LOG_FLAG_VMCODESD); vm_present = 1; log_analyse_bytecode(); } // Behavior is on INT4 (softirq trigged by 1khz timer). behavior_init(PRIO_BEHAVIOR); test_mode = sd_test_file_present(); if(!test_mode) mode_init(vm_present); // Enable the LVD interrupt _LVDIE = 1; play_sound(SOUND_POWERON); if(test_mode) { test_mode_start(); while(1) idle_without_aseba(); } while(behavior_enabled(B_MODE)) idle_without_aseba(); // If usb did not put us out of behavior mode, then start the rf link if(!usb_uart_serial_port_open() && (rf_get_status() & RF_PRESENT)) { rf_set_link(RF_UP); } // get the random seed seed = 0; for(i = 0; i < 5; i++) { seed += vmVariables.buttons_mean[i]; seed += vmVariables.buttons_noise[i]; } seed += vmVariables.vbat[0]; seed += vmVariables.vbat[1]; for(i = 0; i < 3; i++) seed += vmVariables.acc[i]; AsebaSetRandomSeed(seed); for(i = 0; i < 3; i++) AsebaGetRandom(); // Give full control to aseba. No way out (except reset). run_aseba_main_loop(); }
void HAL_adc_init() { analog_init(); while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish while (ADC1_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish NVIC_ENABLE_IRQ(IRQ_FTM1); }
int unicorn_init(void) { channel_tag fan = NULL; int ret = 0; board_info_t board_info; printf("unicorn_init...\n"); ret = eeprom_read_board_info(EEPROM_DEV, &board_info); if (ret < 0) { printf("Read eeprom board info failed\n"); return -1; } if (!strncasecmp("bbp1s", board_info.name, 5)) { bbp_board_type = BOARD_BBP1S; } else if(!strncasecmp("bbp1", board_info.name, 4)){ bbp_board_type = BOARD_BBP1; } printf("board name:%s, version:%s, get board type:%d \n", board_info.name, board_info.version, bbp_board_type); /* * Create fifo * fifo_plan2st, fifo_st2plan * fifo_plan2gc, fifo_gc2plan */ Fifo_Attrs fAttrs = Fifo_Attrs_DEFAULT; hFifo_plan2st = Fifo_create(&fAttrs); hFifo_st2plan = Fifo_create(&fAttrs); if ((hFifo_st2plan == NULL) || (hFifo_plan2st == NULL)) { printf("Create Fifo failed\n"); return -1; } Pause_Attrs pAttrs = Pause_Attrs_DEFAULT; hPause_printing = Pause_create(&pAttrs); if (hPause_printing == NULL) { printf("Create pause err\n"); return -1; } else { Pause_on(hPause_printing); } /* set up unicorn system */ ret = unicorn_setup(); if (ret < 0) { return ret; } /* init sub systems of unicorn */ ret = parameter_init(EEPROM_DEV); if (ret < 0) { printf("parameter_init failed\n"); return ret; } ret = analog_init(); if (ret < 0) { printf("analog_init failed\n"); return ret; } ret = temp_init(); if (ret < 0) { printf("temp_init failed\n"); return ret; } ret = pwm_init(); if (ret < 0) { printf("pwm_init failed\n"); return ret; } ret = fan_init(); if (ret < 0) { printf("fan_init failed\n"); return ret; } ret = heater_init(); if (ret < 0) { printf("heater_init failed\n"); return ret; } #ifdef SERVO if (bbp_board_type == BOARD_BBP1S) { ret = servo_init(); if (ret < 0) { printf("servo_init failed\n"); return ret; } } #endif ret = lmsw_init(); if (ret < 0) { printf("lmsw_init failed\n"); return ret; } ret = plan_init(); if (ret < 0) { printf("plan_init failed\n"); return ret; } ret = stepper_init(); if (ret < 0) { printf("stepper_init failed\n"); return ret; } ret = gcode_init(); if (ret < 0) { printf("gcode_init failed\n"); return ret; } fan = fan_lookup_by_name("fan_3"); if (fan) { fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); fan_enable(fan); } fan = fan_lookup_by_name("fan_4"); if (fan) { fan_enable(fan); fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); } fan = fan_lookup_by_name("fan_5"); if (fan) { fan_enable(fan); fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); } fan = fan_lookup_by_name("fan_6"); if (fan) { fan_enable(fan); fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); } printf("unicorn_init ok!!!\n"); return ret; }
void pinguino_main(void) { #if defined(PIC18F26J50) // Enable the PLL and wait 2+ms until the PLL locks u16 pll_startup_counter = 600; OSCTUNEbits.PLLEN = 1; while(pll_startup_counter--); #endif PIE1 = 0; PIE2 = 0; IOsetSpecial(); IOsetDigital(); IOsetRemap(); #ifdef ON_EVENT // Enable General/Peripheral interrupts int_init(); // Disable all individual interrupts #endif #ifdef __USB__ PIE2bits.USBIE = 1; INTCONbits.PEIE = 1; INTCONbits.GIE = 1; #endif //setup(); //#ifdef ON_EVENT //int_start(); // Enable all defined timers interrupts //#endif #ifdef ANALOG analog_init(); #endif #ifdef __MILLIS__ // Use Timer 0 millis_init(); #endif #ifdef SERVOSLIBRARY servos_init(); #endif #ifdef __USBCDC CDC_init(); PIE2bits.USBIE = 1; INTCONbits.PEIE = 1; INTCONbits.GIE = 1; #endif #ifdef __USBBULK bulk_init(); PIE2bits.USBIE = 1; INTCONbits.PEIE = 1; INTCONbits.GIE = 1; #endif #ifdef __PS2KEYB__ keyboard_init() #endif #if defined(__SERIAL__) || defined(SERVOSLIBRARY) INTCONbits.PEIE = 1; INTCONbits.GIE = 1; #endif /* RB : millis.c/millis_init() did already the job #ifdef MILLIS INTCONbits.TMR0IE= 1; INTCONbits.GIE = 1; #endif */ setup(); #ifdef ON_EVENT int_start(); // Enable all defined timers interrupts #endif while (1) loop(); }