#include "drivers/serial.h"
#include "drivers/gpio.h"
#include "extdrv/status_led.h"
-#include "drivers/adc.h"
#include "drivers/timers.h"
* - inverted one (3), for use with a single transistor
* - non inverted (40 - 3), for use with two transistors (or none).
*/
-#define DUTY_INVERTED 1
+#define DUTY_INVERTED 0
#if (DUTY_INVERTED == 1)
#define SERVO_MED_POS_DUTY_CYCLE 3
#else
/* UART 0 */
{ LPC_UART0_RX_PIO_0_1, LPC_IO_DIGITAL },
{ LPC_UART0_TX_PIO_0_2, LPC_IO_DIGITAL },
- /* TIMER_32B0 */
- { LPC_TIMER_32B0_M1_PIO_0_19, LPC_TIMER_PIN_CONFIG },
+ /* TIMER_32B1 */
+ { LPC_TIMER_32B1_M0_PIO_0_23, LPC_TIMER_PIN_CONFIG },
ARRAY_LAST_PIO,
};
-const struct pio_config adc_pins[] = {
- { LPC_ADC_AD0_PIO_0_30, LPC_IO_ANALOG },
- { LPC_ADC_AD1_PIO_0_31, LPC_IO_ANALOG },
- { LPC_ADC_AD2_PIO_1_0, LPC_IO_ANALOG },
- { LPC_ADC_AD3_PIO_1_1, LPC_IO_ANALOG },
- { LPC_ADC_AD4_PIO_1_2, LPC_IO_ANALOG },
- { LPC_ADC_AD5_PIO_1_3, LPC_IO_ANALOG },
- ARRAY_LAST_PIO,
-};
-const struct pio status_led_green = LPC_GPIO_1_4;
-const struct pio status_led_red = LPC_GPIO_1_5;
+const struct pio status_led_green = LPC_GPIO_0_28;
+const struct pio status_led_red = LPC_GPIO_0_29;
/***************************************************************************** */
static uint32_t servo_med_pos_cmd = 0;
.period_chan = 3,
};
- if (timer_num > LPC_TIMER_32B1) {
- uprintf(uart_num, "Bad timer number\n");
- return -1;
- }
- if (pwm_chan >= 3) {
- uprintf(uart_num, "Bad channel number\n");
- return -1;
- }
timer = timer_num;
channel = pwm_chan;
timer_conf.outputs[0] = pwm_chan;
return 0;
}
-int set_servo(int adc_num, int uart_num)
+int set_servo(int c, int uart_num)
{
uint16_t val = 0, angle = 0;
uint32_t pos = servo_med_pos_cmd;
- adc_start_convertion_once(adc_num, LPC_ADC_SEQ(0), 0);
- msleep(10);
- adc_get_value(&val, adc_num);
- uprintf(uart_num, "ADC(%d): %d (raw: 0x%04x)\n", adc_num, val, val);
-
- angle = ((val * 10) / 56);
+ val = c - '0';
+ angle = (val * 20);
if (angle > 180) {
angle = 180;
}
}
+volatile int set_pos = -1;
+void change_pos(uint8_t c)
+{
+ set_pos = c;
+}
+
/***************************************************************************** */
void system_init()
{
system_set_default_power_state();
clock_config(SELECTED_FREQ);
set_pins(common_pins);
- set_pins(adc_pins);
gpio_on();
status_led_config(&status_led_green, &status_led_red);
/* System tick timer MUST be configured and running in order to use the sleeping
int main(void)
{
system_init();
- uart_on(UART0, 115200, NULL);
- adc_on(NULL);
- servo_config(LPC_TIMER_32B0, 1, 0);
+ uart_on(UART0, 115200, change_pos);
+
+ servo_config(LPC_TIMER_32B1, 0, UART0);
while (1) {
chenillard(500);
- /* ADC Test */
- set_servo(LPC_ADC(0), 0);
+ if (set_pos != -1) {
+ set_servo(set_pos, UART0);
+ set_pos = -1;
+ }
}
return 0;
}