element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Blog Microblaze based PID controller with sense coprocessing
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: pandoramc
  • Date Created: 28 Jul 2022 8:39 PM Date Created
  • Views 1067 views
  • Likes 7 likes
  • Comments 0 comments
  • controller
  • 7 Ways to Leave Your Spartan-6
  • xilinx
  • fpga
  • soft processors
  • pid
  • 7 Ways to Leave Your Spartan-6 FPGA: Arty S7 Activities
  • microblaze
  • IP Block
Related
Recommended

Microblaze based PID controller with sense coprocessing

pandoramc
pandoramc
28 Jul 2022

For the last step in this journey, the software-based controller is implemented. The most used control is the PID controller defined as,

image

Discretizing the continuous model, we can obtain the following recursive action,

image

Where the Q constants are dependent of sampling time, proportional, differential, and integral constants. This allows the implementation of the new PID_t data type and function data handlers

#ifndef __PID_H__
#define __PID_H__

typedef struct{
	float SetPoint;
	float Q[3];
	float E[3];
	float Response;
}PID_t;

void PID_Init(PID_t *controller, float Kp, float Ki, float Kd, float Ts, float Set);
void PID_SetReference(PID_t *controller, float SetPoint);
float PID_CalcResponse(PID_t *controller, float feedback);
float PID_GetResponse(PID_t *controller);

#endif

The QEI interrupt handler has two tasks, update the control action according to the sensor response and data transmission. For this, the QEI peripheral is configured to manage interrupt times of 10 ms, allowing a precise and periodic sampling time required by the actual model of the PID. The processor only requires three peripheral memory accesses for the control operation: one for the sensor position register, one for the PWM action control update, and the rotation direction. The QEI decodes the signals and does not require the processor to calculate the position and velocity. This means that the processor is free while the next 10 ms interrupt occurs. We can transmit information to computer by the serial port. The printf function could consume more processor time, but the endianness feature in the processor is a great advantage to minimize the transmission time. The MPLAB Data Visualizer has a simple protocol based on byte framing addressing. The requirement in the GUI is establish the protocol shape, how many bytes will be received and what kind of variables will be decoded. All of this allow the follow interrupt handler,

void QEI_Handler(void){
	XIntc_Acknowledge(&intc, XPAR_INTC_0_QEI_0_VEC_ID);
	XIntc_Disable(&intc, XPAR_INTC_0_QEI_0_VEC_ID);

	static uint32_t pPWM;

	response = PID_CalcResponse(&MotorCtrl, (float)sMt -> Position);

	if(response >= 0)
		OUTS -> DATA2 |= 0x02;
	else
		OUTS -> DATA2 &= 0x0D;

	pPWM = (uint32_t)(fabs(response));

	*Duty = pPWM - 2;

	dvSendCode(0x03, DV_START);
	dvSendVar(&sMt -> Velocity, sizeof(sMt -> Velocity));
	dvSendVar(&sMt -> Position, sizeof(sMt -> Position));
	dvSendVar(&response, sizeof(response));
	dvSendVar(&(MotorCtrl.SetPoint), sizeof(MotorCtrl.SetPoint));
	dvSendCode(0x03, DV_END);

	XIntc_Enable(&intc, XPAR_INTC_0_QEI_0_VEC_ID);
}

It's observable that, according AXI Timer documentation, a subtraction by two of the conditioned action response is required.

An experimental tuning allow the next behavior of the system,

The use of Q constants on the controller definition allows the reduction of calculus each interrupt, reducing the processor time on runtime, while in the initialization process all these calculi are required once according to the following,

image

We only require a precise time processing. To do it, we need a peripheral like Fixed time peripheral, Timer peripheral. For the QEI, a Fixed time peripheral behavior was embedded to trigger the interrupt and catch the values for velocity calculation.

The Dual TB9051FTG Motor Driver Shield for Arduino is used for power signal conditioning. In addition, it is possible to sense the current through the motor using a single-ended input ADC. Despite the current signal was not used, it is important to mention that this shield has a current response between the safe voltage range. With 500mV/A resolution, at the peak current allowed by the circuitry, 5A, we obtain a signal of 2.5V peak. The signals for the encoder and motor encoders were remapped in the architecture to avoid signal inconsistency and shield manipulation. The newest port definition is shown below,

set_property PACKAGE_PIN H17 [get_ports CH_Z]
set_property PACKAGE_PIN R16 [get_ports CH_B]
set_property PACKAGE_PIN R14 [get_ports CH_A]
set_property PACKAGE_PIN T15 [get_ports M1PWM]
set_property IOSTANDARD LVCMOS33 [get_ports M1PWM]
set_property IOSTANDARD LVCMOS33 [get_ports CH_A]
set_property IOSTANDARD LVCMOS33 [get_ports CH_B]
set_property IOSTANDARD LVCMOS33 [get_ports CH_Z]

set_property PACKAGE_PIN V17 [get_ports {M1CTRL_tri_o[1]}]
set_property PACKAGE_PIN L16 [get_ports {M1CTRL_tri_o[0]}]
set_property IOSTANDARD LVCMOS33 [get_ports {M1CTRL_tri_o[1]}]
set_property IOSTANDARD LVCMOS33 [get_ports {M1CTRL_tri_o[0]}]

Thess XDC definitions allows the following interaction with external signal conditioners

image

Both boards, Arty S7 and Motor Diver shield are very flexible to test your experiments with signal conditioning and DC power management devices involved.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube