当前位置:网站首页>Stm32h750vbt6 drives programmable gain amplifier module pga113 -- Hal Library Based on cubemx
Stm32h750vbt6 drives programmable gain amplifier module pga113 -- Hal Library Based on cubemx
2022-07-24 07:11:00 【W_ oilpicture】
Preface
Gao Qing has chased xiaoyunkong , Don't dream with pear flowers .
lately , Because of the need to prepare for the video game , A programmable gain amplifier module is needed (PGA113), That is, the protagonist of this blog : Brother Po ( Homophonic address ), We need to get through this big brother , Today, I finally finished the driver code . Speaking of tune PGA113 The process of this big brother , It's really a little emotional .
Originally, this module was a gain amplification module that another team needed to do the first game preparation project , They bought chips ( Why buy chips ? Because the module is too expensive , Can't afford to buy . Here is the purchase link of Taobao module :https://item.taobao.com/item.htm?id=673514214019, I recommend buying a module first , After you understand it, buy a chip and make it yourself , Don't be like us , Directly bought sixorseven chips , As a result, almost no one can adjust it , The boss can do it according to his own ideas ), And then weld the circuit by yourself , Make modules , As a result, the students in charge of software in their team couldn't be transferred , Then we started “ Politely refuse ” link , Final adjustment PGA113 The task falls on me .
Fortunately, it was finally adjusted , Because there are not many materials that can be found on the Internet , Just watch it slowly according to a chip manual , It's still in English , A hundred words of roast are omitted here , I don't say much nonsense , Let's share .
One 、 Introduce
- Introduction to chip manual :pga113 Chip manual .pdf
brief introduction
PGAyesPmgrammable Gain AmplifierThe English name of , Chinese meaning Programmable gain amplifier .PGAIt is a very versatile amplifier , Its magnification can be controlled by program according to needs . Use this amplifier , The magnification can be adjusted by program , sendA/DThe full-scale signal of the converter is homogenized , Therefore, the measurement accuracy is greatly improved .
Applications :
- Remote electrometer reading
- Automatic gain control
- Portable data acquisition
Manual catalog :

SPI Sequence diagram


Gain control range selection :

The most important part :SPI command


- All we need to do here is SPI Configure to :
Transmit Only MasterMode is enough , We don't need toPGA113Data transmission to single chip microcomputer ; - Remember to write instructions Hexadecimal Express :
0x2a00(0x0010 1010 0000 0000),
0010 1010: Express Write (write) Pattern ;
first 0000: Indicates gain magnification ;
the second 0000: Indicates the number of channels selected ,( The passage used here 0, The module we designed does not use channels 1, Because the first version uses channels 0, Useless channel 1, The second version is changed , The fact proved that : Use channel 0 It's still more effective , There is an initial effect that will double the magnification (Bug))
Let's introduce our protagonist (PGA113):


- Wiring diagram :( So here I'm going to use theta
SPI1, Software selection :CS, useDACOutput1.5 VThe reference voltage of )
| STM32H750VBT6 Single chip microcomputer | PGA113 modular |
|---|---|
PA4(DAC1_OUT ) | VREF |
GND | GND |
PA5(SPI1_SCK) | SCLK |
PA7(SPI1_MOSI) | DIO |
PC4(SPI1_CS) | CS |
Two 、 New project
1、 Conduct CubeMX To configure
Turn on the clock :

Configure clock tree :

Turn on DAC:

SPI To configure :

The generated code :


- The above is done CubeMX The process of generating code .
3、 ... and 、 Code writing
- stay
main.cAdd the following code to the file :
/* USER CODE BEGIN PTD */
// Define the gain array
uint16_t gainBuffer[8]={
0x2a00,0x2a10,0x2a20,0x2a30,
0x2a40,0x2a50,0x2a60,0x2a70 };
// Corresponding to system amplification :
// Corresponding array subscript :0, 1, 2, 3, 4, 5, 6, 7
// Binary gain :1, 2, 4, 8,16,32, 64,128
// Gain range :1, 2, 5,10,20,50,100,200
//CS Chip selection low level is effective enable , CS Chip selection high level is not enabled
#define SPI_CS_Enable() HAL_GPIO_WritePin(GPIOC,SPI1_CS_Pin,GPIO_PIN_RESET)
#define SPI_CS_Disable() HAL_GPIO_WritePin(GPIOC,SPI1_CS_Pin,GPIO_PIN_SET)
/* USER CODE END PTD */
// Define function control gain magnification
void SetGain(int gain)
{
uint8_t gtemp=0;
switch(gain)
{
case 1:
gtemp=0;
break;
case 2:
gtemp=1;
break;
case 5:
gtemp=2;
break;
case 10:
gtemp=3;
break;
case 20:
gtemp=4;
break;
case 50:
gtemp=5;
break;
case 100:
gtemp=6;
break;
case 200:
gtemp=7;
break;
}
SPI_CS_Enable();
HAL_SPI_Transmit(&hspi1, (uint8_t *)gainBuffer+gtemp*2, 1, 0xffff);
SPI_CS_Disable();
}
/* USER CODE BEGIN 2 */
PrintfUart("wang_test\r\n");
// start-up DAC converter
HAL_DAC_Start(&hdac1,DAC1_CHANNEL_1);
// Voltage conversion : utilize DAC Output 1.5V The voltage of , As a reference voltage (VREF)
HAL_DAC_SetValue(&hdac1, DAC1_CHANNEL_1, DAC_ALIGN_8B_R, 116);
SetGain(50);
PrintfUart("Over\r\n");
/* USER CODE END 2 */
Four 、 experimental result


End of sharing , In fact, it's not particularly difficult to finish writing , Just pay attention to some details , for example : Don't write the hexadecimal format of the command incorrectly (8+2=a, No 6)、 And convert hexadecimal to octal , These two parts are what hurt me when I wrote the driver , Remind people of .
The above is the sharing content of this blog , If it helps you , Please give me a little praise , thank you !!!
边栏推荐
- Use the root user to create a new user and set the password for
- PyTorch 深度学习实践 第10讲/作业(Basic CNN)
- Prediction of advertising investment and sales based on regression analysis -- K neighborhood, decision tree, random forest, linear regression, ridge regression
- 【Tips】创建版本控制项目的简单方法
- C language from entry to soil (I)
- Prompt for garbled code when CHM file is opened
- C language to achieve three chess? Gobang? No, it's n-chess
- Take you to learn C step by step (second)
- QoS服务质量四QoS边界行为之流量监管
- Part II - C language improvement_ 1. Overview of C language
猜你喜欢

Redis persistence

Take you to learn C step by step (second)

聚合型新生态模式-分享购,会员及奖励制度

单场GMV翻了100倍,冷门品牌崛起背后的“通用法则”是什么?

One book a day: machine learning and practice -- the road to the kaggle competition from scratch

STM32 external interrupt (register version)

Ue4/5 cannot open the file "xxx.generated.h" (cannot open file xxx.generated.h) solution summary

xavier_ normal_ Initialization test

一日一书:机器学习及实践——从零开始通往kaggle竞赛之路
![[C language] operator details (in-depth understanding + sorting and classification)](/img/0a/e726126f6a55590d5ae73c49757cdb.png)
[C language] operator details (in-depth understanding + sorting and classification)
随机推荐
C language from entry to soil (II)
Tensorflow Einstein function
[C language] operator details (in-depth understanding + sorting and classification)
变量和数据类型(03)
You are you, and no one can replace you
Part II - C language improvement_ 1. Overview of C language
Mongodb application scenario and model selection (massive data storage model selection)
Part II - C language improvement_ 4. Secondary pointer
C language from introduction to soil -- super detailed summary of operators
Vs2019 configuration running open3d example
B. Also Try Minecraft
Huawei experts' self statement: how to become an excellent engineer
JMeter笔记2 | JMeter原理及测试计划要素
Redis persistence
Never lose yourself!
"Big factory interview" JVM Chapter 21 questions and answers
聚合型新生态模式-分享购,会员及奖励制度
Variables and data types (03)
owasp top10 渗透测试
【行测】图形找规律类题目