add init on poweron

This commit is contained in:
eddyem 2015-08-04 16:55:28 +03:00
parent 36bea5ad11
commit f88cbaafd5
6 changed files with 19 additions and 5 deletions

View File

@ -192,9 +192,9 @@ void adc_dma_on(){
void ADC_init(){
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN); // enable clocking
rcc_periph_clock_enable(RCC_ADC1);
// rcc_periph_clock_enable(RCC_ADC1);
rcc_set_adcpre(RCC_CFGR_ADCPRE_PCLK2_DIV4);
rcc_periph_clock_enable(RCC_GPIOA | RCC_GPIOB | RCC_GPIOC); // clocking for ADC ports
//rcc_periph_clock_enable(RCC_GPIOA | RCC_GPIOB | RCC_GPIOC); // clocking for ADC ports
// channels 4-7: PA7-PA4 (ADC IN 4..7); U10 (PA0); U36 (PA1)
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO4|GPIO5|GPIO6|GPIO7|GPIO1|GPIO0);
// channels 0,1: PB1, PB0 (ADC IN 8, 9)

View File

@ -32,6 +32,7 @@
#include "onewire.h"
#include "stepper_motors.h"
#include "powerhw.h"
#include "init_on_power.h"
volatile uint32_t Timer = 0, tOVRFL = 0; // global timer (milliseconds), overflow counter
usbd_device *usbd_dev;
@ -215,6 +216,7 @@ int main(){
LED_STATUS_OK(); // All initialized - light up LED
while(1){
init_on_poweron_proc();
usbd_poll(usbd_dev);
if(oldusbdatalen != usbdatalen){ // there's something in USB buffer
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen, usb_send);

View File

@ -35,7 +35,7 @@ static volatile int32_t Motor_abs_steps[5] = {0, 0, 0, 0, 0};
// increments that will be added each step to Motor_abs_steps (+1/-1)
static int8_t Motor_step_increment[5] = {1,1,1,1,1};
// flag of active motor
static volatile uint8_t Motor_active[5] = {0, 0, 0, 0, 0};
volatile uint8_t Motor_active[5] = {0, 0, 0, 0, 0};
/*
* Wait flags: if non-zero, flag just decremented
* (we need it to wait a little on turrets' fixed positions to omit Halls' histeresis)

View File

@ -86,6 +86,8 @@
extern uint8_t move2pos[]; // export this array for ability of moving turret to given position from outside
extern volatile uint8_t Motor_active[];
void steppers_init();
void process_stepper_motors();
uint8_t move_motor(uint8_t num, int32_t steps);

View File

@ -27,6 +27,7 @@
#include "stepper_motors.h"
#include "powerhw.h"
#include "AD7794.h"
#include "init_on_power.h"
// mode:
curmode_t mode = BYTE_MODE; // text protocol, activated on 1st meeteng of '['
@ -272,7 +273,7 @@ void help(sendfun s){
//pr("n");
pr("o\topen shutter");
pr(STR_MOTORS_VOLTAGE "\tshow motors voltage");
//pr("q");
pr("q\tget initialisation status");
pr("r\treinit shutter");
pr(STR_EXTADC_VALUES "\tshow AD7794 values");
pr(STR_SHTR_STATE "\tprint shutter state");
@ -281,7 +282,7 @@ void help(sendfun s){
//pr("w");
pr("x\tset timer period for turrets' motors");
//pr("y");
//pr("z");
pr("z\treinitialisation (move linear stages to zero position)");
pr("\nAfter entering of user value press '+' to submit or '-' to reject it");
#undef pr
}
@ -467,6 +468,10 @@ int parce_incoming_buf(char *buf, int len, sendfun s){
if(mode != BYTE_MODE) return 0;
OW_fill_next_ID();
break;
case CMD_INIT_STATUS: // [q] - get init status
print_init_status();
do_echo = 0;
break;
case 'Q': // 1-wire scan OFF
OW_scan = 0;
break;
@ -522,6 +527,9 @@ int parce_incoming_buf(char *buf, int len, sendfun s){
get_motors_position();
do_echo = 0;
break;
case 'z':
forced_init();
break;
/*
case '_':
P("set: ", s);

View File

@ -96,6 +96,8 @@ void print_hex(uint8_t *buff, uint8_t l, sendfun s);
#define STR_EXTADC_INIT "i"
#define CMD_MOTORS_VOLTAGE 'p'
#define STR_MOTORS_VOLTAGE "p"
#define CMD_INIT_STATUS 'q'
#define STR_INIT_STATUS "q"
#define CMD_EXTADC_VALUES 's'
#define STR_EXTADC_VALUES "s"
#define CMD_SHTR_STATE 't'