8 months, 3 weeks ago.

Why does my AnalogOut pin produce digital output?

I have a feedback system that is configured with a PID controller. I am tuning the PID parameters (Kp, Ti, and Td) using poteniometers. However, my problem is that I can't properly tune the PID parameters because the output I am seeing on the oscilloscope (pin 18) seems like a digital output, rather than an analog output. From what I read, there is a 10-bit DAC at pin 18 so it should be analog and not digital.

Can someone please tell me if there is something wrong with my code or how I am writing analogout ?

Here is the libraray to my code: https://os.mbed.com/users/mmohamed/code/PIDControl


1 Answer

8 months, 2 weeks ago.

HI Mohamed,

Without knowing what hardware you are using I would start by looking from https://os.mbed.com/platforms/ that the used pin is for DAC. Also look at AnalogOut example: https://os.mbed.com/docs/mbed-os/v5.14/apis/analogout.html#analogout-example

About the code: AnalogOut.cpp: AnalogOut out(p18); You set out to 0 out = 0; Then inside for loop for (int i = 0; i<1000; i++) you set it once if(i == 500){ out = 1.5/3.3; } This looks like that during 0 - 499 the value is 0 and from 500 to 999 it is 1.5/3.3 = 0.45. -> very digital.

I hope this helps.

Regards, Pekka

Hi Pekka,

I apologize for the confusion. The code I was referring to is AmpPID_Pot.cpp in the same directory. I also edited the forum to include the block diagram of my feedback system. I'm using the LPC1768 here and the input to the microcontroller is a DC voltage. I am trying to tune the PID parameters using potentiometers (to tune in real-time) using an oscilloscope.

I looked at the analogout examples you listed and the only difference I saw in the sine wave example is that the voltage is written as an unsigned short instead of as a float (PID library does most of the calculations using float). Do you see any glaring issues with my code indicating why I am not seeing an analog output?

I appreciate you taking the time to help me with this!


posted by Mohamed Abdelrahman 26 Nov 2019