Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4-20 mA using pic 16f72

Status
Not open for further replies.

djc

Advanced Member level 1
Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Visit site
Activity points
4,554
Hi all,

I want to display 4-20 mA current on 7 segment display. I have a hardware using pic16f72. Current to voltage converter circuit is implemented on hardware. Current in miliampere will be supplied externally. Converted voltage will be supplied to RA0 pin. Now i have a doubt that exatly what value of the voltage will be generated for 4mA current. '0' will be displayed for 4 mA current, '50' for 12 mA and 100 for 20mA current. I have implemented ADC routine.Please guide me how to do that.

Thanking You.
 

Your A-to-V converter must provide an output range that is usable by your ADC.

This means it needs to have sufficient gain.
At the same time, it must not send too high a volt level to your ADC input.

I believe you want some reading when 4 mA is present.
 

Hi,

Thanx for the reply sir. I tried to do something. I supplied current starting from 0 mA upto 20 mA. While varying current I measured voltage on RA0 pin on which current to voltage converter is attached. It showed varying voltage for different current. Like for 4mA current it showed 925mV and for 20mA current it showed 4.78V. I further tried to increase current, But maximum was 21mA and voltage corresponding to it was 4.81V. I hope voltage is not too high for ADC and some reading is there for 4 mA. Further guidance is needed.

Thanking You
 

It appears your pic16f72 accepts volt levels up to 5VDC at its ADC input. Do not apply a higher voltage.

Like for 4mA current it showed 925mV and for 20mA current it showed 4.78V.

These look as though these should be usable levels for your ADC.

If 0 to 5V analog represents 0 to 255 digital...

Then 4.78 V should convert to 244.

And 925 mV should convert to 47.

I have no experience with pics, so I don't know if you should change any internal settings. You may need to designate a high and low volt level, corresponding to values of 255 and 0.
 

does your adc giving result?? actually what is your problem? you are not getting result from adc ... or you want to know how to translate adc result in % (percentage)?

- - - Updated - - -

does your adc giving result?? actually what is your problem? you are not getting result from adc ... or you want to know how to translate adc result in % (percentage)?
 

Hi,
ADC is giving 8 bit output. I'l ake care not to apply voltage more than 5V. Supply itself is not giving current more than 20-21 mA so its goin upto 5V max. So can I compare corresponding digital value for particular voltage with that specific current and display it? Will that be perfectly correct? or any other caliberation is needed?

Thanking you

- - - Updated - - -

Hi nisarg,

Yep I think my ADC is working. Because It's showing varying output on LED's connected at port B. Means when I operate the knob various LED's glows with different intensity. Now at first I would like to display digital value regarding specific voltage on 4 FND's connected on PORT B. I think I have to implement some scanning mechanism also to display the value at the same time on FND. Then in next step currnt will be supplied to ADC and have to display digital value regarding that current on FND.

Thanking you
 

Assuming you are using a 5V supply for your PIC, then pass your current through resistors totalling 244ohms. Currents of 4mA and 20mA will give voltage drops across them of 0.96V and 4.88V respectively. Apply those voltages to your A/D input and you will get 8bit values of 50 and 250.

Shift register right to divide by 2 gives values of 25 and 125. Now subtract 25 to get values of zero for 4mA and 100 for 20mA.
 

Hi,
Thank you pebe. However can you please tell me why divide by 2?

Here is my code, which is not working. Its displaying some garbage value on FND. Digits are not getting seprated. Where I am goin wrong?

Code:
/****************************************************************
1) RA0 is selected as input channel
2) Source is connected to RA0 pin on kit, by varying it we can have ADC result which is displayed on PORTC.
3) GO/DONE bit must be set before monitoring it for going low.
******************************************************************/




void main() {
     //int arr[10] = {0x5f,0x06,0x3b,0x2f,0x66,0x6d,0x7d,0x47,0xff,0x6f};
     
     unsigned int temp, i,x,y,z,no1,no2,no3;
     
     TRISA = 0xff;      //Set port A direction as i/p
     //TRISA = 0x00;        //Port A as output
     PORTA = 0X00;        //ALL BITS OFF
     TRISB = 0x00;        //Set port B as output
     TRISC = 0x00;        //Set PORT C as output

     ADCON0 = 0X00;       //CLOCK SELECTION Fosc/2 AND ANALOG CHANNEL SELECTION channel RA0 as input
     ADCON1 = 0X00;       //ALL CHANNELS AS ANALOG INPUT Vref is VDD
     

     //PORTA.A1 = 1;        //PORT A0 as input

     PORTB.B1 = 1;          //4 FND's are connected on PORT B1, B2, B3, B4
     PORTB.B2 = 1;
     PORTB.B3 = 1;
     PORTB.B4 = 1;

                PORTC = 0xFF;
                Delay_ms(1000);
                PORTC = 0x00;
                Delay_ms(1000);

                               while(1)

                               {
                                       ADRES = 0x00;
                                       ADCON0.ADON = 0x01;                 //Turn on the ADC
                                       ADCON0.GO = 1;
                                       while(ADCON0.GO == 1);             //Wait till conversion is goin on
                                       ADCON0.GO =0                                      
                                       ADCON0 = 0x00;                         // Stop the ADC
                                      
                                       //PORTC = ADRES;

                                                 temp = ADRES;
                                                 //x = temp/10;
                                                 no1 = temp%10;
                                                 //temp = x%10;
                                                 no2 = temp/10;
                                                 no2 = no2%10;
                                                 no3 = temp/100;
                                                 
                                                 //PORTC = no1 | 0x30;
                                                 PORTC = no1;
                                                 Delay_ms(1000);
                                                 //PORTC = no2 | 0x30;
                                                 PORTC = no2;
                                                 Delay_ms(1000);
                                                 //PORTC = no3 | 0x30;
                                                 PORTC = no3;
                                                 Delay_ms(1000);
                                                 
                                       

                                       Delay_us(2);    //Call delay 2 microseconds;
                               }

}
 
Last edited:

Hi all,
Value for ADC are now being displayed on FND now. But I am displaying it one by one. Can you guys tell me how to implement scanning mechanism so that values will be displayed at once. I know lil basic that we have to employ 'Persistance Of Vision' mechanism, but he how to implement it? What should be the time interval for scanning?

Thanking you
 

Hi,
Thank you pebe. However can you please tell me why divide by 2?

Here is my code, which is not working. Its displaying some garbage value on FND. Digits are not getting seprated. Where I am goin wrong?
The divide by 2 was to get the best resolution from the D/A. You could also have used 122ohm resistor to avoid the div/2. In either case you would need a lookup table.

I can only program in assembler. Your table looks like 'C', so I cannot read it.
 

Hi pebe,
Rest of the problems are solved now. However initial ADC value is showing 252 when it should display '0'. Why it's happening. What could be the reason? IS interrupt for ADC is necessary?

Thank you.
 

Hi all,
Value for ADC are now being displayed on FND now. But I am displaying it one by one. Can you guys tell me how to implement scanning mechanism so that values will be displayed at once. I know lil basic that we have to employ 'Persistance Of Vision' mechanism, but he how to implement it? What should be the time interval for scanning?

Thanking you

for this you have to use a timer with interrupt enabled. in the interrupt routine you have to illuminate each 7 seven segment one by one on each interrupt..
like on first int seg1 will display its coresponding value. on 2nd int second seg. will be flashed. same for remaining displays.

interrupt time for persistence of vision is 4.3 ms . you can adjust this period + or - if your displays flickers.

- - - Updated - - -

Hi all,
Value for ADC are now being displayed on FND now. But I am displaying it one by one. Can you guys tell me how to implement scanning mechanism so that values will be displayed at once. I know lil basic that we have to employ 'Persistance Of Vision' mechanism, but he how to implement it? What should be the time interval for scanning?

Thanking you

for this you have to use a timer with interrupt enabled. in the interrupt routine you have to illuminate each 7 seven segment one by one on each interrupt..
like on first int seg1 will display its coresponding value. on 2nd int second seg. will be flashed. same for remaining displays.

interrupt time for persistence of vision is 4.3 ms . you can adjust this period + or - if your displays flickers.
 

Hi nisRG,
Thanx for solution. I however used the delay routine available for PIC in microc. Its generating 5 msec delay. So its doin fine now.

Thank you.
 

Hi djc,
Is that using the setup I suggested in thread #7 ?

Hi pebe,

Till now I was struggling to get ADC work. As it is working, now i am getting reading as '007' for 0.46mA and '241' for 20.80mA. Now how to implement it the scale of 0-100 for 4-20 mA. Other values between 4-20mA should be displayed accordingly. Can you please suggest me the logic.

Thanking you.
 
Last edited:

Hi pebe,

No its not set up u told. I cant change the hardware now.I am getting reading as '007' for 0.46mA and '241' for 20.80mA. Now how to implement it the scale of 0-100 for 4-20 mA. Other values between 4-20mA should be displayed accordingly.

Thanking you
 

There is no simple way to change those readings to give 0 to 100 unless you want to write very complex software. You have decided to stick to your original hardware and you have not given any details of how you get the 4 to 20mA to a voltage suitable for the ADC, so I cannot suggest how to change that voltage.

But how are you going to display the numbers? As 0 to 100 on separate 7segment digits? And are you going to use look-up tables for the 7bits for each digit?
 

5 msec is somewhat larger.. if you have enough processor time remaining.. you can decrease by 1 or 1.5 msec... if there is no problem in your display.. (i.e. no flicker) than it is ok..

- - - Updated - - -

5 msec is somewhat larger.. if you have enough processor time remaining.. you can decrease by 1 or 1.5 msec... if there is no problem in your display.. (i.e. no flicker) than it is ok..
 

Hi pebe,

I have one meter which has current, voltage sink and source capabilities in miliamp and milivolt. Which can be varied using knob provided on meter itself. Two knobs are there one for coarse and one for fine tuning. Current can be varied from 0 mA to 20 mA. Then it is passed through the resistance of 470 Ohm which is fixed on board on which controller is fixed and then supplied to RA0 pin. Two wires from current meter coming out one is ground and one is VCC . So for maximum current for 20 mA or 20.80mA voltage at pin RA0 is about 4.80 V. If circuit draws more current then reading on meter is max 21mA and voltage regarding that is 4.84v which i measured using multimeter separately.
Now ADC gives 8 bit output so in decimal it goes upto 255. In my application its going upto 240 for 20mA current. Now i have separated these digits in software and displayed on FND connected on port B2, B3, B4. YEs I have used an array or u can say as a look up table for a particular digit. As mentioned in above code port C will be as PORTC = arr[no1], PORTC = arr[no2], PORTC = arr[no3] which will be displayed one by one using persistence of vision which is working fine. Means as mentioned in last post for 0.46mA reading on 3 FND is '007' and for maximum of near about 20 mA its '240'. Supply for controller is 5V . Now my problem is how to scale down the reading for 4-20mA into digital scale of 000-100 and and corresponding digital values for in between current values. How to implement it in software. Step size for 5v and 255 steps will be 0.01960 volt for each step. Now how to relate it for current in range for 4-20mA. I hope this information will be sufficient for you.Please guide.

Thanking you.

- - - Updated - - -

Hi nisarg

For 5 msecond too there is no flicker though i have reduced it to 4 ms to save controllers time as u suggested.

Thanking you
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top