2242 views|0 replies

1140

Posts

0

Resources
The OP
 

MSP430F169 MCU DAC12 [Copy link]

  • Hardware Introduction:
    MSP430x14x series does not contain DAC12 module, so the implementation in this article can only be used in 16 series and other microcontrollers with DAC12 module.
    The DAC12 module of MSP430F169 microcontroller has 2 DAC channels, which are completely equal in operation. And the DAC12GRP control bit can be used to combine multiple DAC12 channels to achieve synchronous update, and the hardware can also ensure that the synchronous update is independent of any interrupt or NMI event.
    This DAC12 module has the following features: 8-bit or 12-bit adjustable resolution, programmable time-to-energy loss, optional internal or external reference source, support for binary original code and complement code input, self-checking function, multiple DACs can be updated synchronously, and DMA can be used.
    Here is a relatively simplified version, you need to add or rewrite functions by yourself, such as: calling the self-checking function inside the initialization function, and self-checking can be performed every time it is initialized.
    Each module of DAC12 has only two registers: control register and data register. The control register is used to initialize and set the use of the module, and the data register is used to store the digital voltage to be output. The registers of the DAC of 169 are as follows: DAC12_0 control register DAC12_0CTL DAC12_0 data register DAC12_0DAT DAC12_1 control register DAC12_1CTL DAC12_1 data register DAC12_1DAT
    The function of each bit of the control register is as follows:
    DAC12REFx: Select the reference source of DAC12 0, 1 Vref+ 2, 3 Veref+ DAC12RES: Select DAC12 resolution 0 12-bit resolution 1 8-bit resolution DAC12LSELx: Latch trigger source selection When the DAC12 latch is triggered, the data in the latch can be transferred to the core of DAC12. When DAC12LSELx=0, DAC data update is not affected by DAC12ENC. 0 DAC12_XDAT write operation will trigger (regardless of DAC12ENC status) 1 DAC12_XDAT write operation will trigger (consider DAC12ENC status) 2 Rising edge of Timer_A3.OUT1 3 Rising edge of Timer_B7.OUT2 DAC12CALON: DAC12 calibration operation control starts calibration operation after setting, and is automatically reset after calibration is completed. Calibration operation can correct offset error. 0 No calibration operation started 1 Start calibration operation DAC12IR: DAC12 input range sets the relationship between input reference voltage and output 0 The full scale of DAC12 is 3 times the reference voltage (AVcc is not operated) 1 The full scale of DAC12 is the reference voltage DAC12AMPx: DAC12 operational amplifier setting 0 Input buffer off, output buffer off, high impedance 1 Input buffer off, output buffer off, 0V 2 Input buffer low speed low current, output buffer low speed low current 3 Input buffer low speed low current, output buffer medium speed medium current 4 Input buffer low speed low current, output buffer high speed high current 5 Input buffer medium speed medium current, output buffer medium speed medium current 6 Input buffer medium speed medium current, output buffer high speed high current 7 Input buffer high speed high current, output buffer high speed high current DAC12DF: DAC12 data format 0 Binary 1 Twos complement DAC12IE: DAC12 interrupt enable 0 Disable interrupt 1 Enable interrupt DAC12IFG: DAC12 interrupt flag 0 No interrupt request 1 DAC12ENC: DAC12 conversion control bit DAC12LSEL>0, DAC12ENC is valid. 0 DAC12 stop 1 DAC12 conversion DAC12GRP: DAC12 combination control bit 0 No combination 1 Combination
    For detailed information about DAC12, please refer to the user guide provided by TI. : The program for the DAC12 module is relatively simple, because each group has only one register for control; the functions implemented by this program are as follows: DAC module initialization, completing the initialization of two DAC modules, you can determine which module to initialize or both of them according to the parameters, or update a group of two at the same time; use parameters to pass the value of DAC12AMPx for easy setting, the program has very detailed comments, if you don't understand, you can directly set AMPx to 5 or 0x05; calibration function, completing the self-calibration of the DAC12 module, also through the parameter passing the module to be calibrated; voltage output function, this also uses parameters to pass the module to be output.
    Initialization:
    /************************************************************* Function name: DAC12Init* Function: Initialize the related resources used by DAC12* Parameters: * module module 0: Use module DAC12_0* 1: Use module DAC12_1* 2:Use module DAC12_0/1* 3: Use module DAC12_0/1 to update together* DAC12AMPx: DAC operational amplifier settings:* 0 Input buffer off, output buffer off, high impedance* 1 Input buffer off, output buffer off, 0V* 2 Input buffer low speed/current, output buffer low speed/current* 3 Input buffer low speed/current, output buffer medium speed/current* 4 Input buffer low speed/current, output buffer high speed/current* 5 Input buffer medium speed/current, output buffer medium speed/current* 6 Input buffer medium speed/current, output buffer high speed/current* 7 Input buffer high speed/current, output buffer high speed/current* Return value: char, 1 is returned if the setting is successful, and 0 is returned if the parameter is wrong* Note: Other defaults are: 12-bit scheme, write and update output, when module* is 3, both are written and updated; the full scale of DAC12 is the reference voltage* voltage; internal 2.5v reference voltage: AD needs to set the reference source to open 2.5.************************************************************/char DAC12Init(char module,char DAC12AMPx){ if(DAC12AMPx>7) { return(0); } //---------------------------Set module------------------------------- switch(module) { case 0:case'0': DAC12_0Init(DAC12AMPx); break; //Module 0 case 1:case'1': DAC12_1Init(DAC12AMPx); break; //Module 1 case 2:case'2': DAC12_0Init(DAC12AMPx); DAC12_1Init(DAC12AMPx); break; //Module 0, 1 case 3:case'3': DAC12_0Init(DAC12AMPx); DAC12_1Init(DAC12AMPx); DAC12_0CTL |= DAC12GRP; break; //No checkdefault : return(0); //Parameter error} return (1);}
    Here, if the parameter is invalid, it returns 0, and if the setting is completed, it returns 1. However, it should be noted that before using the DAC, the internal reference source must be turned on (in the ADC module, please refer to the usage example for details). The contents of DAC12_0Init and DAC12_1Init functions are the same, except that the control registers are DAC12_0CTL and DAC12_0CTL respectively. Only the function of DAC12_0Init is given here. Another reference source program: void DAC12_0Init(char DAC12AMPx){ // Internal ref gain 1 DAC12_0CTL = DAC12SREF_0 + DAC12IR; DAC12_0CTL |= DAC12LSEL_1 + (DAC12AMPx << 5); DAC12_0CTL |= DAC12ENC;}
    This function only completes the setting of the control register. Select the internal reference source, the output full scale is 1 times the reference voltage, the update method: write is update, if the group is set, both are written to update. Calibration function: Complete the self-calibration of DAC12 module, void DAC12Cal(char module){ switch(module) { case 0:case'0': DAC12_0CTL |= DAC12CALON; // Start verification DAC while((DAC12_0CTL & DAC12CALON) != 0); // Wait for verification to complete break; //Module 0 case 1:case'1': DAC12_1CTL |= DAC12CALON; // Start verification DAC while((DAC12_1CTL & DAC12CALON) != 0); // Wait for verification to complete break; //Module 1 case 2:case'2': case 3: case'3': DAC12_0CTL |= DAC12CALON; // Start verification of DAC while((DAC12_0CTL & DAC12CALON) != 0); // Wait for verification to complete DAC12_1CTL |= DAC12CALON; // Start verification DAC while((DAC12_1CTL & DAC12CALON) != 0); // Wait for verification to complete break; //Module 0, 1 default : return; //Parameter error}}
    The meaning of the parameters is the same as that of the previous initialization function, for consistency when using the function.
    Output function:
    void DAC12Out(char module,int out){ switch(module) { case 0:case'0': DAC12_0D AT=out; break; //Module 0 case 1:case'1': DAC12_1DAT=out; break; //Module 1 case 2:case'2': case 3:case'3': DAC12_0DAT=out; DAC12_1DAT=out; break; //Module 0, 1 default : return; //Parameter error}}
    The parameters of the output function have the same meaning as the initialized module parameters. This function is relatively simple. It just assigns the value to the DAT register according to the output value.
    There are so many DAC12 program libraries. DAC12 can also update data strictly according to time to output a waveform with a certain frequency. It can be set to update data on the rising edge of TA out1 or on the rising edge of TB out2. In addition, it can be used together with DMA to complete more complex functions; none of them are implemented here. If necessary, it can be implemented according to the register function.
    This is the end of the program part.
  • Usage Example:
    The usage here is still the same as the previous program. Just add the C file and include the H file. In addition, when using this program, you must turn on the internal AD reference source to provide reference voltage for the DAC12 module.
    void main( void ){ // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; ClkInit(); DAC12Init(3,5); //Initialize DAC12Cal(2); //Calibrate ADC12CTL0 = REF2_5V + REFON; //Turn on the internal reference source 2.5V, which is required for DA to use DAC12Out(2,0x666);}
    ADC12CTL0 = REF2_5V + REFON;This sentence turns on the reference voltage 2.5v for DA to use.
The program library of DAC12 module is here. If there is anything wrong, please feel free to criticize.
DAC12_0DAT=out; DAC12_1DAT=out; break; //Module 0, 1 default : return; //Parameter error}}
The parameters of the output function have the same meaning as the initialized module parameters. This function is relatively simple. It just assigns the DAT register according to the value to be output.
There are so many libraries for DAC12. DAC12 can also update data strictly according to time to output a waveform with a certain frequency. It can be set to update data on the rising edge of TA out1 or on the rising edge of TB out2. In addition, it can be used together with DMA to complete more complex functions; none of them are implemented here. If necessary, it can be implemented according to the register function.
This is the end of the program.
  • Example of use:
    The usage here is still the same as the previous program. Just add the C file and include the H file. In addition, when using this program, you must turn on the internal AD reference source to provide reference voltage for the DAC12 module.
    void main( void ){ // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; ClkInit(); DAC12Init(3,5); //Initialize DAC12Cal(2); //Calibrate ADC12CTL0 = REF2_5V + REFON; //Turn on the internal reference source 2.5V, which is required for DA to use DAC12Out(2,0x666);}
    ADC12CTL0 = REF2_5V + REFON;This sentence turns on the reference voltage 2.5v for DA to use.
    The program library of DAC12 module is here. If there is anything wrong, please feel free to criticize.
    DAC12_0DAT=out; DAC12_1DAT=out; break; //Module 0, 1 default : return; //Parameter error}}
    The parameters of the output function have the same meaning as the initialized module parameters. This function is relatively simple. It just assigns the DAT register according to the value to be output.
    There are so many libraries for DAC12. DAC12 can also update data strictly according to time to output a waveform with a certain frequency. It can be set to update data on the rising edge of TA out1 or on the rising edge of TB out2. In addition, it can be used together with DMA to complete more complex functions; none of them are implemented here. If necessary, it can be implemented according to the register function.
    This is the end of the program.
  • Example of use:
    The usage here is still the same as the previous program. Just add the C file and include the H file. In addition, when using this program, you must turn on the internal AD reference source to provide reference voltage for the DAC12 module.
    void main( void ){ // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; ClkInit(); DAC12Init(3,5); //Initialize DAC12Cal(2); //Calibrate ADC12CTL0 = REF2_5V + REFON; //Turn on the internal reference source 2.5V, which is required for DA to use DAC12Out(2,0x666);}
    ADC12CTL0 = REF2_5V + REFON;This sentence turns on the reference voltage 2.5v for DA to use.
    The program library of DAC12 module is here. If there is anything wrong, please feel free to criticize.

  • This post is from Microcontroller MCU
     

    Guess Your Favourite
    Just looking around
    Find a datasheet?

    EEWorld Datasheet Technical Support

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list