|
|
View previous topic :: View next topic |
Author |
Message |
Arakel
Joined: 06 Aug 2016 Posts: 107 Location: Moscow
|
PIC12F675 ADC setup |
Posted: Sat Aug 06, 2016 8:57 am |
|
|
Hello! I am trying to setup the ADC on PIC12 but I do not know how exactly. Can someone assist me in this matter ? I want to setup only 2 channels of the microcontroller to be used for and ADC from 4 maximum. I need to use the 3rd and 4th pin as an I/O pin digital. The idea is to compare the values of 2 ADCs and start something with the other 4 pins if the values are different.
This code works, how do I edit it to achieve the needed result?
Code: |
#include <12F675.h>
#define GP0 PIN_A0
#device ADC=8
#fuses NOMCLR, NOWDT, NOPROTECT, INTRC_IO
#use delay(clock=4M)
//#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
unsigned int8 SetupValue = 0; //Global variables
void main() {
int i; //Local variables
unsigned int8 ADC;
//printf("Sampling:");
setup_adc_ports( ALL_ANALOG ); //Adc functions for the next 3 rows
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
do { //Takes 10 samples from pin A0 in order to avoid fluctuations from the ADC pin we have 5 volts/256 = 20mV per division
for(i = 0; i <= 10; ++i)
{
delay_ms(1);
ADC = read_adc();
if (ADC != ADC) //This may not be accurate I want to compare the value of ADC with the previous value of ADC
i = 0;
}//Close for
if (ADC > SetupValue)
output_a(0b100000);
//printf("nrMin:%x MAX: %x", min, max);
}//Close do
while (TRUE);
}
|
_________________ 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! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Sat Aug 06, 2016 10:02 am |
|
|
OK, couple of hints...
1) you'll need to select which ADC pins. IE say, AN0 and AN1.
then use
setup_adc_ports(sAN0 | sAN1);
that 'should' select AN0 and AN1 as analog inputs.
2) you also need to carefully read the data sheet ! Items like GP3 is INPUT only HAS to be considered in selecting which pin for what function !
3) more reading... this time the 'ADC' section. In there you'll read that using the 'internal ADC osc' is ONLY for when the PIC is asleep and < 1MHz clock. So, at 4 MHz you look in the chart and the MINIMUM choice would be div by 8 so
setup_adc(adc_clock_div_8);
would be appropriate
4) OBVIOUSLY you need to delete the #use RS232(...) line !!
5) naming a variable ADC is 'bad form'. Use a far better descriptive name,say ADC_8bit_value. Something that clearly details what the variable is.
6) sample 8 or 16 times , not ten. You should think "PIC". If you're going to compute an average, binary(2,4,8,16) is a LOT faster.
others will post their comments.....
this is just a start...
Jay |
|
|
Arakel
Joined: 06 Aug 2016 Posts: 107 Location: Moscow
|
Reply for the reply |
Posted: Sat Aug 06, 2016 1:36 pm |
|
|
temtronic wrote: | OK, couple of hints...
1) you'll need to select which ADC pins. IE say, AN0 and AN1.
then use
setup_adc_ports(sAN0 | sAN1);
that 'should' select AN0 and AN1 as analog inputs.
2) you also need to carefully read the data sheet ! Items like GP3 is INPUT only HAS to be considered in selecting which pin for what function !
3) more reading... this time the 'ADC' section. In there you'll read that using the 'internal ADC osc' is ONLY for when the PIC is asleep and < 1MHz clock. So, at 4 MHz you look in the chart and the MINIMUM choice would be div by 8 so
setup_adc(adc_clock_div_8);
would be appropriate
4) OBVIOUSLY you need to delete the #use RS232(...) line !!
5) naming a variable ADC is 'bad form'. Use a far better descriptive name,say ADC_8bit_value. Something that clearly details what the variable is.
6) sample 8 or 16 times , not ten. You should think "PIC". If you're going to compute an average, binary(2,4,8,16) is a LOT faster.
others will post their comments.....
this is just a start...
Jay |
Ok thank you for your reply!
Lets start:
1. I tried with set adc ports witn (AN0 | AN1) but it didnt work, I tried PIN_A0 and GP0 but no luck I did not knew i had to make it like this (sA0).
2. I know MCLR is only input that is not a problem. I disable it by default I dont intendt to use that pin unless neccessary.
3. This is useful:
this time the 'ADC' section. In there you'll read that using the 'internal ADC osc' is ONLY for when the PIC is aslee.
Thank you for that one.
I think this is set up in the declarations at the start for PIC12 probably.
Like this:
#device=8 //That means division by 8.
4. The RS232 is commented out it might be used somewhere but not here.
5.
5) naming a variable ADC is 'bad form'. Use a far better descriptive name,say ADC_8bit_value. Something that clearly details what the variable is.
Thank you for this but you are wrong. Naming the variable ADC is a psychological factor its much easier to understand the program if its simple and details like the variable type can be put in a comment.
6. Here you are right but this takes experience!
6) sample 8 or 16 times , not ten. You should think "PIC". If you're going to compute an average, binary(2,4,8,16) is a LOT faster.
Thank you for all your suggestions. I hope you do not get offended that I reply what I have done for some of them!
So I need to set up an external Oscilator? Is there no way to use the internal one on PIC12 even if its not asleep? I do not think that PIC12 can go to sleep, that should be from higher versions of PIC.
The next thing that I would request help on is that someone helps me to add assembly code in the CCS code. That way I spare memory and have direct access to the Registers. Unfortunately I do not remember all the 32 assembly functions plus I do not know which ones does PIC12 support. Perhaps the datasheet will help? _________________ 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
|
Fixed code |
Posted: Sat Aug 06, 2016 2:00 pm |
|
|
It should be allright now.
The idea is to compare a sensor voltage with an analog potentiometer voltage and if there is a difference start a heater or cooler.
The schematic is attached also.
[imt]https://drive.google.com/open
id=0B0kVHbb80xxTRjVsa2NoS0ZPbEE[/img]
Code: | #include <12F675.h>
#define GP0 PIN_A0
#device ADC=8
#fuses NOMCLR, NOWDT, NOPROTECT, INTRC_IO
#use delay(clock=4M)
//#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
unsigned int8 SetupValue = 60000000000000000; //Global variables
void main()
{
int i; //Local variables
unsigned int8 ADC_8bit_Sensor;
unsigned int8 ADC_8bit_Potentiometer;
//printf("Sampling:");
setup_adc_ports( sAN0 | sAN3 ); //Adc functions for the next 3 rows
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
do { //Takes 10 samples from pin A0 in order to avoid fluctuations from the ADC pin we have 5 volts/256 = 20mV per division
for(i = 0; i <= 15; i++)
{
delay_ms(1);
ADC_8bit_Sensor = read_adc();
if (ADC_8bit_Sensor != ADC_8bit_Sensor) //This may not be accurate I want to compare the value of ADC with the previous value of ADC
i = 0;
}//Close for
set_adc_channel( 3 ); //The next channel from which the ADC to be read
for(i = 0; i <= 15; i++)
{
delay_ms(1);
ADC_8bit_Potentiometer = read_adc();
if ( ADC_8bit_Potentiometer != ADC_8bit_Potentiometer)
i = 0;
}//Close sedond for
If ( ADC_8bit_Sensor != ADC_8bit_Potentiometer)
{
if ( ADC_8bit_Potentiometer > ADC_8bit_Sensor)
output_a(0b000001);
else output_a(0b000010);
}
}//Close do
//printf("nrMin:%x MAX: %x", min, max);
while (1);
}
|
I have another question that bothers me. When a value is read from the ADC how is it recorded in the memory, in binary format, hex or something else?
If a put a value of 5 to a variable and then compare it with the value of the ADC 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! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Sat Aug 06, 2016 2:27 pm |
|
|
#device adc=8
Does _not_ mean 'division by 8'.
It sets the code so that it only returns the high 8 bits of the ADC value.
So effectively division by 4.
Correct the divisor:
setup_adc( ADC_CLOCK_INTERNAL );
Change this to:
setup_adc(ADC_CLOCK_DIV_8);
This tell the ADC to run off the master oscillator/8.
The point about the 'internal oscillator', is that there are two. The main oscillator, and a separate one for the ADC. The separate one can be used when asleep (and the master oscillator has stopped), but has the disadvantage that if used when awake, it tends to 'beat' with the master oscillator, so you get an effect similar to 'drumming' between the two oscillators, which degrades the result from the ADC.
Just use the internal master oscillator as shown.
The adc value is just a number. _Everything_ inside the PIC is binary. 'Bases', like hexadecimal, decimal etc., are just ways for _us_ to represent numbers, that are more convenient than having to do everything in binary.
So each 'count' of the ADC (in 8bit mode), represents the reference voltage (default is the supply) /256. So just under 20mV.
So to test for a voltage of (for example) 1v, just check for the ADC value being >51.
No, he is right about not naming the voltage 'ADC'. It is 'bad form' on multiple counts:
First, in C there is a standard to reserve declarations in 'ALL CAPITALS' for things that are macros, or hardware definitions.
Then the peripheral name in many cases is reserved. So (for instance), UART1 is automatically the physical UART (on chips with one), I2C1 is the first I2C port etc. etc..
So change the variable to something like ADC_val, which is both helpful in describing what the variable actually 'is', and avoids using the peripheral name, and ALL CAPITALS.
However 'beware'. Using the supply, the value from the ADC _will_ be noisy. You need to have a little hysteresis/damping added to your test, especially for such a small signal as 5 counts (just under 0.1v). |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Sat Aug 06, 2016 2:39 pm |
|
|
another analog 'problem'....
Potentiometers, made with carbon, are NOISEY and get worse with age(use), especially if it only gets move a little, say 3 to 5 oclock, but often. Old school 'fix' is to add a capacitor on the wiper to 'dampen' the noise. In audio terms you'd hear 'scratches' , in PIC ADC, depending on how fast you sample, you'll get 'wrong' results.
Just something to be aware of. You may want to look up 'Olympic' averaging. It's just one method of getting consistant ADC results.
Also as Mt. T points out using the VDD as the Vref of the ADC is only OK for 'non demanding' projects. The simple act of the PIC turning on an LED WILL affect the VDD, which affects the ADC, which will give a 'wrong' reading. Uisng 8 bit mode , it shouldn't be a noticeable problem.
Jay |
|
|
Arakel
Joined: 06 Aug 2016 Posts: 107 Location: Moscow
|
I thank you for the replies. I appreciate your experience. |
Posted: Sat Aug 06, 2016 3:33 pm |
|
|
I thank you for the replies. I appreciate your experience and I would like to keep getting answers if possible. I want to learn the embedded programming but I do admit that I make mistakes.
Quote: |
#device adc=8
Does _not_ mean 'division by 8'.
It sets the code so that it only returns the high 8 bits of the ADC value.
So effectively division by 4.
Correct the divisor:
setup_adc( ADC_CLOCK_INTERNAL );
Change this to:
setup_adc(ADC_CLOCK_DIV_8);
This tell the ADC to run off the master oscillator/8.
The point about the 'internal oscillator', is that there are two. The main oscillator, and a separate one for the ADC. The separate one can be used when asleep (and the master oscillator has stopped), but has the disadvantage that if used when awake, it tends to 'beat' with the master oscillator, so you get an effect similar to 'drumming' between the two oscillators, which degrades the result from the ADC.
Just use the internal master oscillator as shown.
|
I corrected it.
Quote: |
The adc value is just a number. _Everything_ inside the PIC is binary. 'Bases', like hexadecimal, decimal etc., are just ways for _us_ to represent numbers, that are more convenient than having to do everything in binary.
|
I understand this and know it. But I was wondering what exactly is going on because I made a variable with a value of 600000000000 compared it to what I am taking from the ADC and it had no effect what so ever.
Quote: |
So each 'count' of the ADC (in 8bit mode), represents the reference voltage (default is the supply) /256. So just under 20mV.
So to test for a voltage of (for example) 1v, just check for the ADC value being >51.
|
I know this I calculated it in my first post I think.
Yes about 50 divisions make about 1 V.
Quote: |
No, he is right about not naming the voltage 'ADC'. It is 'bad form' on multiple counts:
First, in C there is a standard to reserve declarations in 'ALL CAPITALS' for things that are macros, or hardware definitions.
Then the peripheral name in many cases is reserved. So (for instance), UART1 is automatically the physical UART (on chips with one), I2C1 is the first I2C port etc. etc..
So change the variable to something like ADC_val, which is both helpful in describing what the variable actually 'is', and avoids using the peripheral name, and ALL CAPITALS.
|
I understand.
Quote: |
However 'beware'. Using the supply, the value from the ADC _will_ be noisy. You need to have a little hysteresis/damping added to your test, especially for such a small signal as 5 counts (just under 0.1v).
|
I think thats standard practice for catching the ADC ref from VDD as far as I have seen and been told until now. But I am not catching Vref for the ADC, I am just using the signal in order to input something to channel zero so I can test.
Yes the idea is to use 0.01 or 0.02 Volts because I am using LM335 which gives 0.01 Volts per degree. The accuracy can be 1-3 degrees its not a problem.
Quote: |
another analog 'problem'....
Potentiometers, made with carbon, are NOISEY and get worse with age(use), especially if it only gets move a little, say 3 to 5 o'clock, but often. Old school 'fix' is to add a capacitor on the wiper to 'dampen' the noise. In audio terms you'd hear 'scratches' , in PIC ADC, depending on how fast you sample, you'll get 'wrong' results.
|
They also change their value with the temperature.
You are right, one filter capacitor will be useful plus I should put the potentiometer as close as possible to the PIC. I did not think of that.
Quote: |
Just something to be aware of. You may want to look up 'Olympic' averaging. It's just one method of getting consistant ADC results.
|
I will look it up when I have time.
Quote: |
Also as Mr. T points out using the VDD as the Vref of the ADC is only OK for 'non demanding' projects. The simple act of the PIC turning on an LED WILL affect the VDD, which affects the ADC, which will give a 'wrong' reading. Using 8 bit mode, it shouldn't be a noticeable problem.
Jay
|
I think 10 bit mode will not be a problem here.
The idea is to measure temperature and if it's 3 degrees off it should not be a big deal.
This is the last code plus the schematic.
Code: | #include <12F675.h>
#define GP0 PIN_A0
#device ADC=10
#fuses NOMCLR, NOWDT, NOPROTECT
#use delay(clock=4M)
//#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
void main()
{
int i; //Local variables
unsigned int8 ADC_8bit_Sensor;
unsigned int8 ADC_8bit_Potentiometer;
//printf("Sampling:");
setup_adc_ports( sAN0 | sAN1 ); //Adc functions for the next 3 rows
setup_adc( ADC_CLOCK_DIV_10 );
while(TRUE)
{
set_adc_channel( 0 );
//Takes 10 samples from pin A0 in order to avoid fluctuations from the ADC pin we have 5 volts/256 = 20mV per division
for(i = 0; i <= 15; i++)
{
delay_ms(1);
ADC_8bit_Sensor = read_adc();
if (ADC_8bit_Sensor != ADC_8bit_Sensor) //This may not be accurate I want to compare the value of ADC with the previous value of ADC
i = 0;
}//Close for
set_adc_channel( 1 ); //The next channel from which the ADC to be read
for(i = 0; i <= 15; i++)
{
delay_ms(1);
ADC_8bit_Potentiometer = read_adc();
if ( ADC_8bit_Potentiometer != ADC_8bit_Potentiometer)
i = 0;
}//Close second for
If ( ADC_8bit_Sensor != ADC_8bit_Potentiometer)
{
if ( ADC_8bit_Potentiometer < ADC_8bit_Sensor)
{
output_a(0b000100);
} else output_a(0b000000);
}
//printf("nrMin:%x MAX: %x", min, max);
}//Clow while
} |
[img]https://drive.google.com/open?id=0B0kVHbb80xxTVXlHdTNtMFJYRnc[/img] _________________ 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! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Sat Aug 06, 2016 4:56 pm |
|
|
one problem....
re: adc clock choice
cut from the CCS 12F675 header
Code: |
// Constants used for SETUP_ADC() are:
#define ADC_OFF 0 // ADC Off
#define ADC_CLOCK_DIV_2 0x100
#define ADC_CLOCK_DIV_4 0x40
#define ADC_CLOCK_DIV_16 0x50
#define ADC_CLOCK_DIV_32 0x20
#define ADC_CLOCK_DIV_64 0x60
#define ADC_CLOCK_INTERNAL 0x30 // Internal 2-6us
|
you've coded...
Code: | setup_adc( ADC_CLOCK_DIV_10 ); |
which should fail !
When programming PICs, 'think' like a PIC, binary.
this
Code: | #define ADC_CLOCK_DIV_8 0x10 |
would be my choice.
Also you're not getting the average of 16 readings and then doing something, rather; IF I read it right, you take a reading, then another and if the 2nd <>1st, start all over. If that's how it is coded, then odds are real good it could stay in that loop forever !
You need to know that any ADC is always +-1 digit, so 127, 128, 129 are all valid for a true, spam 128 reading. Now IF you've got a super stable Vref (NOT VDD) and 8 bit mode ( 20mv/bit), yes, it'd 'probably' work but...not really 'good form'.
Olympic average is to take 10 samples, toss out highest, toss out lowest, average the remaining 8. There are examples of it here (search for 'olympic average"). The PIC makes quick work of avg of 8 as it's a simple right right>3 places.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Sun Aug 07, 2016 12:16 am |
|
|
The key big thing missing though, is if you switch the ADC to 10bit mode, then the variable that you use to hold the result must be 10bit or larger (int16). Currently you are trying to put a 10bit ADC value into an 8bit integer.....
Then you talk about 'variable with a value of 600000000000'. No. You are not using any variables that can hold a number this big. Even an int32, can only hold a maximum value of 4294967295......
10bit number = 0 to 1023.
int16 variable = 0 to 65535 maximum. |
|
|
Arakel
Joined: 06 Aug 2016 Posts: 107 Location: Moscow
|
Ok I understand a part of this. Let me work on it |
Posted: Sun Aug 07, 2016 7:19 am |
|
|
I understand a part of this, let me work on it for a few days, unfortunately I am working on 12 hour shifts so it will be difficult, since I sleep during the day and have 4 hours transportation.
Quote: |
cut from the CCS 12F675 header
Code:
// Constants used for SETUP_ADC() are:
#define ADC_OFF 0 // ADC Off
#define ADC_CLOCK_DIV_2 0x100
#define ADC_CLOCK_DIV_4 0x40
#define ADC_CLOCK_DIV_16 0x50
#define ADC_CLOCK_DIV_32 0x20
#define ADC_CLOCK_DIV_64 0x60
#define ADC_CLOCK_INTERNAL 0x30 // Internal 2-6us
you've coded...
Code:
setup_adc( ADC_CLOCK_DIV_10 );
which should fail !
When programming PICs, 'think' like a PIC, binary.
this
Code:
#define ADC_CLOCK_DIV_8 0x10
would be my choice.
|
Well in the PIC12F675 datasheet it says that this pic has 4 channels of 10 bit ADCs, so I do not see why this is a problem? The header should include it.
I understand that its an 8 bit microcontroller which records 8 bits in one register of data and a 14 bit microcontroller which records 14 bits in one register of instructions. Its made with a harvard architecture which means that it can include more instructions in 14 bit than normally 2 on 14.
I do not exactly understand the process of the ADC. A normal ADC would be made in some of the ADC bulding ways, but I do not know how is this one made and how it records the data.
Quote: |
Also you're not getting the average of 16 readings and then doing something, rather; IF I read it right, you take a reading, then another and if the 2nd <>1st, start all over. If that's how it is coded, then odds are real good it could stay in that loop forever !
|
I understand this part. I have mislead myself because this is how you debounce a button to see if its '1' or '0' but here I should use the olympyc mode that you mentioned. Actually it means the middle value of 10 samples as far as I understand, therefore 4 samples will be enough if I use the method middle crawling.
Quote: |
You need to know that any ADC is always +-1 digit, so 127, 128, 129 are all valid for a true, hard 128 reading. Now IF you've got a super stable Vref (NOT VDD) and 8 bit mode ( 20mv/bit), yes, it'd 'probably' work but...not really 'good form'.
|
I do not understand this one. What do you mean +- 1 digit? Is that +-1 digit off? What is valid for a true, hard 128 reading? I do not know the good form I am learning here.
Quote: |
Olympic average is to take 10 samples, toss out highest, toss out lowest, average the remaining 8. There are examples of it here (search for 'olympic average"). The PIC makes quick work of avg of 8 as it's a simple right right>3 places.
|
This is not even middle crawling its only the middle value of 10 samples. I think middle crawling would be better.
Quote: |
The key big thing missing though, is if you switch the ADC to 10bit mode, then the variable that you use to hold the result must be 10bit or larger (int16). Currently you are trying to put a 10bit ADC value into an 8bit integer.....
Then you talk about 'variable with a value of 600000000000'. No. You are not using any variables that can hold a number this big. Even an int32, can only hold a maximum value of 4294967295......
10bit number = 0 to 1023.
int16 variable = 0 to 65535 maximum.
|
Yes. I overlooked this. I need a variable like int16.
Thats not the problem here that I am recording 60000000. I tried with comparing 5 to 0, 1 to 0 and 6000000 to 0 and there was no effect. Thats why I ask if I assign a value to a variable for instance 5 and compare it with the ADC recorded value is there any difference how its recorded? Should I use the binary operator to compare it Assigned_Value_5 ^= ADC_8bit_value or something else? _________________ 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! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Sun Aug 07, 2016 8:04 am |
|
|
You really need to read the datasheet and application notes from Microchip. I understand english is not everyone's first language but it is for Microchip.
As for the ADC. When you look at the 675 header file, in the ADC section, you will NOT see 'adc_clock_div_10 so you CANNOT use it. In fact the compiler WILL flag it as an error and quit. PICs like all computers work in binary go the valid adc clock divisors will all be multiples of 2 (2, 4, 8, 16, etc.) but you have to look at the datasheet, adc section of which PIC you're using as the choices will be different for different PICs. THAT is WHY it is crucial to read the data sheets and look at the PIC header file.
Now all ADC devices are always +-1 digit. a 10 bit ADC reading is x+-1 digit, the last bit( the least significant) can either be a '1' or a '0' even though the analog input might be stable. This is because it is converting from an analog signal to a digital signal, you can never be 100% correct all the time. This is one reason why you normally take several samples and average them. Why you use 4, 8, 16 samples is because the PIC compiler is very,very smart and will quickly (1 instruction) compute the average simply by right shifting the number, say by 3 place if 8 samples are taken. when you sample say 6 or 9, then there is a LOT of 'math' involved, which takes a LOT longer. If you write a test program for 6 samples vs 8, compile, dump the listing you'll see it is FASTER to take 8 and get an average than to take samples than 6 and average them !
Setting a variable beyond it's limit (say 6,000,000 in your case) probably should make the compiler quit. If it does finish, the variable will not have 6 million in it, rather a 'truncate' number. You could figure it out by representing 6 million in binary and then only taking the right most 8 bits or 16 bits. Also be aware that the ADC is +ve only input, so comparisons should be done with unsigned numbers (0-255, 0-1023).
Jay
Jay |
|
|
Arakel
Joined: 06 Aug 2016 Posts: 107 Location: Moscow
|
|
Posted: Thu Aug 11, 2016 7:06 pm |
|
|
temtronic wrote: | You really need to read the datasheet and application notes from Microchip. I unbderstand english is not everyone's first language but it is for Microchip .
|
I have no problem with English. My problem is the 130 to 600 pages. Thats too much for a datasheet!
Ok I understand thank you! I can change the output of the sensor with an amplifier and make it 0.1 volts. Perhaps that would give more accurate results? One Operational amplifier should work. _________________ 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
|
|
Posted: Sun Sep 18, 2016 2:26 am |
|
|
Hello! I am sorry for the long delay, I have a lot of work. The idea is like this:
[img]https://drive.google.com/open?id=0B0kVHbb80xxTdjNDRWdqbmUxYWM[/img] _________________ 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
|
Message towards my tutors |
Posted: Fri Sep 30, 2016 7:23 pm |
|
|
I hope you did not get angry at me for some reason. Sometimes I tend to overextend things, that is true.
Thank you for everything, when I have time I will start working on my next project. This one had great educational value! _________________ 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! |
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Sat Oct 01, 2016 2:26 am |
|
|
Hi Arakel! You seem to have a lot of motivation, and if you master PICs it might get you a better job (it did for me! I got an advice from a friend to learn PICs and have been working, enjoying, and earning well for more than 15 years).
I see you have strong theoretical background but you have some 'holes' in your understanding and the practical aspects. For example comparing 2 analog values makes sense in theory but in real life, with noise on both signals, comparing them would be done (just an example) :
Code: | #define HYSTERESIS 5 // 5*20mV = 100mV
if(sensorRead>poten+HYSTERESIS) output_high(COOLER);
else if(sensorRead<poten) output_low(COOLER);
if(sensorRead<poten-HYSTERESIS) output_high(HEATER);
else if(sensorRead>poten) output_low(HEATER);
|
My advice is to get your hands on a slightly larger PIC with PIC-KIT3 and start building and experimenting. No simulations. |
|
|
|
|
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
|