![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
attabros
Joined: 28 Jul 2008 Posts: 35
|
DC look up Table |
Posted: Mon Aug 31, 2009 5:09 am |
|
|
I have input of 160 V DC ,I have made that scale to 3 volt to analog input to PIC 16F877A ,I want to create a look up table for 32 steps from 00000
to 11111 as the voltage decreases or increses which will output on PORT D.
Kindly Help me out for writing a software.
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
wireless
Joined: 02 Nov 2003 Posts: 16 Location: London England
|
|
Posted: Mon Aug 31, 2009 8:38 am |
|
|
Hi Attabros
Why do you need a look up table? Just read the ADC (assuming you are using a 3V reference) divide the value by 8 or right shift it 3 times and output it to the port.
Good luck
Terry |
|
![](templates/subSilver/images/spacer.gif) |
attabros
Joined: 28 Jul 2008 Posts: 35
|
|
Posted: Tue Sep 01, 2009 2:44 am |
|
|
Thanks for a quick reply,
Well I have designed an inverter the input will varies from 132.5 VDC to 198 VDC in 32 steps & the output will remain stable at 220 VAC, the reference volt is 160V DC that scale to 3V to AN0 as the voltage increases or decreses the output volt must be at 220 VAC.
Code: |
S No. A12-A8 O/P AC V LOAD Ampere I/P DC V
0 00000 220 748W 3.4 198
1 00001 220 748W 3.4 195.5
2 00010 220 748W 3.4 194.5
3 00011 220 748W 3.4 191
4 00100 220 748W 3.4 190
5 00101 220 748W 3.4 189.5
6 00110 220 748W 3.4 186
7 00111 220 748W 3.4 180.5
8 01000 220 748W 3.4 178
9 01001 220 748W 3.4 175.5
10 01010 220 748W 3.4 174.5
11 01011 220 748W 3.4 171
12 01100 220 748W 3.4 169.5
13 01101 220 748W 3.4 168
14 01110 220 748W 3.4 166
15 01111 220 748W 3.4 165.7
16 10000 220 748W 3.4 164.5
17 10001 220 748W 3.4 160.5
18 10010 220 748W 3.4 159
19 10011 220 748W 3.4 156
20 10100 220 748W 3.4 153
21 10101 220 748W 3.4 152.9
22 10110 220 748W 3.4 152
23 10111 220 748W 3.4 150
24 11000 220 748W 3.4 148
25 11001 220 748W 3.4 147.5
26 11010 220 748W 3.4 146.7
27 11011 220 748W 3.4 143.5
28 11100 220 748W 3.4 141.5
29 11101 220 748W 3.4 140
30 11110 220 748W 3.4 139
31 11111 220 748W 3.4 132.5
|
Thats why I need a look up table. The address A8-A12 will o/p on port D
to switch the output voltages.
Kindly give detail.
Just read the ADC (assuming you are using a 3V reference) divide the value by 8 or right shift it 3 times and output it to the port.
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
attabros
Joined: 28 Jul 2008 Posts: 35
|
|
Posted: Wed Sep 02, 2009 12:36 am |
|
|
Is there any simple way to read the data from Analog & output the data on port D
using the table i given above.
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
attabros
Joined: 28 Jul 2008 Posts: 35
|
|
Posted: Wed Sep 02, 2009 5:58 am |
|
|
I have write a few lines with respect to the DC volt
but not sure will it work or not can anyone guide me, please help me out
its urgent for me.
Code: |
#include <16F877A.h>
#device ICD=TRUE
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
int b,c;
float a;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
While(TRUE)
{
set_adc_channel(0);
delay_ms(50);
b=read_adc();
a=(b*5/255);
if (a==4) //for 198 DC volt
{
output_D(0x00);
}
else if(a==3.9) //for 195.5 DC volt
{
output_D(0x01);
}
else if(a==3.87) //for 194.5 DC volt
{
output_D(0x02);
}
else if(a==3.82) //for 191 DC volt
{
output_D(0x03);
}
else
{
output_D(0x00);
}
}
}
|
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 02, 2009 2:39 pm |
|
|
Here is a sample program that shows how to use a look-up table to
translate input values to output values.
Code: |
#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define ADC_LOWER_LIMIT 132
#define ADC_UPPER_LIMIT 198
// Create a lookup table that translates input
// values from 132 to 198, to output values from
// 31 to 0. This table will have 67 entries. Note
// that we use 'const' to place this table in ROM,
// to save on RAM usage.
int8 const translation_table[] = {
31, // 132
31, // 133
30, // 134
30, // 135
30, // 136
29, // 137
28, // 138
// Fill in the remaining table entries, for input values
// from 139 to 194. If the existing entries are not
// correct, then change them.
2, // 195
1, // 196
1, // 197
0 // 198
};
int8 translate_adc_value(int8 adc_value)
{
int8 index;
int8 retval;
// Do a range check on the adc value. If it's out of range,
// then force it to the lower or upper limit of the acceptable
// range.
if(adc_value < ADC_LOWER_LIMIT)
adc_value = ADC_LOWER_LIMIT;
if(adc_value > ADC_UPPER_LIMIT)
adc_value = ADC_UPPER_LIMIT;
// Subtract the lower limit (the offset) from the adc value,
// to get a convenient array index that starts at 0.
index = adc_value - ADC_LOWER_LIMIT;
// Now translate the adc value, to get the output value.
retval = translation_table[index];
// Return the output value.
return(retval);
}
//======================================
void main()
{
int i;
// Do a test of the translation routine.
for(i = ADC_LOWER_LIMIT; i < ADC_LOWER_LIMIT + sizeof(translation_table); i++)
printf("%2u %u\r", i, translate_adc_value(i));
while(1);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
attabros
Joined: 28 Jul 2008 Posts: 35
|
|
Posted: Fri Sep 04, 2009 6:00 am |
|
|
I have write some lines to the software but its not working
Code: |
void main()
{
long int reading;
float a,b;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
while(TRUE)
{
set_adc_channel(0);
delay_ms(50);
reading=read_adc(); //can be 0-1024
a=(reading*5/1023); //converting into voltage
b=(a*100);
reading=(long int)a,b; //float to long integer
if(b>400)
{
output_D(0x00);
}
else if(b>390)
{
output_D(0x01);
}
else if(b>387)
{
output_D(0x01);
}
else
{
output_toggle(PIN_D1);
delay_ms(1000);
}}}
|
as i vary the voltages the output at PIN D1 toggles , what changes should
i make so that it will read the voltages & output on port D. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|