Ejemplo n.º 1
0
static void
get_adc_config (uint32_t config[4])
{
  config[2] = ADC_SQR1_NUM_CH(2);
  switch (SYS_BOARD_ID)
    {
    case BOARD_ID_FST_01:
      config[0] = 0;
      config[1] = ADC_SMPR2_SMP_AN0(ADC_SAMPLE_1P5)
		| ADC_SMPR2_SMP_AN9(ADC_SAMPLE_1P5);
      config[3] = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN0)
		| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN9);
      break;

    case BOARD_ID_OLIMEX_STM32_H103:
    case BOARD_ID_STBEE:
      config[0] = ADC_SMPR1_SMP_AN10(ADC_SAMPLE_1P5)
		| ADC_SMPR1_SMP_AN11(ADC_SAMPLE_1P5);
      config[1] = 0;
      config[3] = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN10)
		| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN11);
      break;

    case BOARD_ID_STBEE_MINI:
      config[0] = 0;
      config[1] = ADC_SMPR2_SMP_AN1(ADC_SAMPLE_1P5)
		| ADC_SMPR2_SMP_AN2(ADC_SAMPLE_1P5);
      config[3] = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN1)
		| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN2);
      break;

    case BOARD_ID_CQ_STARM:
    case BOARD_ID_FST_01_00:
    case BOARD_ID_MAPLE_MINI:
    case BOARD_ID_STM32_PRIMER2:
    case BOARD_ID_STM8S_DISCOVERY:
    case BOARD_ID_ST_DONGLE:
    case BOARD_ID_ST_NUCLEO_F103:
    case BOARD_ID_NITROKEY_START:
    default:
      config[0] = 0;
      config[1] = ADC_SMPR2_SMP_AN0(ADC_SAMPLE_1P5)
		| ADC_SMPR2_SMP_AN1(ADC_SAMPLE_1P5);
      config[3] = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN0)
		| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN1);
      break;
    }
}
Ejemplo n.º 2
0
  ADC_GRP1_NUM_CHANNELS,
  NULL,
  adcerrorcallback,
  .u.adc = {
    0,                      /* CR1      */
    ADC_CR2_SWSTART,        /* CR2      */
    0,                      /* LTR      */
    0,                      /* HTR      */
    {                       /* SMPR[2]  */
      0,
      ADC_SMPR2_SMP_AN9(ADC_SAMPLE_41P5) | ADC_SMPR2_SMP_AN1(ADC_SAMPLE_41P5),
    },
    {                       /* SQR[3]   */
      0,
      0,
      ADC_SQR3_SQ2_N(ADC_CHANNEL_IN9) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN1)
    }
  }
};

/*
 * ADC conversion group.
 * Mode:        Continuous, 16 samples of 8 channels, SW triggered.
 * Channels:    IN1, IN9, IN1, IN9, IN1, IN9, VBat, Sensor.
 */
static const ADCConversionGroup adcgrpcfg2 = {
  TRUE,
  ADC_GRP2_NUM_CHANNELS,
  adccallback,
  adcerrorcallback,
  .u.adc = {
Ejemplo n.º 3
0
  ADC_CR2_SWSTART,          /* CR2 */
  ADC_SMPR1_SMP_AN10(ADC_SAMPLE_3) |
    ADC_SMPR1_SMP_AN11(ADC_SAMPLE_3) |
    ADC_SMPR1_SMP_AN12(ADC_SAMPLE_3) |
    ADC_SMPR1_SMP_AN13(ADC_SAMPLE_3) |
    ADC_SMPR1_SMP_AN14(ADC_SAMPLE_3) |
    ADC_SMPR1_SMP_AN15(ADC_SAMPLE_3),
  0,                        /* SMPR2 */
  ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS),
  0,
  ADC_SQR3_SQ6_N(ADC_AN33_2)          |
    ADC_SQR3_SQ5_N(ADC_AN33_1)        |
    ADC_SQR3_SQ4_N(ADC_AN33_0)        |
    ADC_SQR3_SQ3_N(ADC_6V_SUPPLY)     |
    ADC_SQR3_SQ2_N(ADC_MAIN_SUPPLY)   |
    ADC_SQR3_SQ1_N(ADC_CURRENT_SENS)
};

static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) {
  (void)adcp;
  (void)err;

  osalSysHalt("");
}

static void adccallback(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
  (void)adcp;
  (void)buffer;
  (void)n;
  ints++;
}
Ejemplo n.º 4
0
      // Please, refer to ST manual RM0008.pdf to understand what we do.
      // CR1 register content, set to zero for begin
      0,
      // CR2 register content, set to zero for begin
      0,
      // SMRP1 register content, channels 10, 11, 12, 13 to 71.5 cycles
      0xB6D,
      // SMRP2 register content, channels 0, 1, 2, 3 to 71.5 cycles
      0xB6D,
      // SQR1 register content. Set channel sequence length
      ADC_SQR1_NUM_CH(ADC_CH_NUM),
      // SQR2 register content, set to zero for begin
      (ADC_SQR2_SQ7_N(ADC_CHANNEL_IN10) |
       ADC_SQR2_SQ8_N(ADC_CHANNEL_IN11)),
      // SQR3 register content. First 6 channels
      (ADC_SQR3_SQ1_N(ADC_CHANNEL_IN0 ) |
       ADC_SQR3_SQ2_N(ADC_CHANNEL_IN1 ) |
       ADC_SQR3_SQ3_N(ADC_CHANNEL_IN2 ) |
       ADC_SQR3_SQ4_N(ADC_CHANNEL_IN3 ) |
       ADC_SQR3_SQ5_N(ADC_CHANNEL_IN12) |
       ADC_SQR3_SQ6_N(ADC_CHANNEL_IN13)),
};

/*-----------------------------------------------------------------------------*/
/** @brief      Initialize the ADC1 sub system                                 */
/*-----------------------------------------------------------------------------*/

void
vexAdcInit()
{
    // Init and start ADC1
Ejemplo n.º 5
0
static const ADCConversionGroup core_temp_conv_grp = {
    .circular = FALSE,
    .num_channels = 1,
    .end_cb = NULL,
    .error_cb = NULL,

    /* HW dependent part.*/
    .cr1   = 0, // 12-bit resolution
    .cr2   = ADC_CR2_SWSTART, // software triggered
    .smpr1 = ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_480),
    .smpr2 = 0,
    .sqr1  = ADC_SQR1_NUM_CH(1),
    .sqr2  = 0,
    .sqr3  = ADC_SQR3_SQ1_N(ADC_CHANNEL_SENSOR),
};


/**
 * @brief   PAL setup.
 * @details Digital I/O ports static configuration as defined in @p board.h.
 *          This variable is used by the HAL when initializing the PAL driver.
 */
#if HAL_USE_PAL || defined(__DOXYGEN__)
const PALConfig pal_default_config =
{
  {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR, VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH},
  {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR, VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH},
  {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR, VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH},
  {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR, VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH},
Ejemplo n.º 6
0
static const ADCConversionGroup adc_grpcfg = {
		TRUE,
		ADC_NUM_CHANNELS,
		NULL,
		NULL,
		0, /* CR1 */
		ADC_CR2_SWSTART, /* CR2 */
		ADC_SMPR1_SMP_AN15(ADC_SAMPLE_144) | ADC_SMPR1_SMP_AN14(ADC_SAMPLE_144)
				| ADC_SMPR1_SMP_AN12(ADC_SAMPLE_144)
				| ADC_SMPR1_SMP_AN11(ADC_SAMPLE_144),  /* SMPR1 */
		0, /* SMPR2 */
		ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS),
		0, /* SQR2 */
		ADC_SQR3_SQ4_N(ADC_CHANNEL_IN15) | ADC_SQR3_SQ3_N(ADC_CHANNEL_IN14)
				| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN12)
				| ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11) };

static WORKING_AREA(irWorkingArea, 1024);

/* ICU callbacks and data to be used with sonars */

/* Thread used for read data from sonar */
static msg_t irThread(void *arg) {
	(void) arg;
	char buf[40];

	/*
	 * Activates the ADC1 driver.
	 */
	adcStart(&ADCD1, NULL);
	adcStartConversion(&ADCD1, &adc_grpcfg, (adcsample_t *)&ir_data, ADC_BUF_DEPTH);
Ejemplo n.º 7
0
/*===========================================================================*/
/* Driver local variables.                                                   */
/*===========================================================================*/

static const TouchscreenDriver *ts;

static const ADCConversionGroup adc_y_config = {
    FALSE,
    ADC_NUM_CHANNELS,
    NULL,
    NULL,
    0, 0,                       
    0, 0,                      
    ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS),
    0,                        
    ADC_SQR3_SQ2_N(ADC_CHANNEL_IN12) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN13)
};

static const ADCConversionGroup adc_x_config = {
    FALSE,
    ADC_NUM_CHANNELS,
    NULL,
    NULL,
    0, 0,
    0, 0,
    ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS),
    0,
    ADC_SQR3_SQ2_N(ADC_CHANNEL_IN10) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)
};

/**
Ejemplo n.º 8
0
/*
  capture VRSSI in mV
 */
uint16_t adc_sample_vrssi(void)
{
    const uint32_t channel = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN5);
    return adc_sample_channel(channel) * 9900 / 4096;
}
Ejemplo n.º 9
0
 * ADC conversion group.
 * Mode:        Linear buffer, 1 sample of 1 channel, SW triggered.
 * Channels:    IN11.
 */
static const ADCConversionGroup adcgrpcfg1 = {
  FALSE,
  PRESSURE_ADC_NUM_CHANNELS,
  NULL,
  adcerrorcallback,
  0,                        /* CR1 */
  ADC_CR2_SWSTART,          /* CR2 */
  ADC_SMPR1_SMP_AN14(ADC_SAMPLE_480),
  0,                        /* SMPR2 */
  ADC_SQR1_NUM_CH(PRESSURE_ADC_NUM_CHANNELS),
  0,                        /* SQR2 */
  ADC_SQR3_SQ1_N(ADC_PRESSURE_CHANNEL)
};

//The PWM configuration for the solenoid control
static PWMConfig PWM_Config_Solenoid = {
  1000000,                                  			/* 1MHz PWM clock frequency. */
  250,                                  			/* Initial PWM period 4KHz. */
  NULL,								/* No cyclic callback */
  {
   {PWM_OUTPUT_ACTIVE_HIGH, NULL},				/* Have to define the channel to enable here - channel 1=solenoid*/
   {PWM_OUTPUT_DISABLED, NULL},
   {PWM_OUTPUT_DISABLED, NULL},
   {PWM_OUTPUT_DISABLED, NULL}
  },
  0,
};
Ejemplo n.º 10
0
/* Instrument conversion group */
static const ADCConversionGroup adc_con_group_1 = {
    TRUE, /* circular mode */
    1, /* number of channels in this con_group */
    adc_inst_callback,
    adc_error_callback,
    0, /* ADC_CR1 */
    /* cr2: Clock the ADC to timer 8 TRGO event*/
    ADC_CR2_EXTSEL_SRC(14) | ADC_CR2_EXTEN_0,
    /* smpr1+2: set all channels to 40 cycles per conversion (28+12) */
    ADC_SMPR1_SMP_AN11(2)| ADC_SMPR1_SMP_AN12(2)| ADC_SMPR1_SMP_AN13(2),
    ADC_SMPR2_SMP_AN0(2) | ADC_SMPR2_SMP_AN1(2) | ADC_SMPR2_SMP_AN2(2),
    ADC_SQR1_NUM_CH(1), /* sqr1: set 1 channel in the group */
    0, /* sqr2: no higher channels being sampled */
    /* sqr3: set the two channels to sample */
    ADC_SQR3_SQ1_N(INST_IN_CHN)
};

/* FX inputs conversion group */
static const ADCConversionGroup adc_con_group_2 = {
    TRUE, /* circular mode */
    3, /* number of channels in this con group */
    adc_fx_callback,
    adc_error_callback,
    0, /* cr1 */
    /* cr2: Clock the ADC to timer 3 TRGO event*/
    ADC_CR2_EXTSEL_SRC(8) | ADC_CR2_EXTEN_0,
    /* smpr1+2: set all channels to 40 cycles per conversion (28+12) */
    ADC_SMPR1_SMP_AN11(2)| ADC_SMPR1_SMP_AN12(2)| ADC_SMPR1_SMP_AN13(2),
    ADC_SMPR2_SMP_AN0(2) | ADC_SMPR2_SMP_AN1(2) | ADC_SMPR2_SMP_AN2(2),
    ADC_SQR1_NUM_CH(3), /* sqr1: set 3 channels in the group */
Ejemplo n.º 11
0
* ADC conversion group.
* Mode:        Linear buffer, 8 samples of 1 channel, SW triggered.
* Channels:    IN15 = PC5 = Morpho Nucleo CN10-pin 6.
*/
static const ADCConversionGroup adcgrpcfg1 = {
  FALSE,                                 // circular buffer mode
  ADC_GRP1_NUM_CHANNELS,                 // Number of the analog channels
  NULL,                                  // Callback function (not needed here)
  NULL,                                // Error callback
  0,                                     // CR1
  ADC_CR2_SWSTART,                       // CR2
  ADC_SMPR2_SMP_AN0(ADC_SAMPLE_3),      // sample times ch10-18
  0,                                     // sample times ch0-9
  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),// SQR1: Conversion group sequence 13...16 + sequence length
  0,                                     // SQR2: Conversion group sequence 7...12
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN0)       // SQR3: Conversion group sequence 1...6
};

int main(void) { 

  halInit(); 
  chSysInit();
    
/*
  * ADC init
  */
  palSetPadMode(GPIOA, 0, PAL_MODE_INPUT_ANALOG);
  adcStart(&ADCD1, NULL); 

  /* 
   * Activates the serial driver 2 using the driver default configuration: 
Ejemplo n.º 12
0
 */
static const ADCConversionGroup adcgrpcfg = {
  TRUE,                 /* Circular buffer mode enabled.    */
  ADC_GRP_NUM_CHANNELS, /* Number of channels in the group. */
  adccb,                /* Callback function of the group.  */
  NULL,                 /* Error callback function.         */
  /* STM32F1xx dependent part: */
  0,                                      /* CR1.   */
  0,                                      /* CR2.   */
  ADC_SMPR1_SMP_AN12(ADC_SAMPLE_239P5) |
  ADC_SMPR1_SMP_AN13(ADC_SAMPLE_239P5),   /* SMPR1. */
  0,                                      /* SMPR2. */
  ADC_SQR1_NUM_CH(ADC_GRP_NUM_CHANNELS),  /* SQR1.  */
  0,                                      /* SQR2.  */
  ADC_SQR3_SQ2_N(ADC_CHANNEL_IN13) |
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN12)        /* SQR3.  */
};

/**
 * Input capture configuration for ICU2 driver.
 *
 * @note ICU drivers used in the firmware are modified ChibiOS
 *       drivers for extended input capture functionality.
 */
static const ICUConfig icucfg2 = {
  ICU_INPUT_TYPE_PWM,       /* Driver input type (EDGE, PULSE, PWM).  */
  1000000,                  /* 1MHz ICU clock frequency.              */
  {                         /* ICU channel configuration.             */
    {ICU_INPUT_DISABLED, NULL},           /* CH1 */
    {ICU_INPUT_ACTIVE_HIGH, icuwidthcb},  /* CH2 */
    {ICU_INPUT_DISABLED, NULL},           /* CH3 */
Ejemplo n.º 13
0
static const ADCConversionGroup adc_grp = {
    .circular = false,
    .num_channels = 5,
    .end_cb = NULL,
    .error_cb = NULL,
    .cr1 = 0,
    .cr2 = ADC_CR2_SWSTART,
    .smpr1 = ADC_SMPR1_SMP_AN11(ADC_SAMPLE_480) |
             ADC_SMPR1_SMP_AN13(ADC_SAMPLE_480),
    .smpr2 = ADC_SMPR2_SMP_AN1(ADC_SAMPLE_480) |
             ADC_SMPR2_SMP_AN2(ADC_SAMPLE_480) |
             ADC_SMPR2_SMP_AN8(ADC_SAMPLE_480),
    .sqr1 = ADC_SQR1_NUM_CH(5),
    .sqr2 = 0,
    .sqr3 = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN2)  |
            ADC_SQR3_SQ2_N(ADC_CHANNEL_IN1)  |
            ADC_SQR3_SQ3_N(ADC_CHANNEL_IN11) |
            ADC_SQR3_SQ4_N(ADC_CHANNEL_IN13) |
            ADC_SQR3_SQ5_N(ADC_CHANNEL_IN8),
};

/* 12bit ADC reading of PYRO_CONTINUITY into 2ohm/LSB uint8t */
static uint8_t adc_to_resistance(adcsample_t reading) {
    float r = 0.5 * (1000.0f * (float)reading) / (4096.0f - (float)reading);
    if(r >= 255.0f) {
        return 255;
    } else {
        return (uint8_t)r;
    }
}
Ejemplo n.º 14
0
	NULL
};

static const ADCConversionGroup adcgrp1cfg5 = {
	FALSE,
	ADC_GRP1_NUM_CHANNELS,
	adccb1,
	NULL,
	/* HW dependent part.*/
	0,
	ADC_CR2_SWSTART,
	0,
	ADC_SMPR2_SMP_AN5(ADC_SAMPLE_56),
	ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
	0,
	ADC_SQR3_SQ1_N(ADC_CHANNEL_IN5)
};

static const ADCConversionGroup adcgrp1cfg4 = {
	FALSE,
	ADC_GRP1_NUM_CHANNELS,
	adccb2,
	NULL,
	/* HW dependent part.*/
	0,
	ADC_CR2_SWSTART,
	0,
	ADC_SMPR2_SMP_AN4(ADC_SAMPLE_56),
	ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
	0,
	ADC_SQR3_SQ1_N(ADC_CHANNEL_IN4)
Ejemplo n.º 15
0
 * Mode:        Continuous, 16 samples of 2 channels, HS triggered by
 *              GPT4-TRGO.
 * Channels:    Sensor, VRef.
 */
static const ADCConversionGroup adcgrpcfg1 = {
    true,
    ADC_GRP1_NUM_CHANNELS,
    adccallback,
    adcerrorcallback,
    0,                                                    /* CR1 */
    ADC_CR2_EXTEN_RISING | ADC_CR2_EXTSEL_SRC(12),        /* CR2 */
    ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_144) | ADC_SMPR1_SMP_VREF(ADC_SAMPLE_144),
    0,                                                    /* SMPR2 */
    ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),               /* SQR1 */
    0,                                                    /* SQR1 */
    ADC_SQR3_SQ2_N(ADC_CHANNEL_SENSOR) | ADC_SQR3_SQ1_N(ADC_CHANNEL_VREFINT)
};

/*===========================================================================*/
/* Application code.                                                         */
/*===========================================================================*/

/*
 * This is a periodic thread that does absolutely nothing except flashing
 * a LED attached to TP1.
 */
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {

    (void)arg;
    chRegSetThreadName("blinker");
Ejemplo n.º 16
0
//				| ADC_SQR3_SQ6_N(ADC_CHANNEL_IN9) /* PB1 - white */
// Conversion group sequence 1...6
		};

static const ADCConversionGroup adcgrpcfg_fast = { FALSE, ADC_NUMBER_CHANNELS_FAST, adc_callback_fast, NULL,
/* HW dependent part.*/
ADC_TwoSamplingDelay_5Cycles,   // cr1
		ADC_CR2_SWSTART, // cr2

		0, // sample times for channels 10...18
		ADC_SMPR2_SMP_AN0(MY_SAMPLING_FAST), // In this field must be specified the sample times for channels 0...9

		ADC_SQR1_NUM_CH(ADC_NUMBER_CHANNELS_FAST), // Conversion group sequence 13...16 + sequence length

		0, // Conversion group sequence 7...12
		0 | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN3) /* PA3 */
// maf		| ADC_SQR3_SQ1_N(ADC_CHANNEL_IN13) /* PC3 */

		// Conversion group sequence 1...6
		};

static void pwmpcb_slow(PWMDriver *pwmp) {
#ifdef EFI_INTERNAL_ADC
	(void) pwmp;

	/* Starts an asynchronous ADC conversion operation, the conversion
	 will be executed in parallel to the current PWM cycle and will
	 terminate before the next PWM cycle.*/chSysLockFromIsr()
	;
	adcStartConversionI(&ADC_SLOW, &adcgrpcfg_slow, slowAdcState.samples, ADC_GRP1_BUF_DEPTH_SLOW);
	chSysUnlockFromIsr()
Ejemplo n.º 17
0
 * Channels:    IN11   (48 cycles sample time)
 *              Sensor (192 cycles sample time)
 */
static const ADCConversionGroup adcgrpcfg = {
  FALSE,
  ADC_GRP1_NUM_CHANNELS,
  adccb,
  NULL,
  /* HW dependent part.*/
  0,
  ADC_CR2_SWSTART,
  ADC_SMPR1_SMP_AN11(ADC_SAMPLE_56) | ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_144),
  0,
  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
  0,
  ADC_SQR3_SQ2_N(ADC_CHANNEL_IN11) | ADC_SQR3_SQ1_N(ADC_CHANNEL_SENSOR)
};

/*
 * PWM configuration structure.
 * Cyclic callback enabled, channels 1 and 4 enabled without callbacks,
 * the active state is a logic one.
 */
static PWMConfig pwmcfg = {
  10000,                                    /* 10KHz PWM clock frequency.   */
  10000,                                    /* PWM period 1S (in ticks).    */
  pwmpcb,
  {
    {PWM_OUTPUT_ACTIVE_HIGH, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
Ejemplo n.º 18
0
static const ADCConversionGroup adcgrpcfg1 = {FALSE,      //circular buffer mode
    ADC_GRP1_NUM_CHANNELS,        //Number of the analog channels
    NULL,                         //Callback function (not needed here)
    0,             //Error callback
    0, /* CR1 */
    ADC_CR2_SWSTART, /* CR2 */
    ADC_SMPR1_SMP_AN10(ADC_SAMPLE_84) | ADC_SMPR1_SMP_AN11(ADC_SAMPLE_84)
        | ADC_SMPR1_SMP_AN12(ADC_SAMPLE_84) | ADC_SMPR1_SMP_AN13(ADC_SAMPLE_84)
        | ADC_SMPR1_SMP_AN14(ADC_SAMPLE_84) | ADC_SMPR1_SMP_AN15(ADC_SAMPLE_84), //sample times ch10-18
    ADC_SMPR2_SMP_AN0(ADC_SAMPLE_84) | ADC_SMPR2_SMP_AN1(ADC_SAMPLE_84)
        | ADC_SMPR2_SMP_AN2(ADC_SAMPLE_84) | ADC_SMPR2_SMP_AN3(ADC_SAMPLE_84)
        | ADC_SMPR2_SMP_AN4(ADC_SAMPLE_84) | ADC_SMPR2_SMP_AN5(ADC_SAMPLE_84)
        | ADC_SMPR2_SMP_AN6(ADC_SAMPLE_84) | ADC_SMPR2_SMP_AN7(ADC_SAMPLE_84)
        | ADC_SMPR2_SMP_AN8(ADC_SAMPLE_84) | ADC_SMPR2_SMP_AN9(ADC_SAMPLE_84), //sample times ch0-9
    ADC_SQR1_SQ13_N(ADC_CHANNEL_IN12) | ADC_SQR1_SQ14_N(ADC_CHANNEL_IN13)
        | ADC_SQR1_SQ15_N(ADC_CHANNEL_IN14) | ADC_SQR1_SQ16_N(ADC_CHANNEL_IN15)
        | ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS), //SQR1: Conversion group sequence 13...16 + sequence length
    ADC_SQR2_SQ7_N(ADC_CHANNEL_IN6) | ADC_SQR2_SQ8_N(ADC_CHANNEL_IN7)
        | ADC_SQR2_SQ9_N(ADC_CHANNEL_IN8) | ADC_SQR2_SQ10_N(ADC_CHANNEL_IN9)
        | ADC_SQR2_SQ11_N(ADC_CHANNEL_IN10) | ADC_SQR2_SQ12_N(ADC_CHANNEL_IN11), //SQR2: Conversion group sequence 7...12
    ADC_SQR3_SQ1_N(ADC_CHANNEL_IN0) | ADC_SQR3_SQ2_N(ADC_CHANNEL_IN1)
        | ADC_SQR3_SQ3_N(ADC_CHANNEL_IN2) | ADC_SQR3_SQ4_N(ADC_CHANNEL_IN3)
        | ADC_SQR3_SQ5_N(ADC_CHANNEL_IN4) | ADC_SQR3_SQ6_N(ADC_CHANNEL_IN5) //SQR3: Conversion group sequence 1...6
};

void adc_convert(void) {
  adcStopConversion(&ADCD1);
  adcStartConversion(&ADCD1, &adcgrpcfg1, adcvalues, ADC_GRP1_BUF_DEPTH);
}

Ejemplo n.º 19
0
/*
 * ADC conversion group.
 * Mode:        Linear buffer, 8 samples of 1 channel, SW triggered.
 * Channels:    IN10.
 */
static const ADCConversionGroup adcgrpcfg1 = {
  FALSE,
  ADC_GRP1_NUM_CHANNELS,
  NULL,
  adcerrorcallback,
  0, 0,                         /* CR1, CR2 */
  ADC_SMPR1_SMP_AN10(ADC_SAMPLE_1P5),
  0,                            /* SMPR2 */
  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
  0,                            /* SQR2 */
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN10)
};

/*
 * ADC conversion group.
 * Mode:        Continuous, 16 samples of 8 channels, SW triggered.
 * Channels:    IN10, IN11, IN10, IN11, IN10, IN11, Sensor, VRef.
 */
static const ADCConversionGroup adcgrpcfg2 = {
  TRUE,
  ADC_GRP2_NUM_CHANNELS,
  adccallback,
  adcerrorcallback,
  0, ADC_CR2_TSVREFE,           /* CR1, CR2 */
  ADC_SMPR1_SMP_AN11(ADC_SAMPLE_41P5) | ADC_SMPR1_SMP_AN10(ADC_SAMPLE_41P5) |
  ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_239P5) | ADC_SMPR1_SMP_VREF(ADC_SAMPLE_239P5),
Ejemplo n.º 20
0
  ADC_ADC3_NUM_CHANNELS, //num_channels
  adccallback, // end_conversion_cb
  adcerrorcallback, //error_cb
  0,                        /* CR1 */ 
  ADC_CR2_SWSTART,          /* CR2 */ 

  ADC_SMPR1_SMP_AN14(ADC_OVERSAMPLING) | ADC_SMPR1_SMP_AN15(ADC_OVERSAMPLING), // SMPR1

  ADC_SMPR2_SMP_AN4(ADC_OVERSAMPLING) | ADC_SMPR2_SMP_AN5(ADC_OVERSAMPLING) | /* SMPR2 */ 
  ADC_SMPR2_SMP_AN6(ADC_OVERSAMPLING) | ADC_SMPR2_SMP_AN7(ADC_OVERSAMPLING) | /* SMPR2 */ 
  ADC_SMPR2_SMP_AN9(ADC_OVERSAMPLING),  /* SMPR2 */ 

  ADC_SQR1_NUM_CH(ADC_ADC3_NUM_CHANNELS), // SQR1

  0,					  //SQR2
  ADC_SQR3_SQ1_N(GPIOF_ADC_CMD_TURRET_CHANNEL) |	//SQR3
  ADC_SQR3_SQ2_N(GPIOF_ADC_CMD_ELBOW_CHANNEL) |		//SQR3
  ADC_SQR3_SQ3_N(GPIOF_ADC_CMD_SHOULDER_CHANNEL)   | 	//SQR3
  ADC_SQR3_SQ4_N(GPIOF_ADC_CMD_WRIST_CHANNEL) | 	//SQR3
  ADC_SQR3_SQ5_N(GPIOF_ADC_CMD_CLAMP_CHANNEL)	        //SQR3
};

#ifndef __COVERITY__
_Static_assert(CMD_TURRET_ADC_IDX == 3, "ADC mismatch");
_Static_assert(CMD_SHOULDER_ADC_IDX == 3, "ADC mismatch");
_Static_assert(CMD_ELBOW_ADC_IDX == 3, "ADC mismatch");
_Static_assert(CMD_WRIST_ADC_IDX == 3, "ADC mismatch");
_Static_assert(CMD_CLAMP_ADC_IDX == 3, "ADC mismatch");
#endif

#else
Ejemplo n.º 21
0
Archivo: adc_local.c Proyecto: mcu786/u
  adccallback,
  adcerrorcallback,
  0,                        /* CR1 */
  ADC_CR2_SWSTART,          /* CR2 */
  ADC_SMPR1_SMP_AN10(ADC_SAMPLE_480) |
  ADC_SMPR1_SMP_AN11(ADC_SAMPLE_480) |
  ADC_SMPR1_SMP_AN12(ADC_SAMPLE_480) |
  ADC_SMPR1_SMP_AN13(ADC_SAMPLE_480) |
  ADC_SMPR1_SMP_AN14(ADC_SAMPLE_480) |
  ADC_SMPR1_SMP_AN15(ADC_SAMPLE_480),
  0,                        /* SMPR2 */
  ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS),
  0,
  (ADC_SQR3_SQ6_N(ADC_AN33_2)         | ADC_SQR3_SQ5_N(ADC_AN33_1) |
      ADC_SQR3_SQ4_N(ADC_AN33_0)      | ADC_SQR3_SQ3_N(ADC_6V_SUPPLY) |
      ADC_SQR3_SQ2_N(ADC_MAIN_SUPPLY) | ADC_SQR3_SQ1_N(ADC_CURRENT_SENS))
};

/*
 *******************************************************************************
 *******************************************************************************
 * LOCAL FUNCTIONS
 *******************************************************************************
 *******************************************************************************
 */

/* пересчет из условных единиц АЦП в mV */
uint16_t get_comp_secondary_voltage(uint16_t raw){
  uint32_t v = 6200; // такое количество милливольт
  uint32_t adc = 770;// приходится на такое количество условных единиц
  return (uint16_t)(((uint32_t)raw * v) / adc);
Ejemplo n.º 22
0
namespace r2p {

/*===========================================================================*/
/* Motor calibration.                                                        */
/*===========================================================================*/

static int pwm = 0;

#define ADC_NUM_CHANNELS  1
#define ADC_BUF_DEPTH     1

static float meanLevel = 0.0f;

static adcsample_t adc_samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];

static void current_callback(ADCDriver *adcp, adcsample_t *buffer, size_t n);

/*
 * ADC conversion group.
 * Mode:        Circular buffer, 1 sample of 1 channel, triggered by pwm channel 3
 * Channels:    IN10.
 */
static const ADCConversionGroup adcgrpcfg = { TRUE, // circular
		ADC_NUM_CHANNELS, // num channels
		current_callback, // end callback
		NULL, // error callback
		0, // CR1
		ADC_CR2_EXTTRIG | ADC_CR2_EXTSEL_1, // CR2
		0, // SMPR1
		ADC_SMPR2_SMP_AN3(ADC_SAMPLE_1P5)/*ADC_SMPR2_SMP_AN3(ADC_SAMPLE_239P5)*/, // SMPR2
		ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), // SQR1
		0, // SQR2
		ADC_SQR3_SQ1_N(ADC_CHANNEL_IN3) // SQR3
		};

static void current_callback(ADCDriver *adcp, adcsample_t *buffer, size_t n) {

	(void) adcp;
	(void) n;

	palTogglePad(LED2_GPIO, LED2);

	chSysLockFromIsr()
	;

	meanLevel = buffer[0];

	if (tp_motor != NULL) {
		chSchReadyI(tp_motor);
		tp_motor = NULL;
	}

	chSysUnlockFromIsr();

}


static PWMConfig pwmcfg = { STM32_SYSCLK, // 72MHz PWM clock frequency.
		4096, // 12-bit PWM, 17KHz frequency.
		NULL, // pwm callback
		{
				{ PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, NULL }, //
				{ PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, NULL }, //
				{ PWM_OUTPUT_ACTIVE_LOW, NULL }, //
				{ PWM_OUTPUT_DISABLED, NULL } }, //
				0, //
#if STM32_PWM_USE_ADVANCED
		72, /* XXX 1uS deadtime insertion   */
#endif
		0 };

static calibration_pub_node_conf defaultPubConf = { "motor_calibration_node",
		"bits" };

msg_t motor_calibration_node(void * arg) {
	//Configure current node
	calibration_pub_node_conf* conf;
	if (arg != NULL)
		conf = (calibration_pub_node_conf *) arg;
	else
		conf = &defaultPubConf;

	Node node(conf->name);
	Publisher<FloatMsg> current_pub;
	FloatMsg * msgp;

	chRegSetThreadName(conf->name);

	node.advertise(current_pub, conf->topic);

	// Start the ADC driver and conversion
	adcStart(&ADC_DRIVER, NULL);
	adcStartConversion(&ADC_DRIVER, &adcgrpcfg, adc_samples, ADC_BUF_DEPTH);

	// Init motor driver
	palSetPad(DRIVER_GPIO, DRIVER_RESET);
	chThdSleepMilliseconds(500);
	pwmStart(&PWM_DRIVER, &pwmcfg);

	// wait some time
	chThdSleepMilliseconds(500);

	// start pwm
	float voltage = 24.0;

	const float pwm_res = 4096.0f / 24.0f;
	pwm = static_cast<int>(voltage * pwm_res);

	if (pwm > 0) {
		pwm_lld_enable_channel(&PWM_DRIVER, 1, pwm);
		pwm_lld_enable_channel(&PWM_DRIVER, 0, 0);

		pwm_lld_enable_channel(&PWM_DRIVER, 2, pwm/2);
	} else {
		pwm_lld_enable_channel(&PWM_DRIVER, 1, 0);
		pwm_lld_enable_channel(&PWM_DRIVER, 0, -pwm);

		pwm_lld_enable_channel(&PWM_DRIVER, 2, -pwm/2);
	}

	// Start publishing current measures
	for (;;) {
		// Wait for interrupt
		chSysLock()
		;
		tp_motor = chThdSelf();
		chSchGoSleepS(THD_STATE_SUSPENDED);
		chSysUnlock();

		// publish current
		if (current_pub.alloc(msgp)) {
			msgp->value = meanLevel;
			current_pub.publish(*msgp);
		}

	}

	return CH_SUCCESS;
}

}