Show Posts
Pages: [1] 2
1  Using Arduino / Microcontrollers / Re: AVR MKII Bricking Every Chip!? on: February 05, 2013, 11:15:08 am
Ok I thought it had copied the ArduinoISP sketch as the lights flashed and it stopped blinking but looking back at the output it shows

Binary sketch size: 5,444 bytes (of a 30,720 byte maximum)
Binary sketch size: 5,444 bytes (of a 30,720 byte maximum)
avrdude: stk500_getsync(): not in sync: resp=0xf9

I think perhaps the AVR MKII has damaged the arduino board too or vice versa. Both did exactly the same thing and worked till I tried to program then nothing happens with an error but the chip gets nerfed.

Well that was my last chip so now I'm going to try using just the AVRMKII with a nerfed 328p on the breadboard.
2  Using Arduino / Microcontrollers / Re: AVR MKII Bricking Every Chip!? on: February 05, 2013, 10:26:25 am
Quote
Do you have the MKii drivers installed? They are buried in the IDE folders.
You also have to power the board when using it, the MKii only senses the voltage on the ICSP header, it does not provide power.

Hi yes drivers installed and yes both had power from separate usb cables. The unit was working fine the other week and I was handling chips to and from the breadboard to the uno board and then I tried to flash one and it did the error so I thought hmm maybe I bust it touching the pins too many times and caused problematic electrostatic discharges to the pins so I tried another chip and that broke too. At the time I thought it was the chips and maybe id static damaged two chips. The new chips arrive and think right il be extra careful and not touch any pins and ground myself only to find that I break another 2 chips aggghh lol. So yeah I figured if the chips are no longer reading in the uno either now they must need the high voltage programmer, a working mkii to bring them back or they are nerfed.
3  Using Arduino / Microcontrollers / Re: AVR MKII Bricking Every Chip!? on: February 05, 2013, 10:01:56 am
Ok connected and done. How should I check it out it still seems to be jammed with pin13 on?
4  Using Arduino / Microcontrollers / AVR MKII Bricking Every Chip!? on: February 05, 2013, 08:11:25 am
Hi All,

The other week I ordered 3 more 328p chips because the AVR MKII said that my existing 2 chips would not program and the arduino software gave the "not in sync" error too.  The chips arrived today and so far here is what happens:

1. Fresh 328p with uno bootloader and blink inserted into uno.
2. AVR MKII plugged into header and usb to uno connected
3. Uno pin 13 starts flashing then goes solid once AVRMKII usb is connected
4. Try to use arduino ide to use MKII to flash bootloader and get error below.
5. The 328p is now bricked and pin13 will never turn off.


"bad AVRISPmkII connection status: Unknown status 0x00 avrdude"


I have a feeling that the MKII has gone bad. So far in total I've bricked 4 chips. With 1 left I'm not sure what to do. My finger is hovering over the purchasing a new one but I thought id at least get everyone elses take on what it might be.

Thanks
5  Using Arduino / Programming Questions / Re: Forgetful 328P during sleep? on: January 27, 2013, 07:49:30 pm
Thanks Nick and Paul I appreciate the help. I just need to integrate the second sleep mode now and find out a simple brownout disable command to replace the register version I was using in 1st example code. Also still a little curious what in my original code was causing the issue. But the code from nick does indeed work and I'm going to try to adapt and move over functions from my broken code a function at a time. 
6  Using Arduino / Programming Questions / Re: Forgetful 328P during sleep? on: January 27, 2013, 06:54:09 pm
Code:
Serial.println (counter++);
  Serial.flush ();
 
  while (!(UCSR0A & (1 << UDRE0)))  // Wait for empty transmit buffer
     UCSR0A |= 1 << TXC0;  // mark transmission not complete
  while (!(UCSR0A & (1 << TXC0)));   // Wait for the transmission to complete
  Serial.end ();

Why is this part needed please? Is it in place of delays to allow serial to work right? Also do I have to do it after every single serial println so that each line waits to complete? Then just serial end at end but why end serial if we are only sleeping? Also in your code I'm not sure if I see brownout detection disabled or not but I need that too. Do you have a simpler version than the one that uses all those registers I had before?
7  Using Arduino / Programming Questions / Re: Forgetful 328P during sleep? on: January 27, 2013, 05:15:30 pm
Or if indeed anyone else has any ideas? Kind Thanks
8  Using Arduino / Programming Questions / Re: Forgetful 328P during sleep? on: January 27, 2013, 04:48:17 pm
Please forgive the messyness I've disabled lots just so I could isolate if it was adding the counter each wdt 8 second sleep. Thanks for taking a look.

Code:
//AceTK - Deepsleep powersaving single cell lion charger


#include <avr/sleep.h> // includes library for sleep
#include <avr/power.h> // includes library for sleep
#include <avr/wdt.h> // watchdog timer

unsigned short int SolVlts = 2;
volatile unsigned long AuxVolts = 0;
byte intCounter, adcsra, mcucr1, mcucr2;
volatile int f_wdt=1;
short unsigned int auxcharging = 0;
short unsigned int Relay1on = 9;
short unsigned int Relay1off = 10;
float AuxBatt = 0;
volatile short unsigned int val = 0;
volatile unsigned long PowerCheckCount = 0;


ISR(WDT_vect)
{
  if(f_wdt == 0)
  {
    f_wdt=1;
  }
  else
  {
    //Serial.println("WDT Overrun Error!!!");
  }
}

void enterSleep(void)
{
 
  //   *     SLEEP_MODE_IDLE         -the least power savings
  //   *     SLEEP_MODE_ADC
  //   *     SLEEP_MODE_PWR_SAVE
  //   *     SLEEP_MODE_STANDBY
  //   *     SLEEP_MODE_PWR_DOWN     -the most power savings
  sleep_enable();
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  // #ifdef WDTO_8S
  wdt_enable(WDTO_8S); // enable WDT 8 seconds
  wdt_reset();
  adcsra = ADCSRA;               //save the ADC Control and Status Register A
  ADCSRA = 0;                    //disable ADC
  cli();
  mcucr1 = MCUCR | _BV(BODS) | _BV(BODSE);  //turn off the brown-out detector
  mcucr2 = mcucr1 & ~_BV(BODSE);
  MCUCR = mcucr1;
  MCUCR = mcucr2;
  /* Now enter sleep mode. */
  sleep_mode();
 
  /* The program will continue from here after the WDT timeout*/
  sleep_disable(); /* First thing to do is disable sleep. */
  ADCSRA = adcsra; 
  /* Re-enable the peripherals. */
  power_all_enable();
}

void SleepCheck()
{
int val; 
val = digitalRead(SolVlts);   // read the 1.092v/5v charge ready input pin
if (val > 0 && auxcharging == 0)                  // if 1.092v  present boolean equals 1 / true
{
  sleep_enable();
    wdt_reset();
    wdt_disable();
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    EIMSK |= _BV(INT0);            //enable INT0
    adcsra = ADCSRA;               //save the ADC Control and Status Register A
    ADCSRA = 0;                    //disable ADC
    cli();
    mcucr1 = MCUCR | _BV(BODS) | _BV(BODSE);  //turn off the brown-out detector
    mcucr2 = mcucr1 & ~_BV(BODSE);
    MCUCR = mcucr1;
    MCUCR = mcucr2;
    sei();                         //ensure interrupts enabled so we can wake up again
    sleep_cpu();                   //go to sleep
    sleep_disable();               //wake up here
    ADCSRA = adcsra;               //restore ADCSRA
}
}

ISR(INT0_vect)
{
    intCounter++;
    EIMSK &= ~_BV(INT0);           //one interrupt to wake up only
}

void AuxBattMan()
{
 AuxVolts = analogRead(A2);
 AuxVolts = analogRead(A2);
 AuxVolts = analogRead(A2);
 AuxVolts = analogRead(A2); 
 AuxBatt = AuxVolts / 240.70; // Aux cell resistive divide ratio converter 1023 / 240.70 = 4.25
 if (AuxBatt < 4.1 && auxcharging == 0)
{
 digitalWrite(Relay1on, HIGH);
  //delay(4);
  digitalWrite(Relay1on, LOW);
  auxcharging=1;
}

if (AuxBatt > 4.1 && auxcharging == 1)
{
  digitalWrite(Relay1off, HIGH);
  //delay(4);
  digitalWrite(Relay1off, LOW);
  auxcharging=0;
 }
}
 
void MiniSleep()
{
  if(f_wdt == 1)
  {
    f_wdt = 0;
    if (auxcharging == 1)
    {
    PowerCheckCount = PowerCheckCount+1;
    }
    // Re-enter sleep mode. //
    PowerCheckCount = PowerCheckCount+1;
    enterSleep();
  }
  else
  {
    // Do nothing. //
  }
}

void PowerChecker()
{
  if (PowerCheckCount >= 7) //12 hours = 4800 1 hour = 400 1 min = 7
  {
  digitalWrite(Relay1off, HIGH);
  delay(1);
  digitalWrite(Relay1off, LOW);
  PowerCheckCount = 0;
  }
 Serial.println(PowerCheckCount);
}

 
void StatusFlash()
{
  if (auxcharging == 0)
  {
  digitalWrite(13, HIGH);
  delay(1);
  digitalWrite(13, LOW);
  delay(1);
  }
  if (auxcharging == 1)
  {
  digitalWrite(13, HIGH);
  delay(1);
  digitalWrite(13, LOW);
  delay(1);
  digitalWrite(13, HIGH);
  delay(1);
  digitalWrite(13, LOW);
  delay(1);
  }
}


void setup() {
 //CLKPR = (1<<CLKPCE); 
 //CLKPR = B00000011; // prescaler powersaver / rampup
// 0000 - divide crystal by 1
// 0001 - divide crystal by 2
// 0010 - divide crystal by 4
// 0011 - divide crystal by 8
// 0100 - divide crystal by 16
// 0101 - divide crystal by 32
// 0110 - divide crystal by 64
// 0111 - divide crystal by 128
// 1000 - divide crystal by 256 
 analogReference(INTERNAL); // sets reference to internal 1.092v
 pinMode(13, OUTPUT); // charge active light
 pinMode(SolVlts, INPUT);  // specifies pin 2 as available solar volts suitable for charge
 EICRA = 0x00;                 //configure INT0 to trigger on low level
 Serial.begin(9600);
 delay(2);
 if (PowerCheckCount > 0)
 {
 Serial.println(" Remembers Yay ");
 delay(3);
 }
 if (PowerCheckCount == 0)
 {
 Serial.println(" Starting Up Forgotten ");
 delay(3);
 }
 delay(4);
 /*** Setup the WDT ***/
 /* Clear the reset flag. */
 MCUSR &= ~(1<<WDRF);
 /* In order to change WDE or the prescaler, we need to
 * set WDCE (This will allow updates for 4 clock cycles).
 */
 WDTCSR |= (1<<WDCE) | (1<<WDE);
 /* set new watchdog timeout prescaler value */
 WDTCSR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds */
 /* Enable the WD interrupt (note no reset). */
 WDTCSR |= _BV(WDIE);
 //digitalWrite(Relay1on, HIGH);
 //delay(4);
 //digitalWrite(Relay1on, LOW);
 //delay(4);
 //digitalWrite(Relay1off, HIGH);
 //delay(4);
 //digitalWrite(Relay1off, LOW);
 auxcharging=0;
}




void loop()
{
 SleepCheck();  // divide#mosfet#pin2 12v solar ready triggers pin
 //SerialDiagnostics();
 //AuxBattMan();
 //Serial.print(AuxBatt);
 //delay(2);
 Serial.println("Working");
 delay(3);
 //Serial.print(AuxVolts);
 //delay(2);
 StatusFlash();
 delay(1000);
 MiniSleep(); // WDT Sleep for 8 seconds
 //PowerChecker();
}

9  Using Arduino / Programming Questions / Forgetful 328P during sleep? on: January 27, 2013, 04:27:09 pm
Hi all,

I'm working on my 18650 charger still and all is almost done but then I noticed that whenever I sleep in any mode the unit restarts like its been reset clearing any counters. Now I know I could use the EEPROM but that has only 100,000 write cycles and using it every 8 seconds would burn it out hella quick. Is there any other way anyone knows of to just hold a value during sleep? Perhaps keep the SRAM powered up but the rest sleeps or something. My intended application needs to count how many times it did an 8 second sleep so that after 12 hours it can start to disconnect the solar cells periodically from the battery to check the cells float voltage is above the battery charge voltage. I also figured worst case I could just not sleep and work in a reduced active mode at a lower clock with brownout off but really id like to save as much power as possible by using sleep mode power down in which I get nearly no draw.

Thanks
10  Using Arduino / Programming Questions / Re: Tricky question about multiple sleep modes in same sketch on: January 23, 2013, 03:01:27 pm
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.
11  Using Arduino / Programming Questions / Re: Tricky question about multiple sleep modes in same sketch on: January 23, 2013, 12:44:28 pm
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.
12  Using Arduino / Programming Questions / Re: Tricky question about multiple sleep modes in same sketch on: January 23, 2013, 12:42:51 pm
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.

13  Using Arduino / Programming Questions / Re: Tricky question about multiple sleep modes in same sketch on: January 23, 2013, 10:51:32 am
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.

14  Using Arduino / Programming Questions / Re: Tricky question about multiple sleep modes in same sketch on: January 23, 2013, 09:53:33 am
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.
15  Using Arduino / Programming Questions / Re: Tricky question about multiple sleep modes in same sketch on: January 22, 2013, 07:14:17 pm
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?

Pages: [1] 2