找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2970|回复: 6
打印 上一主题 下一主题
收起左侧

基于TMS320F28027的微弱电压测量源程序与Proteus仿真

[复制链接]
跳转到指定楼层
楼主
基于TMS320F28027芯片的微弱电压信号测量,熟练掌握DSP开发环境CCS软件以及Proteus电路设计软件,掌握微弱电压的测量方式,掌握TMS320F28027芯片的基本IO操作、中断方式、ADC功能的使用,进一步了解DSP系统的特点。
  • 方案论证:
基于TMS320F28027芯片的微弱电压信号测量方案包括如下几部分:
  • 微弱电压转换电路
为了便于对微弱电压(2*(10-3)*sin(100pi*t))进行测量,设计运算放大电路对微弱电压进行放大处理,使得电压变为0~3.2V,电路设计如下:
电压计算公式:Vout=Rf/R*(u11-u12);
(2)基于TMS320F28027的电压信号采集及转换
TMS320F28027的ADC功能:
1.12位双采样保持电路。
2.同时采样和序列采样方式。
3.全范围电压输入,0V到3.3V固定,或者VREFLO到VREFHI可调。
4.系统时钟全频运行,无需分频。
5.16输入通道。
6.16个SOC配置,设置触发,采样窗口,通道。
7.16个独立保存转换结果的结果寄存器。
8.多触发源。
9.9个灵活的PIE中断
ADC采集电压计算公式如下:
Vol=(AdcResult.ADCRESULT0)/4096*3.3;
(3)电压的动态显示
测量到电压后进行显示,本次实验采用LM016L型号LCD显示器进行电压显示。
引脚接口说明:
第1脚:VSS为地电源。
第2脚:VDD接5V正电源。
第3脚:VL为液晶显示器对比度调整端,接正电源时对比度最弱,接地时对比度最高。
第4脚:RS为寄存器选择,高电平时选择数据寄存器、低电平时选择指令寄存器。
第5脚:R/W为读写信号线,高电平时进行读操作,低电平时进行写操作。当RS和R/W共同为低电平时可以写入指令或者显示地址,当RS为低电平R/W为高电平时可以读忙信号,当RS为高电平R/W为低电平时可以写入数据。
第6脚:E端为使能端,当E端由高电平跳变成低电平时,液晶模块执行命令。
第7~14脚:D0~D7为8位双向数据线。
LM016L接线如下所示:
指令如下所示:
序号
指令
RS
R/W
D7
D6
D5
D4
D3
D2
D1
D0
1
清显示
0
0
0
0
0
0
0
0
0
1
2
光标返回
0
0
0
0
0
0
0
0
1
*
3
置输入模式
0
0
0
0
0
0
0
1
I/D
S
4
显示开/关控制
0
0
0
0
0
0
1
D
C
B
5
光标或字符移位
0
0
0
0
0
1
S/C
R/L
*
*
6
置功能
0
0
0
0
1
DL
N
F
*
*
7
置字符发生存贮器地址
0
0
0
1
字符发生存贮器地址
8
置数据存贮器地址
0
0
1
显示数据存贮器地址
9
读忙标志或地址
0
1
BF
计数器地址
10
写数到CGRAM或DDRAM)
1
0
要写的数据内容
11
从CGRAM或DDRAM读数
1
1
读出的数据内容

芯片时序表如下:
读状态
输入
RS=L,R/W=H,E=H
输出
D0—D7=状态字
写指令
输入
RS=L,R/W=L,D0—D7=指令码,E=高脉冲
输出
读数据
输入
RS=H,R/W=H,E=H
输出
D0—D7=数据
写数据
输入
RS=H,R/W=L,D0—D7=数据,E=高脉冲
输出
  • 系统设计:
  • 系统框图
(2)程序流程图
  • 电路及程序
电路设计如下:
程序如下所示:
  1. #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

  2. // Prototype statements for functions found within this file.
  3. interrupt void adc_isr(void);
  4. void Gpio_select(void);
  5. void IOint();
  6. void CMDWrite(unsigned char cm );
  7. void DataWrite(unsigned char dt);
  8. void lcdinit();
  9. // Global variables used in this example:
  10. //Uint16 LoopCount;
  11. //Uint16 ConversionCount;
  12. //Uint16 TempSensorVoltage[10];
  13. Uint32 Volage=0;
  14. double vol=0;
  15. int16 bit1[3]={0};
  16. Uint16 flag=0;
  17. unsigned data='0';
  18. void main()
  19. {

  20. // Step 1. Initialize System Control:
  21. // PLL, WatchDog, enable Peripheral Clocks
  22. // This example function is found in the DSP2802x_SysCtrl.c file.
  23.    InitSysCtrl();

  24.    Gpio_select();
  25. // Step 2. Initialize GPIO:
  26. // This example function is found in the DSP2802x_Gpio.c file and
  27. // illustrates how to set the GPIO to it's default state.
  28. // InitGpio();  // Skipped for this example

  29. // Step 3. Clear all interrupts and initialize PIE vector table:
  30. // Disable CPU interrupts
  31.    DINT;

  32. // Initialize the PIE control registers to their default state.
  33. // The default state is all PIE interrupts disabled and flags
  34. // are cleared.
  35. // This function is found in the DSP2802x_PieCtrl.c file.
  36.    InitPieCtrl();

  37. // Disable CPU interrupts and clear all CPU interrupt flags:
  38.    IER = 0x0000;
  39.    IFR = 0x0000;

  40. // Initialize the PIE vector table with pointers to the shell Interrupt
  41. // Service Routines (ISR).
  42. // This will populate the entire table, even if the interrupt
  43. // is not used in this example.  This is useful for debug purposes.
  44. // The shell ISR routines are found in DSP2802x_DefaultIsr.c.
  45. // This function is found in DSP2802x_PieVect.c.
  46.    InitPieVectTable();

  47. // Interrupts that are used in this example are re-mapped to
  48. // ISR functions found within this file.
  49.    EALLOW;  // This is needed to write to EALLOW protected register
  50.    PieVectTable.ADCINT1 = &adc_isr;
  51.    EDIS;    // This is needed to disable write to EALLOW protected registers

  52. // Step 4. Initialize the ADC:
  53. // This function is found in DSP2802x_Adc.c
  54.    InitAdc();  // For this example, init the ADC

  55. // Step 5. Configure ADC to sample the temperature sensor on ADCIN5:
  56. // The output of Piccolo temperature sensor can be internally connected to the ADC through ADCINA5
  57. // via the TEMPCONV bit in the ADCCTL1 register. When this bit is set, any voltage applied to the external
  58. // ADCIN5 pin is ignored.
  59.               //EALLOW;
  60.               //AdcRegs.ADCCTL1.bit.TEMPCONV               = 1;              //Connect internal temp sensor to channel ADCINA5.
  61.               //EDIS;

  62. // Step 6. Continue configuring ADC to sample the temperature sensor on ADCIN5:
  63. // Since the temperature sensor is connected to ADCIN5, configure the ADC to sample channel ADCIN5
  64. // as well as the ADC SOC trigger and ADCINTs preferred. This example uses EPWM1A to trigger the ADC
  65. // to start a conversion and trips ADCINT1 at the end of the conversion.
  66.               EALLOW;
  67.               AdcRegs.ADCCTL1.bit.INTPULSEPOS              = 1;              //ADCINT1 trips after AdcResults latch
  68.               AdcRegs.ADCCTL1.bit.ADCBGPWD=1;
  69.               AdcRegs.ADCCTL1.bit.ADCPWDN=1;
  70.               AdcRegs.ADCCTL1.bit.ADCENABLE=1;
  71.               AdcRegs.ADCCTL1.bit.ADCREFSEL=0;
  72.               EDIS;
  73.               //DELAY_US(ADC_usDELAY);

  74.               EALLOW;
  75.               AdcRegs.INTSEL1N2.bit.INT1E     = 1;              //Enabled ADCINT1
  76.               //AdcRegs.INTSEL1N2.bit.INT1CONT  = 0;              //Disable ADCINT1 Continuous mode
  77.               //AdcRegs.INTSEL1N2.bit.INT1SEL              = 0;              //setup EOC0 to trigger ADCINT1 to fire
  78.               AdcRegs.ADCSOC0CTL.bit.CHSEL               = 0;              //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
  79.               AdcRegs.ADCSOC0CTL.bit.TRIGSEL               = 5;              //set SOC0 start trigger on EPWM1A
  80.               AdcRegs.ADCSOC0CTL.bit.ACQPS               = 6;              //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
  81.               EDIS;


  82. // Step 7. User specific code, enable interrupts:

  83. // Enable ADCINT1 in PIE
  84.    PieCtrlRegs.PIEIER1.bit.INTx1 = 1;              // Enable INT 1.1 in the PIE
  85.    IER |= M_INT1;                                                                                     // Enable CPU Interrupt 1
  86.    EINT;                                                                                              // Enable Global interrupt INTM
  87.    ERTM;                                                                                              // Enable Global realtime interrupt DBGM

  88.   // LoopCount = 0;
  89.    //ConversionCount = 0;


  90. // Assumes ePWM1 clock is already enabled in InitSysCtrl();
  91.    EPwm1Regs.ETSEL.bit.SOCAEN              = 1;                            // Enable SOC on A group
  92.    EPwm1Regs.ETSEL.bit.SOCASEL              = 4;                            // Select SOC from from CPMA on upcount
  93.    EPwm1Regs.ETPS.bit.SOCAPRD               = 1;                            // Generate pulse on 1st event
  94.    EPwm1Regs.CMPA.half.CMPA               = 0x0080;              // Set compare A value
  95.    EPwm1Regs.TBPRD                                                         = 0xFFFF;              // Set period for ePWM1
  96.    EPwm1Regs.TBCTL.bit.CTRMODE               = 0;                            // count up and start



  97. // Wait for ADC interrupt
  98.    IOint();
  99.    lcdinit();
  100.    //DataWrite(1);

  101.    for(;;)
  102.    {

  103.        if(flag==1)
  104.        {
  105.           flag=0;
  106.           CMDWrite(0x80);

  107.           if(bit1[0]>0)
  108.           {
  109.               DataWrite('+');
  110.               DataWrite('0');
  111.               DataWrite('.');
  112.               DataWrite('0');
  113.               DataWrite('0');
  114.               DataWrite(abs(bit1[2])+'0');
  115.               DataWrite(abs(bit1[1])+'0');
  116.               DataWrite(abs(bit1[0])+'0');
  117.           }
  118.           else
  119.           {
  120.               DataWrite('-');
  121.               DataWrite('0');
  122.             DataWrite('.');
  123.             DataWrite('0');
  124.             DataWrite('0');
  125.             DataWrite(abs(bit1[2])+'0');
  126.             DataWrite(abs(bit1[1])+'0');
  127.             DataWrite(abs(bit1[0])+'0');

  128.           }

  129.        }

  130.    }

  131. }


  132. interrupt void  adc_isr(void)
  133. {

  134.   //TempSensorVoltage[ConversionCount] = AdcResult.ADCRESULT0;
  135.   Volage= AdcResult.ADCRESULT0;
  136.   vol=(3.3/4096*Volage+1.6)/800-0.004;

  137.   bit1[0] = ((int32)(vol*100000))%10;
  138.   bit1[1] = ((int32)(vol*10000))%10;
  139.   bit1[2] = ((int32)(vol*1000))%10;

  140.   AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;                            //Clear ADCINT1 flag reinitialize for next SOC
  141.   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;   // Acknowledge interrupt to PIE
  142.   flag=1;
  143.   return;
  144. }

  145. void Gpio_select(void)
  146. {


  147.     EALLOW;
  148.     GpioCtrlRegs.GPAMUX1.all = 0x00000000;  // All GPIO
  149.     GpioCtrlRegs.GPAMUX2.all = 0x00000000;  // All GPIO
  150.     GpioCtrlRegs.GPAMUX1.all = 0x00000000;  // All GPIO
  151.     GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF;   // All outputs
  152.     GpioCtrlRegs.GPBDIR.all = 0x0000000F;   // All outputs
  153.     EDIS;

  154. }

  155. void IOint()
  156. {
  157.        EALLOW;

  158.       GpioCtrlRegs.GPAPUD.all=0;
  159.       GpioDataRegs.GPASET.all=1;
  160.       GpioCtrlRegs.GPAMUX1.all=0;
  161.       GpioCtrlRegs.GPADIR.all=0;

  162.      GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;   // Enable pullup on GPIO6  //RS
  163.      GpioDataRegs.GPBSET.bit.GPIO32= 1;   // Load output latch
  164.      GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 0;  // GPIO6 = GPIO6
  165.      GpioCtrlRegs.GPBDIR.bit.GPIO32 = 1;

  166.      GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;   // Enable pullup on GPIO6  //RW
  167.       GpioDataRegs.GPBSET.bit.GPIO33= 1;   // Load output latch
  168.       GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 0;  // GPIO6 = GPIO6
  169.       GpioCtrlRegs.GPBDIR.bit.GPIO33 = 1;

  170.       GpioCtrlRegs.GPBPUD.bit.GPIO34 = 0;   // Enable pullup on GPIO6   //E
  171.       GpioDataRegs.GPBSET.bit.GPIO34= 1;   // Load output latch
  172.       GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;  // GPIO6 = GPIO6
  173.       GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;

  174.        EDIS;
  175. }

  176. void CMDWrite(unsigned char cm )
  177. {

  178.     GpioDataRegs.GPBDAT.bit.GPIO32=0;
  179.     GpioDataRegs.GPADAT.all=cm;
  180.     DELAY_US(2);
  181.      GpioDataRegs.GPBDAT.bit.GPIO34=1;
  182.      DELAY_US(2);
  183.      GpioDataRegs.GPBDAT.bit.GPIO34=0;

  184. }
  185. void DataWrite(unsigned char dt)
  186. {

  187.     GpioDataRegs.GPBDAT.bit.GPIO32=1;
  188.     GpioDataRegs.GPADAT.all=dt;
  189.     DELAY_US(2);
  190.     GpioDataRegs.GPBDAT.bit.GPIO34=1;
  191.     DELAY_US(2);
  192.     GpioDataRegs.GPBDAT.bit.GPIO34=0;
  193. }
  194. void lcdinit()
  195. {
  196.     GpioDataRegs.GPBDAT.bit.GPIO33=0;
  197.     GpioDataRegs.GPBDAT.bit.GPIO34=0;

  198.     CMDWrite(0x38);
  199.     CMDWrite(0x06);
  200.     CMDWrite(0x0c);


  201. }
复制代码

  • 仿真结果(附件)
在Proteus软件进行仿真,仿真结果截图如下:
   LCD显示小数点后5位,输入正弦电压幅值为0.002,显示精度为百分之一。


全部资料51hei下载地址:
Proteus仿真与ccs代码.7z (5.99 MB, 下载次数: 90)
基于TMS320F28027的微弱电压测量.doc (453.5 KB, 下载次数: 35)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:326044 发表于 2022-11-2 20:02 | 只看该作者
软件不全,能发全吗
回复

使用道具 举报

板凳
ID:894794 发表于 2023-5-5 11:41 | 只看该作者
资料很全,很好谢谢楼主
回复

使用道具 举报

地板
ID:1074206 发表于 2023-5-16 22:45 | 只看该作者
protuse竟然可以仿真DSP,666
回复

使用道具 举报

5#
ID:420836 发表于 2023-5-17 08:58 | 只看该作者
如果测量的电压非常小,低至几毫伏,则可以使用仪器级运算放大器。
回复

使用道具 举报

6#
ID:899981 发表于 2023-10-16 16:14 | 只看该作者
281523048 发表于 2023-5-5 11:41
资料很全,很好谢谢楼主

您好,能否把能编译工程发一下,谢谢。
回复

使用道具 举报

7#
ID:899981 发表于 2023-10-16 16:27 | 只看该作者
您好,这个例程很好,能否给个能编译的整套源码?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表