LPC1549 LPCxpresso Board read variable voltage on ADC pin

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1549 LPCxpresso Board read variable voltage on ADC pin

1,363 Views
luigi_giunti
Contributor II

Hello all,

I would like to read a variable voltage on ADC pin.

Display-PWM-duty-cycles-img_assist-400x206.jpg

I suppose i must utilize a counter which detects several samples in a period.

However i need to acquire only the high value

Can someone please tell me how to build a function that makes that? 

To write the code i used as example periph_adc_rom.

Thanks.

Labels (3)
7 Replies

1,044 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Hi Luigi,

It's good solution to use ADC+ Analog comparator as your input voltage is only 0.5V and 2.0V,

Analog comparator negative voltage input can be your analog input,

positive input can be  voltage ladder. you can  set CMP->VSEL to set voltage value, for example, you can set ladder as 1.5V in your case.

When your analog signal voltage > voltage ladder 1.5V. output, CMP->STAT is set automatically. you can enable ADC sampling.

Please note, After the voltage ladder is powered on, it requires stabilization time until comparisons using it are accurate. Much shorter settling times apply after the LADSEL value is changed and when either or both voltage sources are changed. Software can deal with these factors by repeatedly reading the comparator output until a number of readings yield the same result.


Have a great day,
Jun Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,044 Views
ianbenton
Senior Contributor I

Connect it to one of the ADC pins which also connects to a comparator (pins 9, 12, 15 and 18 on the 48-pin device). Use the comparator output to trigger the A/D.

That leaves one question unanswered - where to connect the other comparator input.

If you know the voltage of the low part of the waveform, connect it to a suitable point on the voltage divider, if you don't, connect a resistor one end to your signal, and the other end to the comparator input, then connect a capacitor from the comparator input to 0V. Resistor and capacitor values will depend on the frequency (which you didn't state).

Alternatively, (and this depends on the frequency and mark-space ratio of your signal). Sample at a frequency that makes sure you get at least one sample in the high part of the waveform. Then filter the output with a simple IIR filter. Compare the latest sample with the output of the filter. If the sample is higher than the filter that is your "high" voltage.

A simple IIR filter: (latest sample in R0, running total in R1, output in R2, n is the time constant)

SUBS R1,R1,R1,LSR#n

ADDS R1,R1,R0

LSRS R2,R1,#n

or, combining it with the comparator so it now only needs two registers:

SUBS R1,R1,R1,LSR #n

ADDS R1,R1,R0

CMP R0,R1,LSR #n

1,044 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Luigi,

It seems your ADC input is a digital signal, right?

What's the purpose of your function? just want to count how many "high value" in a specific range of time?

How do you define the high value? for example >2.7V ?

Jennie Zhang

0 Kudos

1,044 Views
luigi_giunti
Contributor II

Hi Jennie,

Thank you for your reply.

my ADC input is an analog signal.

My purpose is to read the output voltage of an hall current sensor. Input current sensor is modulated by a PWM signal therefore, sensor output, is a square wave with a know frequency 1000 Hz.

I would like to synchronize with this wave and read only the high value of one period. About 100 samples.

Square wave amplitude is between 0.5V and 2.0V.

0 Kudos

1,044 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Luigi,

Thanks for your reply.

I suggest the solution is as below:

  1. connect your signal to both a GPIO interrupt pin and ADC input pin.

  2. Set GPIO interrupt for both rising edge and falling edge

  3. When rising edge is coming, enter GPIO rising edge interrupt, enable ADC conversion sequence by software, get 100 samples and you want.

 4.  When falling edge is coming, enter GPIO falling edge interrupt. disable ADC conversion sequence by software.


Have a great day,
Jun Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,044 Views
luigi_giunti
Contributor II

Hi Jennie,

Thank you so much for your support.

I'm a first-time programmer so, could you please suggest me an example code to be used to that purpose?

Thank you again for your cooperation.

Have a nice day

0 Kudos

1,044 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Luigi Giunti,

Thanks for your reply. I don't have an exact demo project for this solution but I would like to provide you related demo code instead. You can do combination by yourself.

Download lpcopen from this link.

LPCOpen Software for LPC15XX|NXP 

refer this two demo codes:

- periph_pinint

- periph_adc


Have a great day,
Jun Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos