Skip to content

Commit

Permalink
add adt7420, update hmi. all basic function is working now
Browse files Browse the repository at this point in the history
  • Loading branch information
XuNeo committed Dec 31, 2019
1 parent 7487548 commit af39348
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 52 deletions.
7 changes: 4 additions & 3 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
{
"name": "Win32",
"includePath": [
"C:\\Users\\xxl\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**",
"C:\\Users\\xxl\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.4.2\\**",
"${workspaceFolder}/**"
"${workspaceFolder}/**",
"C:/Keil_v5/ARM/ARMCC/**",
"${workspaceFolder}/**",
"${workspaceFolder}/firmware/LCRMeter/3rdparty/FreeRTOS-Kernel/portable/RVDS/ARM_CM3"
],
"defines": [
"_DEBUG",
Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"hmi.h": "c",
"syslog.h": "c",
"ulog.h": "c",
"key.h": "c"
"key.h": "c",
"string": "c",
"adt7420.h": "c"
},
"cSpell.words": [
"peridically"
],
}
67 changes: 40 additions & 27 deletions src/MDK/AD5791Ref.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,12 @@
<SetRegEntry>
<Number>0</Number>
<Key>DLGUARM</Key>
<Name>燩#w惖J
燩#w惖J
</Name>
<Name></Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>JL2CM3</Key>
<Name>-U20500005 -O206 -S8 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F0xx_32.FLM -FS08000000 -FL08000 -FP0($$Device:STM32F070F6Px$CMSIS\Flash\STM32F0xx_32.FLM)</Name>
<Name>-U20500003 -O206 -S8 -ZTIFSpeedSel50000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F0xx_32.FLM -FS08000000 -FL08000 -FP0($$Device:STM32F070F6Px$CMSIS\Flash\STM32F0xx_32.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
Expand Down Expand Up @@ -160,24 +158,7 @@
<Name></Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>59</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134229052</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\app\ezled-host.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\ad5791_ref\../app/ezled-host.c\59</Expression>
</Bp>
</Breakpoint>
<Breakpoint/>
<WatchWindow1>
<Ww>
<count>0</count>
Expand Down Expand Up @@ -246,6 +227,14 @@
<pSingCmdsp></pSingCmdsp>
<pMultCmdsp></pMultCmdsp>
<SystemViewers>
<Entry>
<Name>System Viewer\GPIOF</Name>
<WinId>35903</WinId>
</Entry>
<Entry>
<Name>System Viewer\RCC</Name>
<WinId>35902</WinId>
</Entry>
<Entry>
<Name>System Viewer\TIM15</Name>
<WinId>35904</WinId>
Expand Down Expand Up @@ -727,6 +716,30 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>37</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\bsp\adt7420.c</PathWithFileName>
<FilenameWithoutPath>adt7420.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>38</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\bsp\i2c.c</PathWithFileName>
<FilenameWithoutPath>i2c.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>

<Group>
Expand All @@ -737,7 +750,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>5</GroupNumber>
<FileNumber>37</FileNumber>
<FileNumber>39</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -749,7 +762,7 @@
</File>
<File>
<GroupNumber>5</GroupNumber>
<FileNumber>38</FileNumber>
<FileNumber>40</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -761,7 +774,7 @@
</File>
<File>
<GroupNumber>5</GroupNumber>
<FileNumber>39</FileNumber>
<FileNumber>41</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -773,7 +786,7 @@
</File>
<File>
<GroupNumber>5</GroupNumber>
<FileNumber>40</FileNumber>
<FileNumber>42</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -785,7 +798,7 @@
</File>
<File>
<GroupNumber>5</GroupNumber>
<FileNumber>41</FileNumber>
<FileNumber>43</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand Down
12 changes: 11 additions & 1 deletion src/MDK/AD5791Ref.uvprojx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
<v6Rtti>0</v6Rtti>
<VariousControls>
<MiscControls>--preinclude ..\stm32f0xx_conf.h </MiscControls>
<Define>STM32F030,USE_STDPERIPH_DRIVER,M_PI=3.14159265358979f,__CLK_TCK=100</Define>
<Define>STM32F030,USE_STDPERIPH_DRIVER,M_PI=3.14159265358979f,__CLK_TCK=100,RT_USING_ULOG</Define>
<Undefine></Undefine>
<IncludePath>..\..\stm32f0xxlib\CMSIS\Device\ST\STM32F0xx\Include;..\..\stm32f0xxlib\STM32F0xx_StdPeriph_Driver\inc;..\..\src;..\..\src\app;..\..\src\bsp;..\printf;..\app\ulog-noos</IncludePath>
</VariousControls>
Expand Down Expand Up @@ -577,6 +577,16 @@
<FileType>1</FileType>
<FilePath>..\bsp\timer.c</FilePath>
</File>
<File>
<FileName>adt7420.c</FileName>
<FileType>1</FileType>
<FilePath>..\bsp\adt7420.c</FilePath>
</File>
<File>
<FileName>i2c.c</FileName>
<FileType>1</FileType>
<FilePath>..\bsp\i2c.c</FilePath>
</File>
</Files>
</Group>
<Group>
Expand Down
68 changes: 51 additions & 17 deletions src/app/hmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "printf.h"
#include "stdbool.h"
#include "ezled-host.h"
#include "ad5791.h"
#include "adt7420.h"

#define LOG_TAG "hmi"
#define LOG_LVL LOG_LVL_DBG
Expand All @@ -19,7 +21,7 @@ float voltref_set_value(float volt);
const char *setting_menu[]={
"1. sEt uOLt",
"2. sEt CODE",
"3. CAL",
"3. CAL rEF",
"4. sHO t",
};
const uint8_t cursor_range[][2]={
Expand All @@ -30,24 +32,30 @@ const uint8_t cursor_range[][2]={
{0xff, 0xff},
};

double volt_set=10.0, volt_disp=10.0f, volt_vref = 10.9f, board_temp=30.123;
uint32_t code_set=0x12345;
static double volt_set=10.0, volt_disp=10.0f, volt_vref = 10.9f;
static float board_temp=30.123;
static int32_t code_set=0x12345;

static int16_t main_menu = 0;
static int16_t sub_menu = 0;
static int16_t menu_level = 0; //0: root, 1: main menu, 2: sub menu
static uint16_t b_refresh_menu = 1;
static uint16_t menu_exit_count = 0;

#define MENU_LEVEL_ROOT 0 //root menu, used to display the real output voltage.
#define MENU_LEVEL_SHOW_MENU 1 //setting menu
#define MENU_LEVEL_SHOW_VALUE 2 //show the setting value
#define MENU_LEVEL_ADJ_VALUE 3 //adjust the setting value

void hmi_timer(void){
static uint16_t count_100ms = 0;
count_100ms ++;
if(count_100ms == 13){
count_100ms = 0;
LOG_D("swap volt display content\n");
b_refresh_menu = 1; //peridically refresh menu
menu_exit_count ++;
if(menu_exit_count == 60/2){ //6 second time out
menu_exit_count = 0;//exit menu automatically if no operation is made
if(menu_level == MENU_LEVEL_SHOW_MENU){
menu_level = MENU_LEVEL_ROOT;
b_refresh_menu = 1;
}
}
}

Expand All @@ -56,7 +64,7 @@ void hmi_init(void){
key_init();
//displed_init();
ezled_host_init((void(*)(char))disp_uart_char);
timer_register(hmi_timer, 100);
timer_register(hmi_timer, 200); //200 ms timer
}

static uint32_t ipow(uint32_t x, uint32_t y){
Expand Down Expand Up @@ -101,16 +109,21 @@ static void menu_refresh(void){
sprintf(buff, "s %.6fu", volt_set);
break;
case 1: //setting code
sprintf(buff, "0h %05x", code_set);
code_set = ad5791_get_code();
sprintf(buff, "0h %05X", code_set);
break;
case 2: //calibrate reference voltage.
if(volt_vref > 9.999999)
sprintf(buff, "r%.6fu", volt_vref);
else
sprintf(buff, "r %.6fu", volt_vref);
break;
case 3: //show temperature
sprintf(buff, "%.3f c", board_temp);
case 3:{ //show temperature
static uint8_t b_blink = 0;
if(adt7420_get_tmp(&board_temp))
b_blink = !b_blink;
sprintf(buff, "%.2f%c", board_temp, b_blink?' ':'c');
}
break;
default:
break;
Expand Down Expand Up @@ -139,17 +152,30 @@ static double float_adjust(double value, double max, int16_t encoder, int16_t po
double scale = 1e-6;
double delta = scale*ipow(10, 6-position)*encoder;
delta += value;
if(delta < max)
if(delta <= max)
value = delta;
if(value<0)
value = 0;
return value;
}


static int32_t hex5_adjust(int32_t value, uint32_t max, int16_t encoder, int16_t position){
if(position > 4) position = 4;
int32_t delta = ipow(16, 4-position)*encoder;
delta += value;
if(delta <= max)
value = delta;
if(value<0)
value = 0;
return value;
}

static void menu_navigate(int8_t encoder, uint8_t key){
if(encoder || key)
if(encoder || key){
menu_exit_count = 0; //clear exit timer.
b_refresh_menu = 1;

}
if(key == KEY_OK){
if(menu_level == MENU_LEVEL_ADJ_VALUE){
//value adjusting has been finished. Enter is pressed.
Expand Down Expand Up @@ -177,13 +203,19 @@ static void menu_navigate(int8_t encoder, uint8_t key){
//check encoder
if(encoder){//encoder changed
if(menu_level == MENU_LEVEL_ROOT){
//ignore now. should be a quick set to voltage.
//enter to menue directly.
if(encoder > 0){
menu_level ++;
main_menu = 0;
}
}
else if(menu_level == MENU_LEVEL_SHOW_MENU){
//adjust main menu
main_menu += encoder;
if(main_menu < 0)
if(main_menu < 0){
main_menu = 0;
menu_level --;
}
else if(main_menu >= sizeof(setting_menu)/sizeof(char*)){
main_menu = sizeof(setting_menu)/sizeof(char*)-1; //set to last menu.
}
Expand All @@ -210,6 +242,8 @@ static void menu_navigate(int8_t encoder, uint8_t key){
volt_disp = voltref_set_value(volt_set);
break;
case 1: //set code
code_set = hex5_adjust(code_set, 0xfffff, encoder, sub_menu);
volt_disp = ad5791_set_code(code_set);
break;
case 2:// calibration
volt_vref = float_adjust(volt_vref, 15.0f, encoder, sub_menu);
Expand Down
2 changes: 1 addition & 1 deletion src/app/ulog_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#define ULOG_USING_USH //use micro shell: USH
#define ULOG_USING_FILTER
#define ULOG_USING_COLOR
//#define ULOG_USING_COLOR
#define ULOG_USING_PRINTF //use custom printf module instead of stdio.h

#define ULOG_OUTPUT_LEVEL
Expand Down
11 changes: 10 additions & 1 deletion src/bsp/ad5791.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* used to track current dac code.
*/
static uint32_t dac_code20b = 0;
static float vref_volt = 10.091745f; /* 10V by default. */
static float vref_volt = 10.091741325f; /* 10V by default. */
/**
* @brief A simple delay function used to meet AD5791 timing.
* @return none.
Expand Down Expand Up @@ -191,6 +191,15 @@ float ad5791_set_code(uint32_t code)
return code*vref_volt/0xfffff;
}

/**
* @brief get ad5791 output code directly. This doesn't include calibration correction.
* @return none.
*/
int32_t ad5791_get_code(void)
{
return dac_code20b;
}

/**
* @brief do AD5791 gain calibration by adjusting current output voltage to 10V and mark it as full scale.
* @return none.
Expand Down
1 change: 1 addition & 0 deletions src/bsp/ad5791.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
void ad5791_init(void);
float ad5791_set_code(uint32_t code);
float ad5791_set_volt(float volt);
int32_t ad5791_get_code(void);

#endif
Loading

0 comments on commit af39348

Please sign in to comment.