CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Configure ADC with rotation sensor

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

Configure ADC with rotation sensor
PostPosted: Fri Jan 13, 2017 1:25 pm     Reply with quote

Hi

After so long without programming, for professional reasons I'm back ...

But now it is time to take a course, so I come to ask for your help.

I have a positioning sensor "ri360p0-qr24m0-eliu5x2-h1151" and wanted to read with the values ​​on a PIC18F458

As the values ​​vary between 0 and 10V (0º-360º), how should I configure my ADC to print the terminal in degrees?

As the PIC works at 5V, I have to make a resistive divider for values ​​ranging from 0 to 5V (0º-360º), I had thought to use pin A3 with a reference value to facilitate calculations.

Can someone help me figure out how to make these calculations?
Code:

#include <18F458.h>
#device adc=10                                        //adc com 10bits
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT,STVREN
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

void main(void)
{
     
      int16 readadc, value;
      int8 i;

      setup_adc_ports(AN0_AN1_VSS_VREF); // colocar referencia em A3 escala 0-1023
      setup_adc(ADC_CLOCK_DIV_2);


while (TRUE)
{
   
     
      printf("Angle: %4lu\r", value);

}
}

asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Jan 13, 2017 1:43 pm     Reply with quote

So take stock.
You have a 10 bit DAC and 360 degrees.

So 360/1024=.3516 BEST CASE degrees per DAC count.

Sadly this is a ratio of 2.8444.... which is never going to give you
whole degrees - since 3 counts =1.0547 degrees.

How FAST does the encoder turn in your application?
I see it is rated to 12,000 RPM. thats 200 RPS


Why on earth are you using a BRUTALLY expensive voltage
output encoder and how well do you understand the way
rotation speed, PIC Clock frequency and only 10 (slow) bits +/- - 2 bits
is going to make it hard to know anything about the encoder position with high accuracy unless it only moves at a dead CRAWL.....

Why not use a pulse output encoder and a PIC with fast DE-encoder hardware built in ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Fri Jan 13, 2017 1:46 pm     Reply with quote

Start again.

Use the 4-20mA output. This is better for noise immunity anyway, and allows you to choose the voltage being generated.

Then connect this to a 110R resistor, so you get 2.2v for 20mA.

Use a 2.5v bandgap reference on Vref. Need this for stability.

Then read the ADC. Subtract 180, and divide by 2. Result is in degrees.

How does this work?.

The range from 0 to 360, gives 4 to 20mA. 16mA span.
16mA * 110R = 1.76v

The ADC running off 2.5v gives 2.5/1024v V/step. = 0.00244v

1.76/0.00244 = 720. 720/2 = 360.

The 4mA gives 0.44v. 0.44/0.00244 = 180.

So subtract 180, then divide by 2, and you have degrees.

This is a classic example of designing the hardware to simplify the maths.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Fri Jan 13, 2017 4:38 pm     Reply with quote

hi

thanks for this help...

My head is full of rust on programming

I understand all

best regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group