I tried to implement a software numerical regulator using an AT MIO 16E 10 card. And I did it so:
1. I create an event that occurs every time an A/D conversion has finished:
Config_DAQ_Event_Message(AT_MIO_16E_10, 1, chanAD, 1, 1L, 0L, 0L, 0L, 0L, 0, 0, adresa);
2. I read the output (in pretrigger mode) of the process :
DAQ_StopTrigger_Config(AT_MIO_16E_10, 1, 100L);
DAQ_Rate(freq, 0, timebase, sampleInterval);
DAQ_Start(AT_MIO_16E_10, chanAD, gainAD, buffer, 100, *timebase, *sampleInterval)
3. When an A/D conversion on my A/D channel has finished is called the callback function "cadr" where the regulator algorithm is implemented and I write the new c
ommand to the process by the D/A channel.
#pragma option -N-
void _loadds far cadr(int *h, int *mm, unsigned *wP, unsigned long *lP)
{
AO_VWrite(AT_MIO_16E_10, chanDA, u[k%n]);
k++;
AI_VScale(AT_MIO_16E_10, chanAD, gainAD, 1, 0, buffer[(k-1)%100], &y[k%n]);
r[k%n] = (ref != r[k%n]) ? ref : r[k%n];
e[k%n] = r[k%n] - y[k%n];
u[k%n] = 0;
for(ii = 1; ii < n; ii++)
u[k%n] += b[ii] * u[(k-ii)%n];
for(ii = 0; ii < m; ii++)
u[k%n] += a[ii] * e[(k-ii)%n];
if(u[k%n] < 0) u[k%n] = 0;
if(u[k%n] > 10) u[k%n] = 10;
}
#pragma option -N
My problem is that the callback function is never executed and I don't know why. If anyone wants to help please look at the source code in the attachments and tell me what is wrong or how can I repair the problem.
Thanks in advance.