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

Clarification for PIC16F690
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Sat Nov 19, 2016 9:05 am     Reply with quote

temtronic wrote:
1) this...
Display = (ADC_10bit_Sensor - 3.13)/0.01;

May not give you the numbers you think it should...
Have you sent the 'display' variable to a PC to see what the numbers really are? Confirm that the range and type are correct?

2)since you're using 2 4511s, another fast/accurate way to send the data is to have a simple table that is 100 elements long.Old school, no math is needed,you just have to manually (or eXcel) create the table once.IE element 24 will have 0b00100100 in it, so 0010 goes to 10s digit 4511, 0100 goes to 1s digit 4511. If you've got the code space for it,it is that simple.....

Jay


1. Based on the datasheet of LM335, the sensor gives 2.7315 volts at 0 degrees. At 3.1315Volts it should be 40 degrees. From there we have
(ADC_10bit_Sensor-3.13)/0.01Volts, because the sensor gives 10mV per degree Celsius. I will try it with 2.73 and see what I get. Maybe it should be float? Can I use int16 instead of float?

2. I have thought of this, but this is not the proper form for coding and the memory is a limited resource on these tiny MCUs so it is not a good idea?

I am looking for the macro, but I could not find it in the forum and I am wondering will it work with two 4511 ICs or does it only work with one 8bit IC. Can I find it in the CCS help section and where in that section if possible? I am trying to learn the proper form for coding, so I can do it right from now on!

Another problem that I came across is how to represent the minus.

These are a few problems that I need answered:
If I use this "Result = Variable/10" and the Result and Variable are int8 will I get a float result or only an int result?
Example: "Result = 25/10 = 2"? or "Result = 25/10 = 2.5" ?

For this equation Display = (ADC_10bit_Sensor - 2.73)/0.01;
What do "Display" and "ADC_10bit_Sensor" have to be int8 or float?

If "ADC_10bit_Sensor" is int8 will I get an accurate result after the point? Meaning will I get 3.12Volts or will I get 3 volts?

I am sorry for the stupid questions it was a long time ago since I programmed, I know that the variables are the first step. I know float should be 16 bits from the standard C99 variables and in CCS, but 3.13Volts can be represented with 8 bits also and I believe int8 works!
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Sat Nov 19, 2016 9:45 am     Reply with quote

This is the biggest problem of the code. Making 2 displays with 2 ICs is very difficult. If I use one IC or a macro without an IC it would be easier I guess? Any recommendations for an IC?

Code:
 Display = (ADC_10bit_Sensor - 2.73)/0.01;
       
      /*   FirstDigit = Display%10;      // These two lines are when we use 2 tables for digits for the first
         SecondDigit = Display/10; */  //and for the second digit instead of one table with all numbers
      
      for(i=0; i<=70; i++)
      {
         if (Display == i)
            FinalFormOfThePORTCOutput ^= TableForDigits[i];
      }
      //FinalFormOfThePORTCOutput ^= BinaryFormOfSecondDigit + BinaryFormOfFirstDigit;
      
      output_c(FinalFormOfThePORTCOutput);
       delay_us(100);

_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Sat Nov 19, 2016 10:41 am     Reply with quote

This should work?
Code:

const unsigned int8 TableForDigits[10] = {
      
      0b00000000, //Output for "0" for the first display from "FirstDigit = Display / 10"
      0b00000001, //1
      0b00000010, //2
      0b00000011, //3
      0b00000100, //4
      0b00000101, //5
      0b00000110, //6
      0b00000111, //7
      0b00001000, //8
      0b00001001, //9

 Display = (ADC_10bit_Sensor - 2.73)/0.01;
       
      FirstDigit = Display%10;     
       SecondDigit = Display/10;   
      
       for(i=0; i<10; i++)
      {
         if (FirstDigit == i)
            BinaryFormOfFirstDigit = TableForDigits[i];
         if(SecondDigit == i)
            BinaryFormOfSecondDigit = TableForDigits[i];
      }
      BinaryFormOfSecondDigit >>4;
      FinalFormOfThePORTCOutput = BinaryFormOfSecondDigit | BinaryFormOfFirstDigit;
      output_c(FinalFormOfThePORTCOutput);


But you are right about this part:

Code:

Display = (ADC_10bit_Sensor - 2.73)/0.01;
       
      FirstDigit = Display%10;     
       SecondDigit = Display/10;


How do I make it accurate?
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Ttelmah



Joined: 11 Mar 2010
Posts: 20059

View user's profile Send private message

PostPosted: Sat Nov 19, 2016 1:31 pm     Reply with quote

Float is 32bits, comprising a 23bit mantissa and an 8bit exponent.

An int8, can hold the integer values 0, 1, 2, 3, 4.... 255 only. Nothing close to or resembling 3.13.

Don't get involved in floats. These are slow, and bulky.

You are starting with an integer (an int16) from the ADC. Can be an integer from 0 to 1023. You are then treating this as if I suspect you think it is a float from 0 to 5?.

Then you waste time everywhere. /0.01, is the same as *100, but the former takes at least twice as long as the latter.
Then you combine two binary values that occupy the same locations in the byte.
Then if your value was 0 to 5, what would happen to values below 3.13?. You'd have -ve results, but there is no sign of this being considered.
Then what on earth is the point of counting through 0 to 9?. All you need to do is read the value from the array. Again waste.

You have huge amounts of wrong code, that is heading in wrong directions. Start simpler. Just et a display routine that can successfully count through and display the numbers from 0 to 99. Once you have this working, then work out how to convert the input adc value (remember 0 to 1023) to this range. Try to do this only using binary divisions, and simple multiplications, in an integer. Then combine these.

Your %10 /10 code, generates the two BCD digits, but does it in just about the most inefficient way possible. An efficient BCD converter, will take perhaps 1/10 the time and less code space as well.

You are firing in very much the wrong direction in lots of places.
temtronic



Joined: 01 Jul 2010
Posts: 9632
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 19, 2016 1:50 pm     Reply with quote

Regarding the table to send data to 4511s. Since the display is only 2 digit (00-99) you only need 100 memory locations out of the 4096 that the PIC has, so a table is easily done.

Also since the display is only 2 digits, a temperature can only be, say, 32 or 33 *C, you can never ever display 32.1234*C.

I'd create the table, then code the 'analog' portion of code to use the 'adc result' to 'select' the table element that is equal to the temperature. So 32*C would select element 32 of the table, which has 0b00110010. That data gets sent to the 4511s and '32' will get displayed on the LEDs.


As MR. T points out, get the display working first, then the analog.

Jay
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Sun Nov 20, 2016 4:40 am     Reply with quote

I will make the table, however I never tried to display 32.123123. The reason for such a variable is because I get 2.73V from the sensor for 0 degrees centigrade and 10mV per degree, so there is no way to to find the degrees I have except: (Sensor-2.73V)/10mV, than if I have (3.0V-2.73V)/10mV=27 degrees.
If I make it with a table will it be accurate? Because I have to 2.73V as 0 degrees and so on by 10mV.

As for the minus I did consider it. The temperature will be from -9 degrees to 50 degrees, so I can use the first display for the minus. The ICs tolerance is -20 degrees to 80 degrees. If I decide to make it to -15 I will use the dot on the display to show it is minus.

Lets see what will happen with the table. I hope I start going in the right directions. This is the point of learning.

The easiest way will be with the macro, but I am looking for it still.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Sun Nov 20, 2016 5:22 am     Reply with quote

I did the table but my problem is still the ADC.
When the value of 2.7323213 volts is read from the ADC in to a unsigned int16 ADC_10bit_Sensor variable, what will I get in that variable?

Will it be 2.7323213 or 27323213? How do I compare it with 2.73? I think it should automatically remove everything after the "3" and if the first digits are the same give an accurate result? Maybe there is some operator for almost accurate comparison?
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Ttelmah



Joined: 11 Mar 2010
Posts: 20059

View user's profile Send private message

PostPosted: Sun Nov 20, 2016 5:42 am     Reply with quote

You are still missing a lot of quite fundamental things.
The ADC does not return a voltage. It returns a simple 10bit number from 0 to 1023, for the the voltage range from it's Vref- to Vref+ (actually it'd go to 1024 at the Vref+, but can never do this, so it stops a little below Vref+ - see below).
So if you are using the 5v supply as your 'reference', at 0C, the LM335, will give an output of 559.

ADC step size = Vref Range/total steps.

Now if the PIC ADC game 0 to 1023 over the range Vref- to Vref+, there would actually be 1023 'rises' (in a stair, there is one less 'riser' than 'steps'). This is why the PIC ADC is built so it behaves as if it went 0 to 1024, but the '1024' is missing. So there are 1024 'rises' over the working range.
So with 5v 'Vref', the ADC step size is 0.00488v (5/1024), and at 2.73v, you would see 2.73/0.00488 = 559.1 counts - however integer, so just 559.

Note that this is very near to 5mV/ADC step.

At 25C, you will see 610 counts.

Now the 'integer' conversion to a degree count then is:

Code:

    //arrive here with adc reading in an int16 'adc_value'
    int16 temp;
    int1 sign;
    //Now this needs to be signed to handle -ve temperatures

    if (adc_value<559)
    {
        //here we have a negative temperature
        sign = TRUE;
        temp=559-adc_value;
    }
    else
    {
        sign = FALSE;
        temp=adc_value-559;
    }
    temp/=2; //because adc Step almost == 5mV
    //At this point we have a integer 'temp' in degrees, and a separate
    //'sign' bit     


Now the 'table' only needs to hold the values you need to output. Nothing more. So 51 entries only for the range you are talking about.

Now let me give a couple of example calculations:

-5C Volts = 2.68. adc_value = 2.68/0.00489 = 548

This is <559, so the code will set the 'sign' bit. Then temp=559-548 = 11. This will just be divided by 2 (integer again), to give '5'. So with the sign bit, -5.

30C Volts = 3.03. adc_value = 619

Sign bit is then cleared. temp = 60 (619-559). This will just be divided by 2, to give '30'.

50C Volts = 3.23. adc_value = 660

Sign again cleared. temp = 101. /2=50.

So this (over this range), gives you a nice integer count of degrees, with a separate sign bit.

So then you just code the patterns required to display '0', '1' etc., into an array. Then test if 'temp>50'. If so display something like '--' for 'over range'. Otherwise just read the array[temp] value, and output this to the display.

Now, you are probably going to have to damp this a little. The odds are that using the Vdd as the Vref, this _will_ change as digits are turned on, and other things happen in the circuit.
temtronic



Joined: 01 Jul 2010
Posts: 9632
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Nov 20, 2016 6:48 am     Reply with quote

hmm.. the 4511 can only display 0,1,..,9 no 'minus' sign possible. There's also no access to the decimal point. I had to reread the 4511 datasheet as I wondered about the negative temperatures to display.
One possible solution is to have '02' represent '-2'. That IS possible with the 4511 chip. ' 2' will be +2*C. The 10s digit is blank.
For 'overrange' ,perhaps '88' ? 88 should be displayed on powerup to confirm the display does show all segments of both LEDs.


Jay
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Sun Nov 20, 2016 7:57 am     Reply with quote

Ttelmah wrote:
You are still missing a lot of quite fundamental things.
The ADC does not return a voltage. It returns a simple 10bit number from 0 to 1023, for the the voltage range from it's Vref- to Vref+ (actually it'd go to 1024 at the Vref+, but can never do this, so it stops a little below Vref+ - see below).
So if you are using the 5v supply as your 'reference', at 0C, the LM335, will give an output of 559.

ADC step size = Vref Range/total steps.

Now if the PIC ADC game 0 to 1023 over the range Vref- to Vref+, there would actually be 1023 'rises' (in a stair, there is one less 'riser' than 'steps'). This is why the PIC ADC is built so it behaves as if it went 0 to 1024, but the '1024' is missing. So there are 1024 'rises' over the working range.
So with 5v 'Vref', the ADC step size is 0.00488v (5/1024), and at 2.73v, you would see 2.73/0.00488 = 559.1 counts - however integer, so just 559.

Note that this is very near to 5mV/ADC step.

At 25C, you will see 610 counts.

Now the 'integer' conversion to a degree count then is:

Code:

    //arrive here with adc reading in an int16 'adc_value'
    int16 temp;
    int1 sign;
    //Now this needs to be signed to handle -ve temperatures

    if (adc_value<559)
    {
        //here we have a negative temperature
        sign = TRUE;
        temp=559-adc_value;
    }
    else
    {
        sign = FALSE;
        temp=adc_value-559;
    }
    temp/=2; //because adc Step almost == 5mV
    //At this point we have a integer 'temp' in degrees, and a separate
    //'sign' bit     


Now the 'table' only needs to hold the values you need to output. Nothing more. So 51 entries only for the range you are talking about.

Now let me give a couple of example calculations:

-5C Volts = 2.68. adc_value = 2.68/0.00489 = 548

This is <559, so the code will set the 'sign' bit. Then temp=559-548 = 11. This will just be divided by 2 (integer again), to give '5'. So with the sign bit, -5.

30C Volts = 3.03. adc_value = 619

Sign bit is then cleared. temp = 60 (619-559). This will just be divided by 2, to give '30'.

50C Volts = 3.23. adc_value = 660

Sign again cleared. temp = 101. /2=50.

So this (over this range), gives you a nice integer count of degrees, with a separate sign bit.

So then you just code the patterns required to display '0', '1' etc., into an array. Then test if 'temp>50'. If so display something like '--' for 'over range'. Otherwise just read the array[temp] value, and output this to the display.

Now, you are probably going to have to damp this a little. The odds are that using the Vdd as the Vref, this _will_ change as digits are turned on, and other things happen in the circuit.


Yes, now I understand. Just like a digital potentiometer. We have the value from 0 to 1023 which is equal to 1024 values because the "0" also counts. I am going to work for a few night shifts so I will be busy the next days. Do not take it personal if I do not reply. Thanks for the help. I will see what will happen.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!


Last edited by Arakel on Sun Nov 20, 2016 8:02 am; edited 1 time in total
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Sun Nov 20, 2016 8:00 am     Reply with quote

temtronic wrote:
hmm.. the 4511 can only display 0,1,..,9 no 'minus' sign possible. There's also no access to the decimal point. I had to reread the 4511 datasheet as I wondered about the negative temperatures to display.
One possible solution is to have '02' represent '-2'. That IS possible with the 4511 chip. ' 2' will be +2*C. The 10s digit is blank.
For 'overrange' ,perhaps '88' ? 88 should be displayed on powerup to confirm the display does show all segments of both LEDs.


Jay


Yes you are right. There is not option for minus except the middle LED which can be lit to show minus on the first display for the digits from 1 to 9. But for 15 it will take a third display or one external LED to show that the temperature is under zero. If the LED is lit the temperature is under 0 if not it is over zero.

I forgot that testing with 88 is common practice to see if all diodes are working. Thank you!
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Ttelmah



Joined: 11 Mar 2010
Posts: 20059

View user's profile Send private message

PostPosted: Sun Nov 20, 2016 10:34 am     Reply with quote

Almost... Smile

Visualise the ADC returned 0 to 7. A 3 bit ADC.

The Vref range was 5v.

Then for a 'standard' ADC layout (which was used for some early ADC's - a couple of the very earliest PIC's were like this), you have 8 'levels', but only 7 'rises'. So you'd actually need to divide by 7 to get the rise/step. Now small processors take a long time to do maths. /8 can be done simply by rotating 3 times. However /7, is vastly more work. This was realised by Texas and they built an ADC which behaved as if it actually went 0 to 8 (the first one to do this was actually an 8bit ADC), so 0 to 256, but outputting the same value for both the top two levels.

So the PIC ADC reaches 1023, 1.5 bits 'below' the Vref+, and behaves as if it actually counted to 1024.
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

Half of the job is done!
PostPosted: Wed Nov 30, 2016 1:20 am     Reply with quote

Here is the working code for temperature from "0" to "50". It will go to "59" but that will be left so we may have some tolerance.

It gives an error of 1 degree, which is good according to me since LM335 gives and error of 1 degrees anyway.

When I have time I will make the "minus" also.
Code:

//A program to scan the values of an ADC and potentiometer and start a heater if they are different with the debouncing routine
#include <16F690.h>

#device ADC=10

#fuses NOMCLR, NOWDT, NOPROTECT, INTRC_IO
#use delay(clock=4M)

void main()
{
   
   int i,z;     //Local variables
   unsigned int16 ADC_10bit_Sensor;
   unsigned int16 ADC_10bit_Potentiometer;
   unsigned int16 OutputDigit;
   unsigned int8 FinalFormOfThePORTCOutput[70] =
   {
      0b00000000, // 0
      0b00000001,
      0b00000010,
      0b00000011,
      0b00000100,
      0b00000101,
      0b00000110,
      0b00000111,
      0b00001000,
      0b00001001,
      0b00010000, // 10
      0b00010001,
      0b00010010,
      0b00010011,
      0b00010100,
      0b00010101,
      0b00010110,
      0b00010111,
      0b00011000,
      0b00011001,
      0b00100000, // 20
      0b00100001,
      0b00100010,
      0b00100011,
      0b00100100,
      0b00100101,
      0b00100110,
      0b00100111,
      0b00101000,
      0b00101001,
      0b00110000, // 30
      0b00110001,
      0b00110010,
      0b00110011,
      0b00110100,
      0b00110101,
      0b00110110,
      0b00110111,
      0b00111000,
      0b00111001,
      0b01000000, // 40
      0b01000001,
      0b01000010,
      0b01000011,
      0b01000100,
      0b01000101,
      0b01000110,
      0b01000111,
      0b01001000,
      0b01001001,
      0b01010000, // 50
      0b01010001,
      0b01010010,
      0b01010011,
      0b01010100,
      0b01010101,
      0b01010110,
      0b01010111,
      0b01011000,
      0b01011001,
   };
      
      
   
   setup_comparator(NC_NC_NC_NC);
   
   setup_adc_ports( sAN0 | sAN1 );   //Adc functions
   setup_adc( ADC_CLOCK_DIV_16 );
   
   while(TRUE)
   {
     
   set_adc_channel( 0 );   //We set the ADC to read from CHANNEL 0 (Where the potentiometer is connected)
   for(i=0; i<16; i++)
   {
      delay_ms(1);
      ADC_10bit_Potentiometer = read_adc();
         if(ADC_10bit_Potentiometer != ADC_10bit_Potentiometer)
            i=0;
   }
   
   set_adc_channel( 1 );   //We set the ADC to read from CHANNEL 1 (Where the sensor is connected)
   for (i=0; i<16; i++)
   {
      delay_ms(1);
      ADC_10bit_Sensor = read_adc();
      if (ADC_10bit_Sensor != ADC_10bit_Sensor)
         i=0;
   }
   
         if (ADC_10bit_Sensor <= ADC_10bit_Potentiometer)    //If the potentiometer is lower than the sensor turn OFF the heater
       {
          delay_ms(1);
          output_b(0b00010000);
       } else {
         output_b(0b00000000);
       }
      OutputDigit = ((ADC_10bit_Sensor*0.0048828125) - 2.82276)/ 0.01163;
      
      output_c(FinalFormOfThePORTCOutput[OutputDigit]);
         
 }//Close while
}

_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

Thanks to everyone for the help!
PostPosted: Fri Dec 02, 2016 3:02 pm     Reply with quote

Everything is working including the minus! The diode for the minus is on "PIN_B5"!

The only thing that bothers me is how to stop the "Minus_LED" from flashing, but if I remove the delay there might be RWM?

Code:
//A program to scan the values of an ADC and potentiometer and start a heater if they are different with the debouncing routine
//The difference is that the minus degrees on the display are with a different coding realization

#include <16F690.h>

#device ADC=10

#fuses NOMCLR, NOWDT, NOPROTECT, INTRC_IO
#use delay(clock=4M)

#define Minus_LED PIN_B5

void main()
{
   
   int i,z;     //Local variables
   unsigned int16 ADC_10bit_Sensor;
   unsigned int16 ADC_10bit_Potentiometer;
   unsigned int16 OutputDigit;
   unsigned int8 FinalFormOfThePORTCOutput[80] =
   {
      0b00000000, // 0
      0b00000001,
      0b00000010,
      0b00000011,
      0b00000100,
      0b00000101,
      0b00000110,
      0b00000111,
      0b00001000,
      0b00001001,
      0b00010000, // 10
      0b00010001,
      0b00010010,
      0b00010011,
      0b00010100,
      0b00010101,
      0b00010110,
      0b00010111,
      0b00011000,
      0b00011001,
      0b00100000, // 20
      0b00100001,
      0b00100010,
      0b00100011,
      0b00100100,
      0b00100101,
      0b00100110,
      0b00100111,
      0b00101000,
      0b00101001,
      0b00110000, // 30
      0b00110001,
      0b00110010,
      0b00110011,
      0b00110100,
      0b00110101,
      0b00110110,
      0b00110111,
      0b00111000,
      0b00111001,
      0b01000000, // 40
      0b01000001,
      0b01000010,
      0b01000011,
      0b01000100,
      0b01000101,
      0b01000110,
      0b01000111,
      0b01001000,
      0b01001001,
      0b01010000, // 50
      0b01010001,
      0b01010010,
      0b01010011,
      0b01010100,
      0b01010101,
      0b01010110,
      0b01010111,
      0b01011000,
      0b01011001,
   };
   
      
      
   
   setup_comparator(NC_NC_NC_NC);
   
   setup_adc_ports( sAN0 | sAN1 );   //Adc functions
   setup_adc( ADC_CLOCK_DIV_16 );
   
   while(TRUE)
   {
     
   set_adc_channel( 0 );   //We set the ADC to read from CHANNEL 0 (Where the potentiometer is connected)
   for(i=0; i<15; i++)
   {
      delay_ms(1);
      ADC_10bit_Potentiometer = read_adc();
         if(ADC_10bit_Potentiometer != ADC_10bit_Potentiometer)
            i=0;
   }
   
   set_adc_channel( 1 );   //We set the ADC to read from CHANNEL 1 (Where the sensor is connected)
   for (i=0; i<15; i++)
   {
      delay_ms(1);
      ADC_10bit_Sensor = read_adc();
      if (ADC_10bit_Sensor != ADC_10bit_Sensor)
         i=0;
   }
   
         if (ADC_10bit_Sensor <= ADC_10bit_Potentiometer)    //If the potentiometer is lower than the sensor turn OFF the heater
       {
          delay_ms(1);
          output_b(0b00010000);
       } else {
         output_b(0b00000000);
       }
      
      {
         
         if (ADC_10bit_Sensor >= 578) //578 equals zero, this is only for the positive digits
         {
         OutputDigit = ((ADC_10bit_Sensor*0.0048828125) - 2.82276)/ 0.01163;
         output_c(FinalFormOfThePORTCOutput[OutputDigit]);
         }
      }
      if (ADC_10bit_Sensor < 578)
      {
         OutputDigit = ((ADC_10bit_Sensor*0.0048828125) - 2.82276)/ (-0.01163);
         output_c(FinalFormOfThePORTCOutput[OutputDigit]);
         delay_ms(1);
         output_high(Minus_LED);
         delay_ms(1);
      }
      
         
 }//Close while
}

_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Mon Dec 05, 2016 5:13 pm     Reply with quote

I thank to: Ttelmah, temtronic !
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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