//*********************************************************************************
#include <pic.h>
#include <pic16f684.h>
#include <则帆明math.h>
#include <stdlib.h>
void Init()
void PID()
void Set_Constants()
bit flag1,do_PID,int_flag
signed char en0, en1, en2, en3, term1_char, term2_char, off_set
unsigned char temp
short int temp_int
unsigned short int ki, kd, kp
signed int SumE_Min, SumE_Max, SumE, integral_term, derivative_term, un
signed long Cn
// __CONFIG _CP_OFF &_CPD_OFF &_BOD_OFF &_MCLRE_ON &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_FCMEN_ON
//***************************************************************************
// Positional PID 256 Hz
//***************************************************************************
//***************************************************************************
//Main() - Main Routine
//***************************************************************************
void main()
{
Init() //Initialize 12F629 Microcontroller
Set_Constants() //Get PID coefficients ki, kp and kd
while(1) //Loop Forever
{
if(do_PID){
PID()
}
}
}
//***************************************************************************
//Init - Initialization Routine
//***************************************************************************
void Init()
{
PORTA = 0
TRISA = 0b00101101 // Set RA4 and RA2 as outputs
PORTC = 0
TRISC = 0b00000011 // Set RC0 and RC1 as inputs, rest outputs
CMCON0 = 0x07 // Disable the comparator
IRCF0 = 1 // Used to set intrc speed to 8 MHz
IRCF1 = 1 //孙告 Used to set intrc speed to 8 MHz
IRCF2 = 1 // Used to set intrc speed to 8 MHz
CCP1CON = 0b01001100 // Full bridge PWM forward
ECCPAS = 0 // Auto_shutdown is disabled for now
PR2 = 0x3F /轿隐/ Sets PWM Period at 31.2 kHz
T2CON = 0 // TMR2 Off with no prescale
CCPR1L = 0 // Sets Duty Cycle to zero
TMR2ON = 1 // Start Timer2
ANSEL = 0b00110101 // Configure AN0,AN2,AN4 and AN5 as analog
VCFG = 0 // Use Vdd as Ref
ADFM = 1 // Right justified A/D result
ADCS0 = 1 // 16 TOSC prescale
ADCS1 = 0
ADCS2 = 1
CHS0 = 0 // Channel select AN0
CHS1 = 0
CHS2 = 0
ADON = 1 //Turn A/D on
en0 = en1 = en2 = en3 = term1_char = term2_char =0
ki = kd = 0
kp = off_set = 0
temp_int = integral_term = derivative_term = un =0
SumE_Max = 30000
SumE_Min = 1 - SumE_Max
do_PID = 1 // Allowed to do PID function
T0CS = 0 // Timer0 as timer not a counter
TMR0 = 10 // Preload value
PSA = 0 // Prescaler to Timer0
PS0 = 0 // Prescale to 32 =>256 Hz
PS1 = 0
PS2 = 1
INTCON = 0
PIE1 = 0
T0IE = 1 // Enable Timer0 int
GIE = 1
return
}
void PID() // The from of the PID is C(n) = K(E(n) + (Ts/Ti)SumE + (Td/Ts)[E(n) - E(n-1)])
{
integral_term = derivative_term = 0
// Calculate the integral term
SumE = SumE + en0 // SumE is the summation of the error terms
if(SumE >SumE_Max){ // Test if the summation is too big
SumE = SumE_Max
}
if(SumE <SumE_Min){ // Test if the summation is too small
SumE = SumE_Min
} // Integral term is (Ts/Ti)*SumE where Ti is Kp/Ki
// and Ts is the sampling period
// Actual equation used to calculate the integral term is
// Ki*SumE/(Kp*Fs*X) where X is an unknown scaling factor
// and Fs is the sampling frequency
integral_term = SumE / 256 // Divide by the sampling frequency
integral_term = integral_term * ki // Multiply Ki
integral_term = integral_term / 16 // combination of scaling factor and Kp
// Calculate the derivative term
derivative_term = en0 - en3
if(derivative_term >120){ // Test if too large
derivative_term = 120
}
if(derivative_term <-120){ // test if too small
derivative_term = -120
} // Calculate derivative term using (Td/Ts)[E(n) - E(n-1)]
// Where Td is Kd/Kp
// Actual equation used is Kd(en0-en3)/(Kp*X*3*Ts)
derivative_term = derivative_term * kd // Where X is an unknown scaling factor
derivative_term = derivative_term >>5 // divide by 32 precalculated Kp*X*3*Ts
if(derivative_term >120){
derivative_term = 120
}
if(derivative_term <-120){
derivative_term = -120
}
// C(n) = K(E(n) + (Ts/Ti)SumE + (Td/Ts)[E(n) - E(n-1)])
Cn = en0 + integral_term + derivative_term // Sum the terms
Cn = Cn * kp / 1024 // multiply by Kp then scale
if(Cn >= 1000) // Used to limit duty cycle not to have punch through
{
Cn = 1000
}
if(Cn <= -1000)
{
Cn = -1000
}
if(Cn == 0){ // Set the speed of the PWM
DC1B1 = DC1B1 = 0
CCPR1L = 0
}
if(Cn >0){ // Motor should go forward and set the duty cycle to Cn
P1M1 = 0 // Motor is going forward
temp = Cn
if(temp^0b00000001){
DC1B0 = 1
}
else{
DC1B0 = 0
}
if(temp^0b00000010){
DC1B1 = 1
}
else{
DC1B1 = 0
}
CCPR1L = Cn >>2 // Used to stop the pendulum from continually going around in a circle
off_set = off_set +1 // the offset is use to adjust the angle of the pendulum to slightly
if(off_set >55){ // larger than it actually is
off_set = 55
}
}
else { // Motor should go backwards and set the duty cycle to Cn
P1M1 = 1 // Motor is going backwards
temp_int = abs(Cn) // Returns the absolute int value of Cn
temp = temp_int // int to char of LS-Byte
if(temp^0b00000001){
DC1B0 = 1
}
else{
DC1B0 = 0
}
if(temp^0b00000010){
DC1B1 = 1
}
else{
DC1B1 = 0
}
CCPR1L = temp_int >>2 // Used to stop the pendulum from continually going around in a circle
off_set = off_set -1
if(off_set <-55){
off_set = -55
}
}
en3 = en2 // Shift error signals
en2 = en1
en1 = en0
en0 = 0
do_PID = 0 // Done
RA4 = 0 // Test flag to measure the speed of the loop
return
}
void Set_Constants()
{
ANS2 = 1 // Configure AN2 as analog
ANS4 = 1 // Configure AN4 as analog
ANS5 = 1 // Configure AN5 as analog
ADFM = 1 // Right justified A/D result
CHS0 = 0 // Channel select AN4
CHS1 = 0
CHS2 = 1
temp = 200 // Gives delay
while(temp){
temp--
}
GODONE = 1
while(GODONE){
temp = 0 // Does nothing.....
}
ki = ADRESH <<8 // Store the A/D result to Integral Constant
ki = ki + ADRESL
CHS0 = 1 // Channel select AN5
CHS1 = 0
CHS2 = 1
temp = 200 // Gives delay
while(temp){
temp--
}
GODONE = 1
while(GODONE){
temp = 0 // Does nothing.....
}
kd = ADRESH <<8 // Store the A/D result to Differential Constant
kd = kd + ADRESL
CHS0 = 0 // Channel select AN2
CHS1 = 1
CHS2 = 0
temp = 200 // Gives delay
while(temp){
temp--
}
GODONE = 1
while(GODONE){
temp = 0 // Does nothing.....
}
kp = ADRESH <<8 // Store the A/D result to Proportional Constant
kp = kp + ADRESL
CHS0 = 0 // Channel select AN0
CHS1 = 0
CHS2 = 0
}
void interrupt Isr()
{
if(T0IF&&T0IE){
TMR0 = 10 // Preload value
T0IF = 0 // Clear Int Flag
// flag1 = (!flag1)
RA4 = 1
temp_int = 0
temp_int = ADRESH <<8 // Store the A/D result with offset
temp_int = temp_int + ADRESL - 512
en0 = temp_int + off_set/8 // Store to error function asuming no over-flow
do_PID = 1 // Allowed to do PID function
GODONE = 1 // Start next A/D cycle
}
else
{
PIR1 = 0
RAIF = 0
INTF = 0
}
if(temp_int >180){ //Check if error is too large (positive)
DC1B0 = DC1B1 = 0 // Stop PWM
CCPR1L = 0
en0 = en1 = en2 = en3 = term1_char = term2_char = off_set = 0 // Clear all PID constants
Cn = integral_term = derivative_term = SumE = RA4 = 0
do_PID = 0 // Stop doing PID
}
if(temp_int <-180){ //Check if error is too large (negative)
DC1B0 = DC1B1 = 0 // Stop PWM
CCPR1L = 0
en0 = en1 = en2 = en3 = term1_char = term2_char = off_set = 0 // Clear all PID constants
Cn = integral_term = derivative_term = SumE = RA4 = 0
do_PID = 0 // Stop doing PID
}
}
生活是积累沉淀的过程!知识就是财富.分享中获取快乐.中国1号信令与7号信令的区别
2010年07月15日 星期四 09:36
中国1号信令与7号信令的区别
第一、概念描述
1号信令:又称为多频互控信令或随路信令。随路信令是指信令和话音在同一条话路中传送的信令方式。在我国使用的1号信令系统称为中国1号信令系统,是国内PSTN网最早普遍使用的信令。
7号信令:又称为公共信道信令。即以时分方式在一条高速数据链路上传送一群话路信令的信令方式,通常用于局间。在我国使用的7号信令系统称为中国7号信令系统。SS7网是一个带外数据通信网,它叠加在运营者的交换网之上,是支撑网的重要组成部分。在固定电话网或ISDN网局间,完成本地、长途和国际的自动、半自动电话接续;在移动网内的交换局间提供本地、长途和国际电话呼叫业务,以及相关的移动业务,如短信等业务;为固定网和移动网提供智能网业务和其他增值业务;提供对运行管理和维护信息的传递和采集。7号信令网大致由以下几部分组成,信令点是SS7信令网中处理控制消息的节点,产生消息的信令点为该消息的源信令点,接收消息的信令点为该消息的目的信令点。有以下三类信令点: 1. Service Switching Point(SSP) 业务交换点是信令消息的产生或终结点,实质上就是本地交换系统(或交换中心CO),它发起呼叫或接收呼入。2. Signal Transfer Point(STP)完成路由器的功能,查看由SSP发来的消息,然后通过网络把每一个消息交换到合适的地方。STP把其它信令点和网络连接在一起组成更大的网络。3. Service Control Point(SCP) 是典型的访问数据库服务器,SCP是智能网业务的控制中心,负责业务逻辑的执行,提供呼叫处理功能,接收SSP送来的查询信息和查询数据库,验证后向SSP发出呼叫处理指令,接收SSP产生的话单并进行相应的处理。在7号信令网中,ISUP信令(ISDN USER PART)消息是用来建立管理释放中心局话音交换机之间的话音中继电路的,提供话音和非话业务所需的信息交换,用以支持基本的承载业务和枝如补充业务,例如:ISUP信令消息可以承载主叫ID, 主叫方的电话号码,用户名等。TCAP信令(Transaction Capabilities Application Part)消息 用以支持电话业务,如免费电话,本地号码可携带,卡业务,移动漫游以及认证业务。TCAP主要包括移动应用部分(MAP)和运营、维护和管理部分(OMAP)。MAP规定移动业务中漫游和频道越局转接等程序,OMAP仅提供MTP路由正式测试和SCCP路由正式测试程序。
第二、特点描述
一、7号信令(七号信令)简介
集团电话
7号信令(七号信令)系统是一种国际性的标准化的通用公共信令系统,其基本特点是:裤闭
1,最适合由数字程控交换机和数字传输设备所组成的综合数字网。
2,能满足现在和将来传送呼叫控制、遥控、维护管理信令及处理机之间事务处理信息的要求。
3,信令传送相当可靠。
NO.7号信令能满足多种通信业务的要求,当前应用的主要有:
1,局与局之间的电话网通信。
2,局与局之间的数据网通信。
3,局与局之间综合业务数字网。(例如:ISDN PRI)
4,可以传送移动通信网中的各种信息。
5,支持各种类型的智能业务。
6,局端到用户端之间的电话网以及数据网的通信。
二、NO.7信令概述
共路信令是随着数字程控交换机的大量应用而出现的一种新的信号方式。它将原来分散在各路传送的控制电话接续信令集中在一个话路内传送,各路信号之间采用标号进行区分。共路信令概括的说,它传送信令猛纯启的信令链路和通话话路是分开的。一般情况都在数字程控局之间应用,因为受编码资源的影响,而不做用户端推广。由于它采用的是直发式发码方式,所以传输速率较NO:1信令要快。
优点:信令传送速度快,使呼叫接续时间大大缩短;信令和话音分开传送,这对改变信令,增加信令带来了很大的灵活性。
缺点:受信令点编码资源限制,无法大面积推广。
物理接口:符合G.703建议
非平衡75欧姆BNC
帧 结 构:符合G.704建议的帧结构与G.706建议的复帧结构
信令标准:NO
这个就是你要做的事件处理。显然。中断服务程序只设置事件标志,中断返回。2、主程序轮询事件标志,检测到事件标志,进行事件处理(延时,去抖。
1,关中断这是很经典的做法,不进行处理,中断服务中需要关中断的,有延时的程序不应该放在中断服务里,结合前面列出的步骤,应该做的是
1,在中断服务程序中关闭中断,并设启谨培置事件标志,就可以退出中断。
2、退出中断后,如果是实时 *** 作系统,可以根据事件标志直接转到对应的事件处理任务执行处理悄唯。如果没有用实时 *** 作系统,就要靠主程序中的轮询不断的检测事件标志,并调用相应的处理子程序。
3、事件处理完,重新打开中断,再重新检测。
你的信号检测有误,典型的去抖处理应该这样处理,检测到第一个边沿后,延时一段时间。。。然后继续等待事件标志。
以上的重点在于,事件处理的过程是在中断外、下降沿触发中断,而不是在中断服务程序里。)
3、重新开中断。
回到你的问题、中断中设晌喊置事件标志
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)