Ejemplo n.º 1
0
/**************************************************************************//** 
 * @brief  DAC_setup
 * Configures the DAC
 *****************************************************************************/
void DAC_setup(void)
{
  /* Enable necessary clocks */
  CMU_ClockEnable(cmuClock_DAC0, true);

  /* Use default settings */
  DAC_Init_TypeDef init               = DAC_INIT_DEFAULT;
  DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT;
  
  /* Calculate the DAC clock prescaler value that will result in a DAC clock
   * close to 500kHz. Second parameter is zero, if the HFPERCLK value is 0, the
   * function will check what the current value actually is. */
  init.prescale = DAC_PrescaleCalc(500000, 0);
  /* Set reference voltage to Vdd */
  init.reference = dacRefVDD;
  
  /* Enable PRS triggered conversion (channel 5) */
  initChannel.prsEnable = true;
  initChannel.prsSel = dacPRSSELCh5;
  
  /* Initialize DAC and DAC channel 0 */
  DAC_Init(DAC0, &init);
  DAC_InitChannel(DAC0, &initChannel, 0);
  
  /* Enable DAC channel 0, located on pin PB11 */
  DAC_Enable(DAC0, 0, true);
}
Ejemplo n.º 2
0
void analogout_init(dac_t *obj, PinName pin)
{
    /* init in-memory structure */
    obj->dac = (DAC_TypeDef *) pinmap_peripheral(pin, PinMap_DAC);
    MBED_ASSERT((int) obj->dac != NC);

    obj->channel = pin_location(pin, PinMap_DAC);
    MBED_ASSERT((int) obj->channel != NC);
    
    pin_mode(pin, Disabled);

    if (!dac_initialized) {
        /* Initialize the DAC. Will disable both DAC channels, so should only be done once */
        /* Use default settings */
        CMU_ClockEnable(cmuClock_DAC0, true);

        DAC_Init_TypeDef init = DAC_INIT_DEFAULT;

        /* Calculate the DAC clock prescaler value that will result in a DAC clock
         * close to 500kHz. Second parameter is zero. This uses the current HFPERCLK
         * frequency instead of setting a new one. */
        init.prescale = DAC_PrescaleCalc(500000, REFERENCE_FREQUENCY);

        /* Set reference voltage to VDD */
        init.reference = dacRefVDD;

        DAC_Init(obj->dac, &init);
        dac_initialized = 1;
    }
    /* Use default channel settings */
    DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT;
    initChannel.enable = true;
    DAC_InitChannel(obj->dac, &initChannel, obj->channel);
}
Ejemplo n.º 3
0
void analogout_init(dac_t *obj, PinName pin)
{
    static uint8_t dac_initialized = 0;

    /* init in-memory structure */
    analogout_preinit(obj, pin);

    if (!dac_initialized) {
        /* Initialize the DAC. Will disable both DAC channels, so should only be done once */
        /* Use default settings */
        CMU_ClockEnable(cmuClock_DAC0, true);

        DAC_Init_TypeDef init = DAC_INIT_DEFAULT;

        /* Calculate the DAC clock prescaler value that will result in a DAC clock
         * close to 500kHz. Second parameter is zero. This uses the current HFPERCLK
         * frequency instead of setting a new one. */
        init.prescale = DAC_PrescaleCalc(500000, REFERENCE_FREQUENCY);

        /* Set reference voltage to VDD */
        init.reference = dacRefVDD;

        DAC_Init(obj->dac, &init);
        dac_initialized = 1;
    }
    /* Use default channel settings */
    DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT;
    DAC_InitChannel(obj->dac, &initChannel, obj->channel);


}
Ejemplo n.º 4
0
void DAC_setup(void)
{
  /* Define DAC settings */
  DAC_Init_TypeDef init =  
  { 
    dacRefresh8,              /* Refresh every 8 prescaled cycles. */    \
    dacRef1V25,               /* 1.25V internal reference. */            \
    dacOutputPinADC,          /* Output to pin and ADC. */               \
    dacConvModeContinuous,    /* Continuous mode. */                     \
    0,                        /* No prescaling. */                       \
    false,                    /* Do not enable low pass filter. */       \
    false,                    /* Do not reset prescaler on ch0 start. */ \
    false,                    /* DAC output enable always on. */         \
    false,                    /* Disable sine mode. */                   \
    false                     /* Single ended mode. */                   \
  };
  
  DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT;

  /* Calculate the DAC clock prescaler value that will result in a DAC clock
   * close to 500kHz. Second parameter is zero, if the HFPERCLK value is 0, the
   * function will check what the current value actually is. */
  init.prescale = DAC_PrescaleCalc(500000, 0);

  /* Set reference voltage to vdd.*/
  init.reference = dacRefVDD;

  /* Initialize the DAC and DAC channel. */
  DAC_Init(DAC0, &init);
  
  /*Initialize DAC channel 0.*/
  DAC_InitChannel(DAC0, &initChannel, 0);
  
}
Ejemplo n.º 5
0
/**************************************************************************//**
 * @brief  Setup DAC
 * Configures and starts the DAC
 *****************************************************************************/
void DAC_setup(void)
{
  /* Use default settings */
  DAC_Init_TypeDef        init        = DAC_INIT_DEFAULT;
  DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT;

  /* Enable the DAC clock */
  CMU_ClockEnable(cmuClock_DAC0, true);

  /* Calculate the DAC clock prescaler value that will result in a DAC clock
   * close to 500kHz. Second parameter is zero, if the HFPERCLK value is 0, the
   * function will check what the current value actually is. */
  init.prescale = DAC_PrescaleCalc(500000, 0);

  /* Set reference voltage to 1.25V */
  init.reference = dacRef1V25;

  /* Set output mode for DAC such that the DAC can produce output to both
   * pin and ADC. */
  init.outMode = dacOutputPinADC;

  /* Initialize the DAC and DAC channel. */
  DAC_Init(DAC0, &init);
  DAC_InitChannel(DAC0, &initChannel, 0);
}