ADC Conditional Loop

Go To Last Post
35 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey guys,

 

I am working on a project that monitors and tests a 24 V Lead acid battery,

 

Basically its a 24V setup,

 

the micro will at intervals connect a small load to a battery for a given period of time, after a small delay itll read the ADC and convert it to a voltage.

 

If the voltage is below a certain point I toggle an OP. Note  PINB1 is set to 1 during initialisation. also read_adc(3) is a another function that reads the selected adc.

 

the conditional loop is like this:

 

v=(read_adc(3)*.0293); //Read ADC 3, and convert to voltage. V is a float.

 

if (v > = 22 )

{

 PORTB |= (1<<PINB1); //Ensure PINB1 is on.

}

else

{

PORTB &= ~(1<<PINB1); //Turn B1 off.

}

 

Can you see any errors in the code it doesn't seem to be working.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what do you mean by "it not working"? 

What were you expecting to happen, what is happening?

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you get any errors? Do you have a debugger to see what v is after the ADC read? Maybe even print it out to a serial port.

 

And finally is B1 on at all times or off at all times?

 

Maybe the "doesn't seem to be working" has to do with the float number??? No idea about that.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I removed the conversion to voltage and replaced it with a fixed digital value that relates to the Voltage I need that should eliminate variable type issues, correct?

 

Ill upload the full code tonight, for review, Im at work at the moment and don't have all the info. available.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One thing I would note, is 22 volts is a pretty deep discharge level for LA battery if you intent to use PORT.B1 to turn on a charger, that deep of a level may shorten its life time.

I would use 23 volts as the trigger level.... 

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So these are a very specialist battery for Telco applications hence the 22.

My biggest concern is the loop does it look right

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
what do you mean by "it not working"?

I agree, what is "it doesn't seem to be working"?

 

ecw23able wrote:
if (v > = 22 )

This may just be a transcription error, but there should not be a space between the 'v' and the '='....

However, if present, it should have generated a compiler error.

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:
My biggest concern is the loop does it look right

Well, there is no loop at all in the code you posted. If that was all of your code it would be executed just once.

 


 

There is an if-statement, and that is not well formed. You have a space between the '>' and the  '='. That is not valid C. Those two needs to be together with no space between.

 

If, possible always post code that you have actually tried to build, e.g. in Atmel Studio. That way we save a lot of unnecessary traffic, and will avoid a lot of misunderstandings and confusion.

 


 

We also like, whenever possible that a minimal but complete program is posted. That way we can avoid asking follow up questions about the missing parts.

 

Finally, please use the "code button" when posting code. That way, indentation does not get mangled whien posting. The code button is the button marked "<>", above and right of the area where you compose your post. Using that your code above will be presented e.g. like this:

 

v=(read_adc(3)*.0293); //Read ADC 3, and convert to voltage. V is a float.

if (v > = 22 )   // <----- Ill formed C code here!!!
{
  PORTB |= (1<<PINB1); //Ensure PINB1 is on.
}
else
{
  PORTB &= ~(1<<PINB1); //Turn B1 off.
}

A lot nicer, don't you think?

 


If you place the above code in a loop, perhaps some kind of hysteresis control will be good? Otherwise, when you hit the limit the pin will most likely go on and off repeatedly and very rapidly since the inaccuracy of the ADC and the small variations in the actual voltage will make the measured value be varying on one or the other side of the limit. The simple solution is to e.g. set the pin when it is below e.g. 21.95 Volts and clear it when it is above 22.05 Volts. Whether the +/- 0.05 Volts is fitting to your application is up to you, but that's the easy way to set up hysteresis control.

 

 

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks yes you raise valid points I will always try to use the code function in future. I really should put my whole code up for review. In terms of hysteresis. I would usually completely agree. But since this voltage is measured across a small test test load the voltage change even when measured on a fluke 45 is very sluggish so for this application I'm not to worried plus this reading will only happen every 5 or so minutes.

Hysteresis is something I would definitely add to other projects though.

I'm try get the full code up

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And since this is interfacing to outside the AVR, please give us a schematic also - if possible.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:
I'm try get the full code up

Note the request is not necessarily for the "full code". 

JohanEkdahl wrote:
We also like, whenever possible that a minimal but complete program is posted. That way we can avoid asking follow up questions about the missing parts.

 

You still haven't told us what "doesn't work" means.  Schematic?  ADC setup?  AVR model?  Clock speed?  Supply voltage?  Reference source?  Voltage on all the pertinent pins?  What toolchain, version, and optimization settings?

 

With that information, what do you expect to happen under a particular condition?  What >>is<< happening?

 

JohanEkdahl wrote:
v=(read_adc(3)*.0293); //Read ADC 3, and convert to voltage. V is a float.

 

IMO/IME there is rarely a reason to do a gratuitous "float" in an AVR application.  You are starting with a small integer number (10-bit ADC result).  One normally ends up with a small integer number, such as timer counts.  In this case it appears to be a single on/off bit.

 

There are a number of small ratios that can carry out your task, and with a small enough numerator fit nicely into 16 bits.  Your result is quite coarse anyway, at ~3%.

 

0.0293 4.0293E-006 ==> 8 / 273 
0.0293 3.1250E-006 ==> 15 / 512 
0.0293 5.7257E-006 ==> 22 / 751 
0.0293 6.3694E-007 ==> 23 / 785 
0.0293 4.0293E-006 ==> 24 / 819 
0.0293 8.3236E-006 ==> 25 / 853 
0.0293 7.0707E-006 ==> 29 / 990 
0.0293 5.6711E-007 ==> 31 / 1058 
0.0293 7.2824E-006 ==> 33 / 1126 
0.0293 7.8926E-006 ==> 36 / 1229 
0.0293 4.6714E-006 ==> 37 / 1263 
0.0293 1.6191E-006 ==> 38 / 1297 
0.0293 1.2772E-006 ==> 39 / 1331 
0.0293 4.0293E-006 ==> 40 / 1365 
0.0293 6.6476E-006 ==> 41 / 1399 
0.0293 9.1417E-006 ==> 42 / 1433 
0.0293 8.4469E-006 ==> 43 / 1468 
0.0293 3.1250E-006 ==> 45 / 1536 
0.0293 1.7456E-006 ==> 47 / 1604 
0.0293 6.2201E-006 ==> 49 / 1672 
...

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Fri. Jul 14, 2017 - 08:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was wandering in the interests of optimization would it be easier to just put the direct digital value in instead of converting to voltage

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Put that aside for the moment.  Answer the other questions...

theusch wrote:
Note the request is not necessarily for the "full code". JohanEkdahl wrote: We also like, whenever possible that a minimal but complete program is posted. That way we can avoid asking follow up questions about the missing parts. You still haven't told us what "doesn't work" means. Schematic? ADC setup? AVR model? Clock speed? Supply voltage? Reference source? Voltage on all the pertinent pins? What toolchain, version, and optimization settings? With that information, what do you expect to happen under a particular condition? What >>is<< happening?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:
I was wandering in the interests of optimization would it be easier to just put the direct digital value in instead of converting to voltage

Premature optimization is the root of much evil.

 

ecw23able wrote:
would it be easier to just put the direct digital value in instead of converting to voltage

"Easy" in what respect?

 

Anyway, having the "raw" ADC limit literally in the test would make for hard to red code. This might slightly better (assuming a 10-bit ADC value):

 

#define ADC_LIMIT (1023 * 0.0293)
  .
  .
  .

  if (read_adc(3) > ADC_LIMIT)
     .
     .
     .

Here I am arguing for code readability, not hiding things behind "magic numbers" etc. (But, since the computation of ADC_LIMIT will be done at build time by the compiler you will also get rid of the run-time floating point calculation which is expensive (both in flash memory consumption and CPU cycles) on an 8-bit AVR.)

 

The 0..0293 is still a magic number, so even better would be to have the expression be explicit about the reference voltage of the ADC..

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Fri. Jul 14, 2017 - 09:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is the functional part of the code,

 

I am reading from ADC 3, DDRB is set in initialization to 0x17; so pins 0,1,2,4 as OP and Pin 3 input. these are the avr pins not physical pins.

/*
Prior to this while loop the adc is initialized and pins defined,
before jumping into the while loop chargeconn is set high, 

Charge conn drives a FET that connects charger to batt,
battload drives a FET that switches a small test load across the battery.

The idea is the battery will not be tested if voltage is less than 27V ideal charge voltage at 20degC is 27.6V
above this the battery will be tested at 5m intervals and after being loaded for 3s it must remain above 22V with
load connected below is a fail. if the voltage is below 27 indicating the battery is flat and being charged
and holding the voltage down or worse charge fail a test will not be completed instead we just monitor the battry
voltage.
*/

while(1)
{
    v=(adc_read(3)*0.0293); //Read ADC and convert to voltage
    if(v>=27)
    {
        PORTB &= ~(1<<chargeconn);//Disconnect batt from charger via FET for test
        PORTB |= (1<<chargeok) | (1<<battload); //Set charge ok indicator & Connect test load
        _delay_ms(3000); // wait 3 sec
        v=(adc_read(3)*0.0293); //Read ADC and convert to voltage
        if (v>=22)
        {
           PORTB &= ~(1<<battload); //discon test load
           PORTB |= (1<<battok) | (1<<chargeconn); // set batt ok indicator and reconnect charger
        }
        else
        {
            PORTB &= ~(1<<battload) & ~(1<<battok); //discon test load and ensure batt ok indicator is off
            PORTB |= (1<<chargeconn); // reconnect charger
        }
    }
    else
    {
        if(v>=22)
        {
            PORTB &= ~(1<<chargeok); // turn off charge ok indicator
            PORTB |= (1<<battok); // turn on batt ok indicator
        }
        else
        {
            PORTB &= ~(1<<chargeok) & ~(1<<battok); // turn off charge ok & batt ok indicator
        }
       
       
    }
   
    _delay_ms((50*60000)); //delay 5 minutes before testing system again.
}

 

Last Edited: Fri. Jul 14, 2017 - 09:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

NO! Do not show us something you type into the forum. Show us the actual code you have in your editor. The code you show above will not compile clean without errors. E.g.

PORTB $= ~(1<<chargeok); // turn off charge ok indicator

What is that '$' doing there?

 

You're wasting our time and wearing out your welcome.

 

Also, from earlier in the thread:

ecw23able wrote:
Can you see any errors in the code it doesn't seem to be working

"doesenät seem to be working" is a useless unworkable description of the problem.

What are you expecting?

What are you actually seeing?

 

Get it together. Give us something substantial to go on. The main effort is on you working to produce the most complete facts possible. We don't like guesswork.

 

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I use this approach would the "0.0293 need to be adjusted to reflect my 22 and 27v tests.

Also this approach will do the reading in the actual test wouldn't it.

would I have two definitions one for 22v and another for 27v,

i.e

#define upperlim (1023*0.0264) //27v limit
#define lowerlim (1023*0.0215) //22v limit

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And, in case this is about LEDs not lighting up when expected: Show schematic.

 

And show a minimal but complete program. E.g. we can not see anything about how you initialize the ADC, how you actually read it and any manipulation of port direction registers.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it shouldn't be '$' it should be '&', that's just an error here when I typed its not like that in my code

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:
its not like that in my code

Again: Do not type code directly into the forum. Your computer has a mark-copy-paste function. Use that.

 

How can we trust any of the code you've shown? What else have you typed in not corresponding to the code that is actually a problem?

 

It is completely up to you to produce a minimal but complete test program that builds and runs and displays the problem. Without that we can most likely not help you.

 

Your call..

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is no issues with LEDs or indicators. its program flow.

 

ADC is initialized via a separate c file from this forum, here is the code from the adc file.

#include avr/io.h

void adc_init(void)
{
 ADCSRA |= (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
 ADMUX |= (1<<REFS0);
}

unsigned int adc_read(char input)
{
 ADMUX &= 0xF8;
 input &= 0x07;
 ADMUX |= input;
 ADCSRA |= (1<<ADSC); // sTART CONVERSION
 while (ADCSRA & (1<<ADSC)); // WAIT FOR CONVERSION TO COMPLETE
 return adc;   
}

 

in front of the while(1) loop I have the following.

 

#define F_CPU 9600000
#define chargeconn PINB2
#define battok PINB1
#define chargeok PINB4
#define battload PINB0

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{

DDRB=0x17;
adc_init();
PORTB |= (1<<chargeconn);

/*
 while(1) loop in here
*/

}

 

 

For the purpose of testing this we have switched out the battery with a variable power supply to simulate.

 

the expected result is that if fed 21V from the supply simulating a battery it senses the voltage below 27 no test will be done it will skip the test and just monitor batt voltage but also clear the chargeok OP turning the LED off. If the batt voltage is also below 22v it will clear the batt ok OP turning off the batt ok LED, then in 5 minutes time it should run through this again with the same result,

 

the behaviour that is being seen is it is still testing when it shouldn't and its not clearing the batt ok pin.

Last Edited: Fri. Jul 14, 2017 - 10:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:
If the batt voltage is also below 22v it will clear the batt ok OP turning off the batt ok LED, then in 5 minutes time it should run through this again with the same result,

 

And this 5 minute wait should only be done in the case that a voltage less than 22 Volts is detected?

 

As the code stands now, the five  minute wait will be done "each time around" regardless of what voltages (less than 27, less than 22) where detected.

 

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you get the expected values out of your adc function? Verify that first.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
 while (ADCSRA & (1<<ADSC)); // WAIT FOR CONVERSION TO COMPLETE
 return adc;   

What is "adc"?

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Apologies I don't know how to quote the previous posts in here. and apologies for the problems establishing what I should have done in the first place. I will try to ensure each new post has more meaningful facts and examples.

 

JohanEkdahl Yes 5m delay should be each time round, the idea is that the tests with the load if above 27 & without the load if below 27 should be every 5 mins regardless of how the last tests went. This is incase the battery is dead flat as it charges there is a chance the indicators will illuminate again once the system is with in the desired limits which are above 22v and/or above 27V.

 

Kartman How can I see the ADC values. I will have access to the hardware and a lab tomorrow so can do some more tests.

 

I will test to ensure it behaves as expected with a voltage above 27V and advise results,

 

I will test to ensure it behaves as expected above 22V but below 27V and advise,

 

I will retest below 22V, to reconfirm the issues I am seeing and advise

 

I will also test with a transitions in voltage between the 3 ranges and advise results,

 

 

Just before going to test tomorrow are there any noticeable errors regarding ADC setup and my nested 'if else' blocks or the way I am testing the voltage,

Just to note the 0.0293 is the mV per digital increment of the ADC result/adc resolution .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The AVR has different registers for reading and writing input/output pins.   PORTB is for writing to the output pins, along with the DDRB bits that are used as outputs set to HIGH.  PINB is used for reading the logic on the input pins of port B.  There are also non-intuitive uses like turning on the pull-up resistors and toggling the output pin that can be found in the datasheet.  PINB1 can't be set to one during init.  You can set DDRB1 to HIGH and then output a HIGH to PORTB1.  Or, clear DDRB1 and read the logic value on PINB1.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sternst wrote:

 while (ADCSRA & (1<<ADSC)); // WAIT FOR CONVERSION TO COMPLETE
 return adc;   

What is "adc"?

 

I assume it's the combination of ADCH and ADCL, - supplied by avrlibc - and another "not the code I actually have" thing from the OP. I.e. I suspect he actually has "ADC", not "adc".

 

Simonetta wrote:

The AVR has different registers for reading and writing input/output pins.   PORTB is for writing to the output pins, along with the DDRB bits that are used as outputs set to HIGH.  PINB is used for reading the logic on the input pins of port B.  There are also non-intuitive uses like turning on the pull-up resistors and toggling the output pin that can be found in the datasheet.  PINB1 can't be set to one during init.  You can set DDRB1 to HIGH and then output a HIGH to PORTB1.  Or, clear DDRB1 and read the logic value on PINB1.

For all that I can see he's doing bit-manipulation in a "bog standard" way. E.g.

DDRB=0x17;  // Not pretty with "magic numbers" but will work

  ...

PORTB |= (1<<chargeconn);

  ...
  
PORTB &= ~(1<<chargeok);
PORTB |= (1<<battok);

What am I missing?

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey guys how do I quote the previous posts as you have done above.

 

And yes JohanEkdahl I have ADC.

 

Just a note on the bit manipulation, is there a better way to do it than how I have. If there is a better or tidier way I would like to try change my habits now.

 

in regards to

DDRB=0x17;

I've always tried to use HEX values and comment what it is, I find it looks tidier. In terms of ease of reading what below would be better.

 

DDRB |= (1<<chargeconn) | (1<<battok) | (1<<chargeok) | (1<<battload);


// or would this be better
 

DDRB=0b010111;

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:
Just a note on the bit manipulation, is there a better way to do it than how I have. If there is a better or tidier way I would like to try change my habits now.

It's your code so follow your habits using hex isn't a problem as long as you know what it is. And you mentioned that you commented it. So why not?
I did that too. Unless I have specific concern to that bit then I'll use bit manipulation style.
.
JohanEkdahl wrote:
What am I missing?

battload? or bit manipulation to PORTB not using magic number?
.
MG

I don't know why I'm still doing this hobby

Last Edited: Sat. Jul 15, 2017 - 12:29 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

how do I quote the previous posts

Copy the bit you want to quote and then use the " button above and insert your text in the box.  Then move the mouse just under the box and a Red line and arrow appear, press enter to continue outside the quote box.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:

Hey guys how do I quote the previous posts as you have done above.


Do you see a button labeled "Quote" below each post?

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:
Here is the functional part of the code,

I'm out.  ~15 more posts, and back-and-forth, and still the questions I asked earlier have not been addressed.

theusch wrote:

Put that aside for the moment.  Answer the other questions...

theusch wrote:
Note the request is not necessarily for the "full code". JohanEkdahl wrote: We also like, whenever possible that a minimal but complete program is posted. That way we can avoid asking follow up questions about the missing parts. You still haven't told us what "doesn't work" means. Schematic? ADC setup? AVR model? Clock speed? Supply voltage? Reference source? Voltage on all the pertinent pins? What toolchain, version, and optimization settings? With that information, what do you expect to happen under a particular condition? What >>is<< happening?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:
How can I see the ADC values.

 

An easy and cheap way is to use USB To RS232 TTL UART cable.

http://www.ebay.com/itm/USB-To-R...

 

Add uart code to your program and you can print variables on a PC terminal during runtime.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I done some more tests and reviewed all my coding. Also found I hadn't adjusted the c file holding the adc functions to work with the attiny13.

I have adjusted ADMUX to use the Vcc as ADC reference instead of the internal 1.1V. Also adjusted prescaler to div64.

It now shows the expected behaviors.

What I have learnt from this is:

A check my code properly first.
B take notes during testing of how it is behaving to how it should behave.
C make sure I have factual information and provide real code the the forum.

Thanks for the help and suggestions though even if I did annoy a few members. Sorry guys.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ecw23able wrote:
It now shows the expected behaviors.

What I have learnt from this is:

A check my code properly first.

B take notes during testing of how it is behaving to how it should behave.

C make sure I have factual information and provide real code the the forum.

Excellent!

 

ecw23able wrote:
Sorry guys.

Everything is well that ends well.

You now have a +1 in my book for the learning experience! (-:

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]