(225条消息) PE4302射频衰减器 程控衰减器 高线性衰减器 原理图和PCB_kvdz_taobao_com的博客-CSDN博客
PE4302最大功率衰减31.5dB。
P/S(模式选择) | LE(使能) | |
手动拨码 | 0 | 1 |
串行程控 | 1 | 1 |
靠近ON的一侧均为1.
GPIO设置:
pe43xx.h
#ifndef PE43xx_h
#define PE43xx_h#include "ytcesys.h"
#include "main.h"
// Define types of sensors.
#define PE4302 02
// untested as I don't own these
#define PE4306 06
#define PE4312 12void PE43xx_f( uint8_t type);
void begin();
int setLevel(float level);
void _writeLevel();
float getLevel();
float getMax();
float getStep();void PE43xx_init(uint8_t type,float level);
void PE43xx_changelevel(float level);#endif
pe43xx.c
#include "pe43xx.h"uint8_t _type;
float _max;
float _step;
float _level;//type写PE43xx (PE4302/PE4306/PE4312)void PE43xx_f( uint8_t type) {
// _pin_le = pin_le;
// _pin_clock = pin_clock;
// _pin_data = pin_data;_type = type;
}void begin() {// set our internal max and step valuesswitch (_type) {case PE4302:case PE4312:_max = 31.5;_step = 0.5;break;case PE4306:_max = 30;_step = 1;break;default:#warning type not certain, going with defaults, step=1 max=30_step = 1;_max = 30;break;}// set level to 0setLevel(0);
}int setLevel(float level) {// bounds checkif(level < 0 || level > getMax() ) {return 0;}_level = level;_writeLevel();return 1;
}void _writeLevel() {// PE4302 and PE4312 wants something like this//// C16 C8 C4 C2 C1 C0.5 => result// 0 0 0 0 0 0 => 0db// 0 0 0 0 0 1 => 0.5db// 0 0 1 1 0 1 => 6.5db// 1 1 1 1 1 1 => 31.5db// for PE4306 (which has only 1db resolution)//// C16 C8 C4 C2 C1 => result// 0 0 0 0 0 => 0db// 0 0 0 0 1 => 1db// 0 1 0 0 1 => 9db// 1 1 1 1 1 => 31db// so the big different is that one can set the .5 bit or not// get the integer part, it will be the same for both chipsint intlevel = _level;//_level==31.5...,int intlevel==31// default to 5 bitsint bits = 5;// if our step is less than 1 the chip supports the 0.5 decimalif(_step < 1) {// one more bitbits = 6;// if the decimal is not 0 shift 1 into our levelif( (_level*10 - intlevel*10) > 0) //有小数部分{intlevel = intlevel << 1;
// bitWrite(intlevel, 0, 1);intlevel+=1;} else {intlevel = intlevel << 1;
// bitWrite(intlevel, 0, 0);}}// LE and CLOCK down to get the chip listen
// digitalWrite(_pin_le, LOW);
// digitalWrite(_pin_clock,LOW);HAL_GPIO_WritePin(_pin_le_GPIO_Port, _pin_le_Pin, GPIO_PIN_RESET);HAL_GPIO_WritePin(_pin_clock_GPIO_Port, _pin_clock_Pin, GPIO_PIN_RESET);// Write the level out MSB firstint b;for (int bit = bits; bit > 0; bit--) {b = ((intlevel << 1) >> bit) & 0x01;HAL_GPIO_WritePin(_pin_data_GPIO_Port, _pin_data_Pin, b);HAL_GPIO_WritePin(_pin_clock_GPIO_Port, _pin_clock_Pin, GPIO_PIN_SET);HAL_GPIO_WritePin(_pin_clock_GPIO_Port, _pin_clock_Pin, GPIO_PIN_RESET);}// toggle LE to latch
// digitalWrite(_pin_le, HIGH); // Toggle LE high to enable latch
// digitalWrite(_pin_le, LOW); // and then low again to hold it.HAL_GPIO_WritePin(_pin_le_GPIO_Port, _pin_le_Pin, GPIO_PIN_SET);HAL_GPIO_WritePin(_pin_le_GPIO_Port, _pin_le_Pin, GPIO_PIN_RESET);
}// getters
float getLevel() {return _level;
}float getMax() {return _max;
}float getStep() {return _step;
}//main调用函数
void PE43xx_init(uint8_t type,float level)//第一次用
{PE43xx_f(type);begin();setLevel(level);}
void PE43xx_changelevel(float level)//非第一次用
{setLevel(level);}
main.c
PE43xx_init(PE4302,16);PE43xx_changelevel(10);
其中的level是功率的衰减。单位:dB
xxdB=20lg(Ua/Ub)