This post was last edited by boming on 2017-12-18 02:01 Copy Mitsubishi PLC (Fx2N) and apply it to industrial sites
Background I am engaged in industrial application development (PLC, HMI programming, etc.), and I have always wanted to develop a complete control system of my own. Let's start with copying! From PLC -> HMI -> Servo -> Network application, etc. Computer and PLC communication was not originally open source. It was used in the products developed by the company (to be used in a low-key manner). Considering that it might be used in the later development of supporting systems, it was open source. The communication was done in my spare time, intermittently until I worked hard to develop it. I hope friends with common interests can communicate with each other.
Coincidentally, with the help of participating in the EEworld DIY event, the latest PLC control unit (FX2n copy product) was officially released and applied to the industrial field version. Some test versions have been released before. As expected, the RIGOL DS1102U dual-channel digital oscilloscope is used to test whether the high-speed counting and high-speed output functions meet the requirements (the high-speed function is not used in the application for the time being). Thanks for your support. Introduction The PLC program uses Mitsubishi GX Developer Version 8. I wanted to upload it, but the file is too large, so I downloaded it from the Mitsubishi official website. Actual application examples [attach] 334583 [/attach] [attach] 334606 [/attach]
The main control uses STM32F446 and uses the standard library (I don't like the HAL library, which seriously affects the PLC scan time). It is easy to port to other main controls. Rapid porting was specially considered during development, and the development environment is IAR.
Fx2N.part18.rar
(6.8 MB, downloads: 5363)
Fx2N.part17.rar
(14.5 MB, downloads: 1179)
Fx2N.part16.rar
(14.5 MB, downloads: 1527)
Fx2N.part15.rar
(14.5 MB, downloads: 1504)
Fx2N.part14.rar
(14.5 MB, downloads: 1306)
Fx2N.part13.rar
(14.5 MB, downloads: 2018)
Fx2N.part12.rar
(14.5 MB, downloads: 3111)
Fx2N.part11.rar
(14.5 MB, downloads: 3335)
Fx2N.part10.rar
(14.5 MB, downloads: 2758)
Fx2N.part09.rar
(14.5 MB, downloads: 3204)
Fx2N.part08.rar
(14.5 MB, downloads: 3050)
Fx2N.part07.rar
(14.5 MB, downloads: 3029)
Fx2N.part06.rar
(14.5 MB, downloads: 3064)
Fx2N.part05.rar
(14.5 MB, downloads: 3595)
Fx2N.part04.rar
(14.5 MB, downloads: 3485)
Fx2N.part03.rar
(14.5 MB, downloads: 3968)
Fx2N.part02.rar
(14.5 MB, downloads: 3923)
Fx2N.part01.rar
(14.5 MB, downloads: 1306)
InLine33.rar
(10.97 KB, downloads: 205)
Main directory
doc All the information and notes during the development process STM32F4xxDSP_StdPeriph_Lib_v1.8.0 standard library (STM32 download) USER source code MCU and master control related code McuConnectPlc PLC core code and master control connection code PLC PLC core code (it can be seen that it is particularly easy to port to other master controls) Fx2N IAR project file The rest is useless
Naming EXTI_PA0 IO external interrupt, use PA0 pin related NVIC priority setting related RCC system clock initialization related RTC real-time clock related
Source code introduction: 1. After the MCU is started, 2. Main is performed, 3. Then each clock is initialized, including the real-time clock (used by the PLC). 4. Timer interrupt is initialized, 1MS interrupt is performed once, and the PLC timer, scan time, etc. are used (this MCU uses the system beat time, which can be replaced by the timer). 5. Interrupt priority is initialized. 6. Enter the PLC core code. int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file. */ RCC_Config();//Initialize the system time to the maximum of 180M /* Enable the LSI OSC */ RCC_LSICmd(ENABLE);//Enable LIS time for real-time clock use /* Wait till LSI is ready */ while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks);//Get the main clock and use SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000) for the system tick;//System tick initialization NVIC_Configuration();//Interrupt priority initialization plc_main(); } void plc_main(void) { // uint32 ddddd; uint8 temp; RGB_LED_Init(); // LED4(OFF);//Green light,运行
// LED5(OFF);//红灯,出错
// LED6(OFF);//蓝灯,电池低
PLC_PowerUpReset();
DMA_Uart_Init();
Programme_Serial_Init(0);
rs232_Serial_Init(D8120);
/*
tim1_pwm_init();
tim1_pwm_start(0xffFf,515,0x7FFF);
tim2_ch1_pb8_UD_init();
tim2_ch2_pb9_R_init();
tim3_etr_pd2_UD_Init();
tim8_pwm_init();
tim8_pwm_start(0xffFf,515,0x7FFF);
tim2_ENC_Init();
tim5_ENC_Init();
GetCounter2();
GetCounter5();
GetDir2();
*/
/* RTC Configuration */
RTC_Configuration();
while(1)
{
/*
PLC_RAM32(PLC_R_START_ADD+0x0cdc)=Get_tim2_ch1_pb8_UD_Counter(); //c255
if(PLC_BIT_TEST(0x800)) //m0
tim2_ch1_pb8_UD_Counter_Clear();
PLC_RAM32(PLC_R_START_ADD+0x0cd8)=Get_tim3_etr_pd2_UD_Counter();//c254
if(PLC_BIT_TEST(0x801)) //m1
tim3_etr_pd2_UD_Counter_Clear();
*/
PLC_PROG_RUN();
if(PLC_1MS_BIT>70)
{
wdt();
PLC_1MS_BIT=0;
Receive_Processing(&PLC_UART_BUFFER,&PLC_UART_RECEIVE_CNT,&PLC_UART_T_BUFFER,&PLC_UART_T_CNT);
DMASend();
Receive_Processing(&RS232_R_BUFFER,&RS232_RECEIVE_CNT,&RS232_T_BUFFER,&RS232_T_CNT);
RS232_SEND();
if(D8065)
{
// LED5(ON);//红灯,出错
}
else
{
// LED5(OFF);//红灯,出错
}
if(D8065==0 && PLC_BIT_TEST(M8037)==0)
{
if(PLC_RUN_BIT==0)
{
PLC_RUN_BIT=1;
} //开始运行测试
// LED4(ON);//绿灯,运行
if(PLC_BIT_TEST(M8015) || PLC_BIT_TEST(M8019) || PLC_BIT_TEST(M8018)==0)
{
RCC_RTCCLKCmd(DISABLE);
temp=2;
}
else
{
if(temp==2)
{
RCC_RTCCLKCmd(ENABLE);
temp=1;
D_to_RTC();
}
else
RTC_to_D();
}
#ifndef debug
if(PLC_RUN_BIT==3)
{
wdt_init(D8000);
}
#endif
}
else
{
wdt_clear();
// LED4(OFF);//绿灯,运行
if(PLC_RUN_BIT!=0)
{
PLC_BIT_OFF(M8000);
PLC_RUN_BIT=0;
PLC_BIT_ON(M8037);
}
}
}
#ifndef debug
PLC_RUN_BIT==3;
#endif
}
}
现在PLC执行时间和三菱的一样,有的指令还快很多。
代码需要高手优化,期等高手帮忙,现在使用的MCU有大牛拉小车感觉。
现场使用的时NUCLEO—446RE核心+拆机杂牌PLC扩展使用。
欢迎大家跟帖交流!!!
后期计划
重新设计原理图,出PCB打样,电源定制,需要大电容检测断电保存数据。外壳定制。(本人不熟悉这块)希望有爱好朋友开发这块
=0) { PLC_BIT_OFF(M8000); PLC_RUN_BIT=0; PLC_BIT_ON(M8037); } } } #ifndef debug PLC_RUN_BIT==3; #endif } } Now the PLC execution time is the same as Mitsubishi, and some instructions are much faster. The code needs to be optimized by experts, and I am waiting for the help of experts. The MCU I am using now feels like a big cow pulling a small cart. The NUCLEO-446RE core + disassembled unknown brand PLC expansion is used on site.
Welcome everyone to post and communicate! ! !
Later plans to redesign the schematic diagram, produce PCB proofing, customize the power supply, and need a large capacitor to detect power failure and save data. Customize the shell. (I am not familiar with this) I hope that friends who are interested in this will develop this
=0) { PLC_BIT_OFF(M8000); PLC_RUN_BIT=0; PLC_BIT_ON(M8037); } } } #ifndef debug PLC_RUN_BIT==3; #endif } } Now the PLC execution time is the same as Mitsubishi, and some instructions are much faster. The code needs to be optimized by experts, and I am waiting for the help of experts. The MCU I am using now feels like a big cow pulling a small cart. The NUCLEO-446RE core + disassembled unknown brand PLC expansion is used on site.
Welcome everyone to post and communicate! ! !
Later plans to redesign the schematic diagram, produce PCB proofing, customize the power supply, and need a large capacitor to detect power failure and save data. Customize the shell. (I am not familiar with this) I hope that friends who are interested in this will develop this