int main(void) { laser_off(); bootloaderSwitcher(); init_serial_number(); USB_Start(); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); setupJP5(); setupJP6(); setupLeds(); init_watchdog(); setup_interlock(); //debug: flas the light on boot, to watch for watchdog resets setCoilLed(1); initialize_led_override(); if (LED_OVERRIDES_EN){ play_long_spin(); //Spin the led's while we load the rest of this stuff } initialize_pwm(); initialize_dripper(); setCornerLed(0); setInLed(0); setCoilLed(0); setUSBLed(0); SysTick_Config(SystemCoreClock / 2000); //48MHz/2000 gives us 2000 ticks per second (2KHz) int last_drip_count = g_dripcount; while(1) { serialio_feed(); updateADC(); if (move_count!=0){ g_twig_coils=0; g_key_coil_gate=0; } if (g_dripcount != last_drip_count) { last_drip_count = g_dripcount; send_updated_drip_count(); } if ((tick % 500) == 0) { send_printer_status(); } } }
int main(void) { unsigned int pot_value; unsigned int counter = 0; initialize_board(); initialize_led(); initialize_uart(); initialize_adc(MODE_ANALOG0); initialize_pwm(); uart_printf("Hello, world!\n"); while(1) { pot_value = adc_get_reading(); //UARTprintf ("Temperature = %3d*C \r", adc_get_temp ()); uart_printf ("AIN0 (PE3) = %3d Duty value = %d\r", pot_value, pot_value/4); led_toggle (GREEN_LED); counter += 100; if (counter > 1000) counter = 0; pwm_set_duty (pot_value/4); // // This function provides a means of generating a constant length // delay. The function delay (in cycles) = 3 * parameter. Delay // 250ms arbitrarily. // SysCtlDelay(SysCtlClockGet() / 12); } }
int pwm_start(const char *key, float duty, float freq, int polarity) { char fragment[18]; char pwm_test_fragment[20]; char pwm_test_path[45]; char period_path[50]; char duty_path[50]; char polarity_path[55]; int period_fd, duty_fd, polarity_fd; struct pwm_exp *new_pwm, *pwm; if(!BBB_G(pwm_initialized)) { initialize_pwm(); } snprintf(fragment, sizeof(fragment), "bone_pwm_%s", key); if (!load_device_tree(fragment)) { //error enabling pin for pwm return -1; } //creates the fragment in order to build the pwm_test_filename, such as "pwm_test_P9_13" snprintf(pwm_test_fragment, sizeof(pwm_test_fragment), "pwm_test_%s", key); //finds and builds the pwm_test_path, as it can be variable... build_path(BBB_G(ocp_dir), pwm_test_fragment, pwm_test_path, sizeof(pwm_test_path)); //create the path for the period and duty snprintf(period_path, sizeof(period_path), "%s/period", pwm_test_path); snprintf(duty_path, sizeof(duty_path), "%s/duty", pwm_test_path); snprintf(polarity_path, sizeof(polarity_path), "%s/polarity", pwm_test_path); //add period and duty fd to pwm list if ((period_fd = open(period_path, O_RDWR)) < 0) return -1; if ((duty_fd = open(duty_path, O_RDWR)) < 0) { //error, close already opened period_fd. close(period_fd); return -1; } if ((polarity_fd = open(polarity_path, O_RDWR)) < 0) { //error, close already opened period_fd and duty_fd. close(period_fd); close(duty_fd); return -1; } // add to list new_pwm = malloc(sizeof(struct pwm_exp)); if (new_pwm == 0) { return -1; // out of memory } strncpy(new_pwm->key, key, KEYLEN); /* can leave string unterminated */ new_pwm->key[KEYLEN] = '\0'; /* terminate string */ new_pwm->period_fd = period_fd; new_pwm->duty_fd = duty_fd; new_pwm->polarity_fd = polarity_fd; new_pwm->next = NULL; if (exported_pwms == NULL) { // create new list exported_pwms = new_pwm; } else { // add to end of existing list pwm = exported_pwms; while (pwm->next != NULL) pwm = pwm->next; pwm->next = new_pwm; } pwm_set_frequency(key, freq); pwm_set_polarity(key, polarity); pwm_set_duty_cycle(key, duty); return 1; }