Page 1 of 1

API integration of PID controller

Posted: Mon Oct 16, 2017 4:12 pm
by JackTheRippchen
Hi,
I'm wondering whether anybody has added the PID controller to the API yet. (Reinventing the wheel is waste of time, imho.)

My final goal is to modify the PID-oscilloscope-web-app. I'd like to step the setpoint of e.g. PID11 and capture the step answer by single trigger.
At the moment, this is too difficult for me. Therefore, I prefer going little steps and try to implement this in C without any web GUI. Hence, I need to control by API.

Re: API integration of PID controller

Posted: Tue Oct 17, 2017 3:58 pm
by JackTheRippchen
Referring to the existing API files on GitHub and this register map, I'm trying to build my own pid.c/pid.h files.

current conception of pid.h:

Code: Select all

#ifndef __PID_H
#define __PID_H

#include <stdint.h>

#include "redpitaya/rp.h"

#define PID_COUNT 4
#define ADC_COUNT_MAX 8191
#define ADC_COUNT_MIN -8192

// Base Generate address
#define PID_BASE_ADDR      0x00300000
#define PID_BASE_SIZE      0x4C

typedef struct pid_control_s {
	unsigned int PID11_IntegratorReset	:1;
	unsigned int PID12_IntegratorReset	:1;
	unsigned int PID21_IntegratorReset	:1;
	unsigned int PID22_IntegratorReset	:1;
	unsigned int 						:28;
    unsigned int PID11_SP				:14;
    unsigned int 						:18;
    unsigned int PID11_Kp				:14;
    unsigned int 						:18;
    unsigned int PID11_Ki				:14;
    unsigned int 						:18;
    unsigned int PID11_Kd				:14;
    unsigned int 						:18;	
    unsigned int PID12_SP				:14;
    unsigned int 						:18;
    unsigned int PID12_Kp				:14;
    unsigned int 						:18;
    unsigned int PID12_Ki				:14;
    unsigned int 						:18;
    unsigned int PID12_Kd				:14;
    unsigned int 						:18;
    unsigned int PID21_SP				:14;
    unsigned int 						:18;
    unsigned int PID21_Kp				:14;
    unsigned int 						:18;
    unsigned int PID21_Ki				:14;
    unsigned int 						:18;
    unsigned int PID21_Kd				:14;
    unsigned int 						:18;
    unsigned int PID22_SP				:14;
    unsigned int 						:18;
    unsigned int PID22_Kp				:14;
    unsigned int 						:18;
    unsigned int PID22_Ki				:14;
    unsigned int 						:18;
    unsigned int PID22_Kd				:14;
    unsigned int 						:18;	
} pid_control_t;

int pid_Init();
int pid_Release();

int pidEnableIntReset(rp_pid_t pid);
int pidDisableIntReset(rp_pid_t pid);
int pidSetParamSP(rp_pid_t pid, float value);
int pidSetParamKP(rp_pid_t pid, float value);
int pidSetParamKI(rp_pid_t pid, float value);
int pidSetParamKD(rp_pid_t pid, float value);

#endif //__PID_H
I don't understand why "PID11 set point" offset is 0x10 (register map page 13), while offset of e.g. "Ch A amplitude scale and offset" is 0x4 (register map page 10). In both cases, 32 bit (= 4 Byte) are described before. :?:

Furthermore, all modules start at address 0x40[x]00000 (register map page 3). In e.g. generate.h, the base address is 0x00200000 instead of 0x40200000. :?:

Re: API integration of PID controller

Posted: Wed Oct 10, 2018 5:02 pm
by lazyoracle
Hey. Did you manage to access the PID blocks on the FPGA using the C API? I would be happy to collaborate if you are still working on this.