Pages: 1 [2]   Go Down
Author Topic: Tricky question about multiple sleep modes in same sketch  (Read 1225 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I had wondered about the tiny85 which I actually have here but my main project uses every single pin. Infact my main project uses so many pins I'm tempted to have a 2nd 328p just so a can get the extra analog pins for a temperature sensor and two hall effect sensors for current in and current out. Also more digital pins would mean I could add an lcd and/or some state / diagnostic lights. I could go for the mega but its only in surface mount and I've not progressed to that spec yet. Although I have to admit through hole although easy to manipulate in the fingers due to its size taks up so much board space. At some point I want to try getting a laser printer and making my own etched pcbs. The smd components are cheaper too so really its the way to go. What would I do about the 10Mohm pots I use? Can you even get 10M smd pots, the biggest I can find is 1M?

Logged

Inspire Excellence

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6639
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a design using a LCD display in which every single pin used to control it is also used for something else (the enable pin is driven from an output on a 4->16 line decoder chip, and the other 5 pins are used for other output devices and for input multiplexing).

What are you using the 10M pots for? If they are for setting values, then once you have an LCD display to show the values on, you can use rotary encoders instead, perhaps just a single rotary encoder with a built-in pushbutton to move between values.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That sounds interesting. I already reuse pin2 so why not others. I googled line decoder and I found one that only uses 8uA which seems very good. Turning 4 or 5 pins into 16 or more pins is very handy thanks. As for the 10M pots I use them in the resistive divides that are spanning the 4 18650 cells in series in my main project. To avoid balance issues I increased the resistance per stacked cell so that the static drain of the divides would exactly match providing all the cells were balanced at the same voltage. The 10M pots go at the bottom of each divide and then pipe out up to 1.092v to the analog pins which then is converted back to the actual real voltage. Then I just subtractively back track the cell stack point voltages to find to true values. Its a shame the 328p does not have an ADC which can handle more than 5v then I could remove all the divides and put the cells direct to the analog pins. I had a look at those rotary encoders too and they also seem interesting but not sure if Ill need them as part of my current project.

Off topic but random I just had my HAKKO 888 solder station arrive today from china and when I plugged it in it the main transformer unit started arcing inside and smoke came out top vent. Its a real shame really as it looked and felt top notch quality. Back in the box it goes, ebay dispute opened, sigh. Lol.
Logged

Inspire Excellence

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6639
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As for the 10M pots I use them in the resistive divides that are spanning the 4 18650 cells in series in my main project. To avoid balance issues I increased the resistance per stacked cell so that the static drain of the divides would exactly match providing all the cells were balanced at the same voltage. The 10M pots go at the bottom of each divide and then pipe out up to 1.092v to the analog pins which then is converted back to the actual real voltage. Then I just subtractively back track the cell stack point voltages to find to true values.

1. Is there any particular reason you are using pots instead of fixed resistors?

2. Bear in mind that when you feed the adc from a high source resistance, you get two sources of error, which are the finite input resistance of the ADC (100M according to the datasheet) and the fact that the sampling time is very short and the Arduino ADC code doesn't have any delay between setting the analog mux to the correct channel and starting the conversion. To reduce these errors, connect a capacitor of about 0.1uF between each analog input and ground (also useful for noise suppression), and switch the mux to an unused channel when you are not taking a reading.

Off topic but random I just had my HAKKO 888 solder station arrive today from china and when I plugged it in it the main transformer unit started arcing inside and smoke came out top vent. Its a real shame really as it looked and felt top notch quality. Back in the box it goes, ebay dispute opened, sigh. Lol.

It wasn't set for 110V and used on 220V, was it?
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1. Is there any particular reason you are using pots instead of fixed resistors?

I tried that before and the tolerance even on the 1% ones was so bad it was hard to get it precise. Much simpler to just trim the bottom pot to output the proportional ADC voltage.

Quote
2. Bear in mind that when you feed the adc from a high source resistance, you get two sources of error, which are the finite input resistance of the ADC (100M according to the datasheet) and the fact that the sampling time is very short and the Arduino ADC code doesn't have any delay between setting the analog mux to the correct channel and starting the conversion. To reduce these errors, connect a capacitor of about 0.1uF between each analog input and ground (also useful for noise suppression), and switch the mux to an unused channel when you are not taking a reading.

Ah thanks yes I already had a 0.1uF on each middle pot pin before the wire going to the analog pin. Should I move this to exactly on the analog pin? Also to reduce noise I only know to either do an average of the collected figures, do 3 analog reads preceding the one I use and/or run from batteries so there are only stable gently declining volts on vcc. In my current project all 6 analog pins are used. Could I set the mux to something internal like A06 which is AREF I think? Would this remove the need to do the averaging and pre-reads though? 

Quote
It wasn't set for 110V and used on 220V, was it?

The unit was sold as 220v, sticker on bottom said 220v, no switch. Wrong voltage was the first thing I thought too. If they end up refunding me and not requesting item back I'm going to open the sucker up and see what the real issue was.

Logged

Inspire Excellence

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6639
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1. Is there any particular reason you are using pots instead of fixed resistors?

I tried that before and the tolerance even on the 1% ones was so bad it was hard to get it precise. Much simpler to just trim the bottom pot to output the proportional ADC voltage.

Is it really the resistor tolerance that was bad, or it it the ADC errors that you get from using a high source resistance that was causing the trouble?

Quote
2. Bear in mind that when you feed the adc from a high source resistance, you get two sources of error, which are the finite input resistance of the ADC (100M according to the datasheet) and the fact that the sampling time is very short and the Arduino ADC code doesn't have any delay between setting the analog mux to the correct channel and starting the conversion. To reduce these errors, connect a capacitor of about 0.1uF between each analog input and ground (also useful for noise suppression), and switch the mux to an unused channel when you are not taking a reading.

Ah thanks yes I already had a 0.1uF on each middle pot pin before the wire going to the analog pin. Should I move this to exactly on the analog pin?

Not necessary unless you have a resistor between the pot and the pin. However, make sure you connect the bottom end of the pot and the ground side of the cap to analog ground, not digital ground.

Also to reduce noise I only know to either do an average of the collected figures, do 3 analog reads preceding the one I use and/or run from batteries so there are only stable gently declining volts on vcc. In my current project all 6 analog pins are used. Could I set the mux to something internal like A06 which is AREF I think? Would this remove the need to do the averaging and pre-reads though? 

The pre-reads are one way (but not a very good one) of getting round the issue of short sample time and no delay in the analogRead code. A better way is to set the analog mux to the channel you are about to read, then delay, then do the analog read. I found that a delay of about 10us per 100K of source resistance was just about sufficient. However, adding the 0.1uF cap on the input also avoids the need to pre-read.

If you need to do averaging to get stable readings, then either your inputs are picking up noise (which they shouldn't do if you have the 0.1uF caps connected), or the voltage you are reading isn't stable, or the analog Aref isn't stable, or you have noise on the ground line (always use separate analog and digital ground connections to the Arduino).
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6639
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

...and/or run from batteries so there are only stable gently declining volts on vcc. In my current project all 6 analog pins are used. Could I set the mux to something internal like A06 which is AREF I think?

You need to have a stable analog reference. If the 5V (or whatever) Vcc supply to the mcu isn't stable, then you should use a voltage reference chip and feed that into Aref instead of using Vcc as the analog reference. Setting the mux to an internal source such as A06 when it's not in use may help increase the input resistance (i.e. not place any additional load on whatever pin you last read).
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is it really the resistor tolerance that was bad, or it it the ADC errors that you get from using a high source resistance that was causing the trouble?

It really was. Plus having to fine tune with other value resistors took up additional space.

Quote
Not necessary unless you have a resistor between the pot and the pin. However, make sure you connect the bottom end of the pot and the ground side of the cap to analog ground, not digital ground.

I do not have a resistor between but have heard a 1ohm resistor can stop the gate ringing although I'm not sure what that means. When you say analog not digital ground what do you mean? All my grounds go to same place - the negative battery terminal unless I'm pulling a pin low and sinking current which I'm not in this project.

Quote
The pre-reads are one way (but not a very good one) of getting round the issue of short sample time and no delay in the analogRead code. A better way is to set the analog mux to the channel you are about to read, then delay, then do the analog read. I found that a delay of about 10us per 100K of source resistance was just about sufficient. However, adding the 0.1uF cap on the input also avoids the need to pre-read.

If you need to do averaging to get stable readings, then either your inputs are picking up noise (which they shouldn't do if you have the 0.1uF caps connected), or the voltage you are reading isn't stable, or the analog Aref isn't stable, or you have noise on the ground line (always use separate analog and digital ground connections to the Arduino).The pre-reads are one way (but not a very good one) of getting round the issue of short sample time and no delay in the analogRead code. A better way is to set the analog mux to the channel you are about to read, then delay, then do the analog read. I found that a delay of about 10us per 100K of source resistance was just about sufficient. However, adding the 0.1uF cap on the input also avoids the need to pre-read.

If you need to do averaging to get stable readings, then either your inputs are picking up noise (which they shouldn't do if you have the 0.1uF caps connected), or the voltage you are reading isn't stable, or the analog Aref isn't stable, or you have noise on the ground line (always use separate analog and digital ground connections to the Arduino).

The last time I took direct readings was when I had it in the uno board and it was in the initial revision stage running off of usb which I suspect may be the cause of the problems but I wont know till I get my bluetooth module and can run the project without anything plugged into it that might upset the values. I had my max232 chip arrive today too so if my soldering iron had not arrived damaged id be soldering the db9 connector so I could serial interface and read some values while on breadboard. Still though I think interfacing usb232 will upset values perhaps. Hopefully the bluetooth module itself does not cause any issues with power lol.

Logged

Inspire Excellence

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh and forgot to say I'm using the internal reference of 1.1v although in my case I found that it's 1.092v.
Logged

Inspire Excellence

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6639
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I do not have a resistor between but have heard a 1ohm resistor can stop the gate ringing although I'm not sure what that means.

That's only for when you are driving capacitive loads over long wires - and 1 ohm would only do any good of the load was a power mosfet and the source was a mosfet driver chip, or something like that.

When you say analog not digital ground what do you mean? All my grounds go to same place - the negative battery terminal unless I'm pulling a pin low and sinking current which I'm not in this project.

That's not ideal, but you may get away with it if the mcu isn't sinking any current. Best is to connect the ground sides of analog sensors through a wire connecting directly to the AGND pin of the mcu, or as near to AGND as possible. Then connect AGND to GND at the chip, and connect GND to the negative supply.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I see what you are getting at. Although I see no specific pin marked AGND I would assume you mean the ground pin closest to the analog pins / pin 22. In my design I have tried hard to keep the ground leads of components very close together so that there is as little ground potential difference as possible. On my analog in pins to the pot center pins I'm using wires that are all exactly the same length too. I've even considered using shielding on the wires but that may be overkill. But thanks yes Ill be sure to make sure sensors have a direct ground link to AGND for the same reason with respect to the ADC.

Perhaps along same lines on a smaller project just running one battery I would like to have a mosfet connected under the battery negative so that I can gate the solar panel on or off. Would it be correct to assume as long as I wire the mcu before the mosfet the only difference is the solar panel has to overcome the mosfets bandgap so its ground will be 0.7v lower? Then at positive end I could have a diode shaving off 0.4v ish. So the solar cells have to overcome 1.1v or so depending on the diodes forward voltage and current draw + the battery charge voltage requirement.
Logged

Inspire Excellence

Pages: 1 [2]   Go Up
Jump to: