SMT(SF)
示例一:
uint iPwmDuty;
double temp; temp = (double)AdConvert(AN_TEMPERATURE);
temp = temp/; iPwmDuty = (int)(temp+0.5)>(int)temp?(int)temp+:(int)temp;
如果参数在xx.5附近,易产生不稳定摆动
SMT(SF)
uint iPwmDuty;
uint temp,temp4,temp6;
static uint LastiPwmDuty; temp = AdConvert(AN_TEMPERATURE);
temp = temp/; //放大10倍,保留一位小数 temp6 = (temp+)/;
temp4 = (temp+)/;
temp = temp/; if(temp6 > temp)
{
iPwmDuty = temp6;
}
else if(temp4 == temp)
{
iPwmDuty = temp;
}
else
{
if(temp >= LastiPwmDuty)//由小到大
{
iPwmDuty = temp6;
}
else //(iPwmDuty < LastiPwmDuty)
{
iPwmDuty = temp4;
}
}
LastiPwmDuty = iPwmDuty;
示例二:
uchar CanCharge(void)
{
uint temp;
static uchar ChgState = FALSE; if(AdResult[AD_SUNBORD] > AdResult[AD_OPEN_BAT] )
{
temp = AdResult[AD_SUNBORD] - AdResult[AD_OPEN_BAT];
}
else
{
temp = ;
}
if (temp > )// 1V = 1/2.5/4.096*4096 = 400; 0.1V = 40;
{
ChgState = TRUE;
}
else if(temp <= )
{
ChgState = FALSE;
}
return ChgState;
}
示例三:
//#include<pic16f1828.h>
#include<htc.h>
#include "adc.h" __CONFIG(FOSC_INTOSC&WDTE_OFF&PWRTE_ON&MCLRE_OFF&CP_ON&CPD_ON&BOREN_ON&CLKOUTEN_OFF&IESO_OFF&FCMEN_OFF);
__CONFIG(WRT_ALL&PLLEN_OFF&STVREN_ON&LVP_OFF); #define uchar unsigned char
#define uint unsigned int #define RLY1 LATA5
#define RLY2 LATA4
#define RLY3 LATC4 #define RLY_ON 0
#define RLY_OFF 1
#define LED_ON 1
#define LED_OFF 0
#define TRUE 1
#define FALSE 0 #define LED1 LATC2 //LED1(DS3)-RLY1
#define LED2 LATC1 //LED2(DS2)-RLY2
#define LED3 LATC0 //LED3(DS1)-RLY3 #define Connect3 262 //26.2V
#define DisConnect3 238 //23.8V
#define Connect2 260
#define DisConnect2 225
#define Connect1 255 //25.5V
#define DisConnect1 215 //21.5V void DisplayLed(void); void main()
{
uint BAT_SENSE ,BAT_VOLT;
static uint LoadConnect3,LoadConnect2,LoadConnect1;
static uint LoadDisConnect3,LoadDisConnect2,LoadDisConnect1;
static uchar RLY1_States,RLY2_States,RLY3_States; init_a2d(); TRISA = 0x08; //MCLR = 1;
TRISC = 0x40;
ANSELC= 0x40; //set anolog in BAT_SENSE = MiddleADValue();
BAT_VOLT = (uint)(BAT_SENSE*0.78125);//AD/1024*5*16 = (V); 5*160/1024 =800/1024 = 0.78125(参数放大10倍) //Automatic system voltage recognition
if(BAT_VOLT <){//12V
LoadConnect3 = Connect3>>;
LoadDisConnect3 = DisConnect3>>;
LoadConnect2 = Connect2>>;
LoadDisConnect2 = DisConnect2>>;
LoadConnect1 = Connect1>>;
LoadDisConnect1 = DisConnect1>>;
}else if(BAT_VOLT >){//48V
LoadConnect3 = Connect3<<;
LoadDisConnect3 = DisConnect3<<;
LoadConnect2 = Connect2<<;
LoadDisConnect2 = DisConnect2<<;
LoadConnect1 = Connect1<<;
LoadDisConnect1 = DisConnect1<<;
}else{//24V
LoadConnect3 = Connect3;
LoadDisConnect3 = DisConnect3;
LoadConnect2 = Connect2;
LoadDisConnect2 = DisConnect2;
LoadConnect1 = Connect1;
LoadDisConnect1 = DisConnect1;
} RLY1_States = FALSE;
RLY2_States = FALSE;
RLY3_States = FALSE;
RLY1 = RLY_OFF;
RLY2 = RLY_OFF;
RLY3 = RLY_OFF; LED1 = LED_OFF;
LED2 = LED_OFF;
LED3 = LED_OFF;
} while()
{
BAT_SENSE = MiddleADValue();
BAT_VOLT = (uint)(BAT_SENSE*0.78125);//5*160/1024 =800/1024 = 0.78125 if(BAT_VOLT < LoadDisConnect1)
{
RLY1_States = FALSE;
}
else if(BAT_VOLT > LoadConnect1)
{
RLY1_States = TRUE;
} if(BAT_VOLT < LoadDisConnect2)
{
RLY2_States = FALSE;
}
else if(BAT_VOLT > LoadConnect2)
{
RLY2_States = TRUE;
} if(BAT_VOLT < LoadDisConnect3)
{
RLY3_States = FALSE;
}
else if(BAT_VOLT > LoadConnect3)
{
RLY3_States = TRUE;
}
//=====================================================
if(RLY1_States == TRUE)
{
RLY1 = RLY_ON;
}
else
{
RLY1 = RLY_OFF;
}
if(RLY2_States == TRUE)
{
RLY2 = RLY_ON;
}
else
{
RLY2 = RLY_OFF;
}
if(RLY3_States == TRUE)
{
RLY3 = RLY_ON;
}
else
{
RLY3 = RLY_OFF;
}
DisplayLed();
_delay();
}
} void DisplayLed(void)
{
//LED state set synchronization
if(RLY1_States == TRUE)
{
LED1 = LED_ON;
}
else
{
LED1 = !LED1;
} if(RLY2_States == TRUE)
{
LED2 = LED_ON;
}
else
{
LED2 = !LED2;
} if(RLY3_States == TRUE)
{
LED3 = LED_ON;
}
else
{
LED3 = !LED3; //One LED twinkle
}
}
//#include<pic16f1828.h>
#include<htc.h>
#include "adc.h" __CONFIG(FOSC_INTOSC&WDTE_ON&PWRTE_OFF&MCLRE_OFF&CP_ON&CPD_ON&BOREN_ON&CLKOUTEN_OFF&IESO_OFF&FCMEN_OFF);
__CONFIG(WRT_ALL&PLLEN_OFF&STVREN_ON&LVP_OFF); #define uchar unsigned char
#define uint unsigned int #define RLY1 LATA5
#define RLY2 LATA4
#define RLY3 LATC4 #define RLY_ON 0
#define RLY_OFF 1
#define LED_ON 1
#define LED_OFF 0 #define LED1 LATC2 //LED1(DS3)-RLY1
#define LED2 LATC1 //LED2(DS2)-RLY2
#define LED3 LATC0 //LED3(DS1)-RLY3 #define Connect3 262 //26.2V
#define DisConnect3 238 //23.8V
#define Connect2 260
#define DisConnect2 225
#define Connect1 255 //25.5V
#define DisConnect1 215 //21.5V void DisplayLed(void); void main()
{
uchar flag;
uint BAT_SENSE ,BAT_VOLT; static uint LoadConnect3,LoadConnect2,LoadConnect1;
static uint LoadDisConnect3,LoadDisConnect2,LoadDisConnect1; init_a2d(); TRISA = 0x08; //MCLR = 1;
TRISC = 0x40;
ANSELC= 0x40; //set anolog in BAT_SENSE = MiddleADValue();
BAT_VOLT = (uint)(BAT_SENSE*0.78125);//AD/1024*5*16 = (V); 5*160/1024 =800/1024 = 0.78125(参数放大10倍) //Automatic system voltage recognition
if(BAT_VOLT <){//12V
LoadConnect3 = Connect3>>;
LoadDisConnect3 = DisConnect3>>;
LoadConnect2 = Connect2>>;
LoadDisConnect2 = DisConnect2>>;
LoadConnect1 = Connect1>>;
LoadDisConnect1 = DisConnect1>>;
}else if(BAT_VOLT >){//48V
LoadConnect3 = Connect3<<;
LoadDisConnect3 = DisConnect3<<;
LoadConnect2 = Connect2<<;
LoadDisConnect2 = DisConnect2<<;
LoadConnect1 = Connect1<<;
LoadDisConnect1 = DisConnect1<<;
}else{//24V
LoadConnect3 = Connect3;
LoadDisConnect3 = DisConnect3;
LoadConnect2 = Connect2;
LoadDisConnect2 = DisConnect2;
LoadConnect1 = Connect1;
LoadDisConnect1 = DisConnect1;
} flag = ;
RLY1 = RLY_OFF;
RLY2 = RLY_OFF;
RLY3 = RLY_OFF; LED1 = LED_OFF;
LED2 = LED_OFF;
LED3 = LED_OFF;
} while()
{
BAT_SENSE = MiddleADValue();
BAT_VOLT = (uint)(BAT_SENSE*0.78125);//5*160/1024 =800/1024 = 0.78125 //Determine which range of BAT_VOLT
if(BAT_VOLT<LoadDisConnect1)
{
RLY1 = RLY_OFF;
RLY2 = RLY_OFF;
RLY3 = RLY_OFF;
flag = ;
}
else if((BAT_VOLT>=LoadDisConnect1)&&(BAT_VOLT<LoadDisConnect2))
{
if(flag > )//由大到小
{
//RLY1 = RLY1;
RLY2 = RLY_OFF;
RLY3 = RLY_OFF;
}else if(flag <= ){ }
flag = ;
}
else if((BAT_VOLT>=LoadDisConnect2)&&(BAT_VOLT<LoadDisConnect3))
{
if(flag > )
{
//RLY1 = RLY1;
//RLY2 = RLY2;
RLY3 = RLY_OFF;
}
flag = ;
}
/*-------------------------------------------------------*/
else if((BAT_VOLT>=LoadDisConnect3)&&(BAT_VOLT<LoadConnect1))
{
//RLY1 = RLY1;
//RLY2 = RLY2;
//RLY3 = RLY3;
flag = ;
}
/*-------------------------------------------------------*/
else if((BAT_VOLT>=LoadConnect1)&&(BAT_VOLT<LoadConnect2))
{
if(flag < ){ RLY1 = RLY_ON;
//RLY2 = RLY2;
//RLY3 = RLY3;
}
flag = ;
}else if((BAT_VOLT>=LoadConnect2)&&(BAT_VOLT<LoadConnect3))
{
if(flag < )
{
RLY1 = RLY_ON;
RLY2 = RLY_ON;
//RLY3 = RLY3;
}
flag = ; }else if(BAT_VOLT>=LoadConnect3)
{
RLY1 = RLY_ON;
RLY2 = RLY_ON;
RLY3 = RLY_ON;
flag = ;
}
DisplayLed();
_delay();
}
} void DisplayLed(void)
{
//LED state set synchronization
if(RLY1 == RLY_ON)
{
LED1 = LED_ON;
}
else
{
LED1 = !LED1;
} if(RLY2 == RLY_ON)
{
LED2 = LED_ON;
}
else
{
LED2 = !LED2;
} if(RLY3 == RLY_ON)
{
LED3 = LED_ON;
}
else
{
LED3 = !LED3; //One LED twinkle
}
}
施密特算法
SMT(SF)的更多相关文章
- 查看Unix/Linux的CPU个数和内存大小,系统位数(转载)
一.AIX 1.查看CPU数: (1) smtctl 从AIX5.3起,对于power5的机器,系统引入了SMT(Simultaneousmulti-threading)的功能,其允许两个处理线程在同 ...
- 备考2019年6月份PMP考试-分享一些考试笔记(二)
最新比较经典的100道试题,有备考的小伙伴可以练练手,文章末尾附答案. 1 一个项目经理在运作一个数据中心安装项目.他发现相关方很恼火,因为他超出了预算,原因是人员费用要高于原先的计划.另外项 ...
- (0)Lora及LoraWAN
Lora和LoraWAN的区别 LoRa经常被误用来描述整个LPWAN通信系统,其实Lora是Semtech拥有的专有调制格式. SX1272和SX1276 LoRa芯片使用称为chirp扩频(CSS ...
- (3)LoraWAN:链路控制、SF BW CR
三.Introduction on LoRaWAN options 本文件描述了一种用于可为移动的或固定在一个固定位置的电池供电的终端设备而优化的LoRaWAN™网络协议.LORA™是一个由Semte ...
- 机器学习算法整理(五)决策树_随机森林——鹃尾花实例 Python实现
以下均为自己看视频做的笔记,自用,侵删! 还参考了:http://www.ai-start.com/ml2014/ In [8]: %matplotlib inline import pandas a ...
- AIX常用命令汇总(转)
在本文中,我将讨论这其中的一些核心命令.其目的旨在为您提供一个可用作便捷参考的列表.虽然这些命令的行为在所有 AIX 版本中都应该相同,但是仅在 AIX 5.3 下对它们进行了测试. 注意:以下段落中 ...
- Vue.js学习笔记(1)
数据的双向绑定(ES6写法) 效果: 没有改变 input 框里面的值时
- 用C#实现MD5的加密(转载)
方法一 首先,先简单介绍一下MD5 MD5的全称是message-digest algorithm 5(信息-摘要算法,在90年代初由mit laboratory for computer scien ...
- 10分钟了解设计模式(C#)
最近把<大话设计模式>重温了下(看完序才知道原来作者是也是博客园园友,这本书的最早博客版本在这里).体会最深的就是面向接口编程的重要性,如何在自己的项目中进行抽象,合理的利用各种设计模式. ...
随机推荐
- mysql 导出数据字典
使用Navicat工具 查询: SELECT TABLE_SCHEMA AS '数据库', TABLE_NAME AS '表名', COLUMN_NAME AS '字段名', COLUMN_TYPE ...
- python3爬虫之开篇
写在前面的话: 折腾爬虫也有一段时间了,从一开始的懵懵懂懂,到现在的有一定基础,对于这一路的跌跌撞撞,个人觉得应该留下一些文字性的东西,毕竟好记性不如烂笔头,而且毕竟这是吃饭的家伙,必须用心对待才可以 ...
- ruby URI类
一. URI require 'uri' uri = URI("http://foo.com/posts?id=30&limit=5#time=1305298413") # ...
- class实现Stack
基于class实现一个存储string类型的Stack 头文件: //stack.h #include<vector> #include<string> class Stack ...
- 003---random随机数模块
import random # 随机数(0-1) print(random.random()) # 随机整数, 包含尾巴 print(random.randint(-1, 2)) # 不包含尾巴 pr ...
- .Net 面试题 汇总(二)
51..net中读写XML的类都归属于哪些命名空间? 答:System.Xml 52.解释一下UDDI.WSDL的意义及其作用. 答:UDDI即统一描述.发现和集成协议.作用: 用来说明一个Web服务 ...
- python2.7入门---字符串
这次咱们就来看一下python的字符串类型.首先我们要知道,字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串.创建字符串很简单,只要为变量分配一个值 ...
- C++11中std::forward的使用
std::forward argument: Returns an rvalue reference to arg if arg is not an lvalue reference; If arg ...
- Android Stadio 指定文件打开类型
我们项目里面,有一个文件,叫做aaa.meta. 这个只是一个配置文件,里面是txt. 但是Android Stadio 不识别.怎么办? 设置如下图: 首先,打开Android stadio 的设置 ...
- Android Stadio调试gradle 插件 || Android Stadio 远程调试 || Anroid APT调试
有时候,自己开发了gralde插件,想调试一下.毕竟打印log 成本太高.效率太低.怎么做呢? 第一种方法: 1.执行gradlew 命令的时候,加上几个参数:-Dorg.gradle.debug=t ...