Go Down

Topic: Two Atmega328 chips on same board but power only one at a time (Read 3 times) previous topic - next topic

sibianul

Hello guys,

I hope my ideea is not very bad, but I really need to find a way to easy change some parameters in my camera gimbal controler as I want to use 2 different cameras, for each camera I will be using different params.

The problem is that I'm not manually uploading the new firmware (including params) but use a GUI software made by the developer of the gimbal, so I don't have access to the code.

Is it possible to add another atmega microcontroler over the original one, connecting all the pins between the two except VCC .. and add a switch to power only one at a time ?

Will it work ?

Thank you. Waiting your advices !


johnwasser

The AVR can get power through any input pin so you can't just disconnect Vcc. I think it would work if you grounded the Reset pin of one of the chips.  Another problem is the clock crystal.  I think if you leave the XTL2 pin of the second processor disconnected you can use the XTL1 pin of the original processor as an external clock on the second processor.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

CrossRoads

Yes, connect the IO in parallel, use Reset to select which will be active as John suggested.
Each should have its own power/decoupling caps, crystal & caps.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

sibianul

Thank you for fast reply, it seems it's a little more complicated than I though.

The board I have now it's of a friend of mine, and I'm waiting to receive a brand new one as this one is damaged, I can see on pins 18 and 20 two capacitors connected, only those need to be mounted on the extra microcontroler or there are other parts too ?

You recommended to connect the IO pins, only those pins or I can connect all except the pins with the capacitors, reset and XLT pins (if the solution proposed by john will not work. CrossRoads, please can you conform if this solution will work ?)

If I don''t connect all pins I think I can't update the firmware on the second AVR, right ? Also, if the reset pin is grounded at one of the chips , the other one will be successfully flash through the onboard USB connector ?



Maybe it will be easier to just buy two boards, but still I need to make some modifications as I can't unplug all the cables everytime I swap cameras. There are 6 pins for 2 brushless motors, GND, SCL, SDA and +5v for the MPU6050 sensor and another 3 PINS for a PWM signal connected to one receiver channel, used so I can manualy adjust the pitch angle of the gimbal.

Any ideea if I connect all the pins I use between the two separated boards, but only power one at a time (the gimbal controller will be powered by a 4S LiPo battery) as I drawn in the second attachment. This will be much easier for me, but will cost me almost another hundred.

CrossRoads

Keep it simple - buy a promini, wire the +5, Gnd, and all IO in parallel - but not Reset.
Then decide which chip you want running by who's reset is not pulled low.
Having active IO while Vcc is unpowered violates the chip specs: IO must not exceed Vcc by more than 0.5V.
However if reset is held low, all IO becomes inputs.

I wonder - when Reset is held low, that is also how ICSP programming is done. So if a chip is held in Reset, and the other chip is doing stuff via SPI, will the reset chip then try and do some programming action?
Might need some more experimenting on this.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

sibianul

I already have a promini as I got it for another project (curent and voltage logger using an SD card).

I'm curios if I will use an FTDI - USB cable if I can upload the firmware to promini as if I connected to the main gimbal controller. I think I will solder the pins now to promini to be able to connect the FTDI cable and give it a try  .. if it will work I think I'll be one step closer to achive what I want.

sibianul

I just flashed the firmware using Xloader, and connected the official GUI to the promini, it seems the firmware was succesfully flashed but I see I2C errors as I did not connect the MCU6050 sensor, any ideea if I can find out what pins are used for the sensor by decompiling the hex file ? I searched about decompiling but it seems it can't be done .. or it's not very easy.

Now I'm trying to look on the traces on PCB to identify the pin used for SCL and SDA ...

CrossRoads

Find them? A4, A5 on the promini.
Physical pins 27, 28.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

sibianul

#8
May 26, 2013, 09:40 am Last Edit: May 26, 2013, 09:58 am by sibianul Reason: 1
Good morning.

Found them last night, I didn't know that SCL and SDA are dedicated pins, I though the sensor can connect to either inputs. Last night I followed the traces and found the pins on the atmega328, when I searched online for the pinout for that chip I seen the SCL and SDA ware already noted on that image :)



Anyway, I connected the sensor but I don;t know why in the GUI I see alot of I2C errors, there is a counter and it's continously increasing. I just tried with the same wires on the main controller and the I2C error counter remains at 0, but when I connect to the promini the counter increases fast and the graph doesn't seem to follow the way I move the sensor, there are alot of spikes.

Now I don't know if the gui reports errors because the promini is not connected to the controller or because of something else.

I have uploaded a MPU6050 code I found online

// MPU-6050 Accelerometer + Gyro
// -----------------------------
//
// By arduino.cc user "Krodal".
// June 2012
// Open Source / Public Domain

In the serial monitor the values seem to oscilate the same as in the GUI of the gimbal, while the sensor was stationary on the table.

Also I don;t know yet what means error = 2 in the serial monitor'.

Code: [Select]
MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: -5374, 2, 305
temperature: 37.212 degrees Celsius
gyro x,y,z : 2050, -13039, -29695,

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: 747, 512, 12545
temperature: 24.459 degrees Celsius
gyro x,y,z : 520, 4557, 396,

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: -5374, 2, 305
temperature: 37.212 degrees Celsius
gyro x,y,z : 2050, -13039, -29695,

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: 747, 512, 12545
temperature: 24.459 degrees Celsius
gyro x,y,z : 520, 4557, 396,

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: -5374, 2, 305
temperature: 37.212 degrees Celsius
gyro x,y,z : 2050, -13039, -29695,

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: 747, 512, 12545
temperature: 24.459 degrees Celsius
gyro x,y,z : 520, 4557, 396,

sibianul

One step closer :)

I used different wires on the sensor and now is working great with the promini and the official gui, but I don;t understand why the same sensors worked perfectly with the official controller, and why not with the promini. I tried to connect it multiple times and everytime it worked with the original controller but not with the promini.

n my project I need to use very thin wires, and I tried with a cable from a cell phone headphones, it has all the wires I need to have the signal from the sensor and to send also the Video Out signal from a camera to a 5.8GHz transmitter. I have tested the very thin cable (and quite long, almost 1 meter) with the original controller in the same tie for video signal and for senzor signal and it worked perfectly.

Any ideea why it didn't work on the promini with that thin cable ?

I attached a photo I made, in the background you can see the gui and the graphs generated by the sensor values

johnwasser

My limited understanding of I2C includes the need for pull-up resistors on the data and clock lines.  The chip has internal pull-up resistors that can be enabled in software.  My guess would be that the 'official firmware' enables those and the MPU6050 code you found online does not.

http://wiki.nycresistor.com/wiki/Using_the_TWI/I2C_interface
Quote

Since the I2C bus normally operates at a relatively high speed, the two bus lines need external pull-up resistors. The internal pull-ups of AVR MCUs with their large resistances, as high as 50 kohms according to the documentation, would degrade the bandwidth of the bus. Nevertheless I still choose to use internal pull-ups, but I did it at a cost of using a slower bus. Since there shouldn't be any shame in reducing your parts count, the next step for me was to enable the internal pull-ups on the TWI clock (SCL) and data (SDA) pins.
Code: [Select]

#define SCL_PORT    PORTC   // pin assignments specific to the ATmega328p
#define SCL_BIT     PC5
#define SDA_PORT    PORTC
#define SDA_BIT     PC4

SCL_PORT |= _BV(SCL_BIT);   // enable pull up on TWI clock line
SDA_PORT |= _BV(SDA_BIT);   // enable pull up on TWI data line


Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

sibianul

My knowledge is limited in this electronics hobby, hope my question is not too stupid :D but are the resistors I mark with round red circle the pull-up resistors on the official controller ? As on the promini there are no resistors connected to A4 and A5 lines.

PS. I have the official firmware (hex file) on both bords, my promini and my friends original controller, the difference was that on the original controller the sensor worked with the long wires, and with my promini it didn't, it worked only with the short wires.

Are those resistors the cause why it did not work on my pro mini with the long wires ?

Anyway, I will shorten the wires I used initialy and see if it will work.

CrossRoads

Those do appear to be 4.7K resistors, which are the recommended value for SCL/SDA pullups.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

sibianul

I just measured the resistors and both are 4.69k, you are right :D. So if I solder two resistors between +5v and SCL and SDA pins it should work with the longer cables, right ?

I was looking now for the pins that I need to solder, 4 of them I can solder in some other points where I have more space but still there are another 12 pins that need to be soldered right on the original atmega chip .. that will be "fun" :)

sibianul

If I connect the I/O pins in paralel and both boards (original + promini) have pull-up resistors installed, can it be a problem ?

Or if I connect the original board which has the pull-up resistors with a new MPU6050 sensor which also has the pull up resistors installed could cause any problem ?

I want to get the new sensors as it also has holes and I can mount it properly, my old sensor doesn't have any holes and the only way to mount is using thick double sided tape


OLD SENSOR


NEW SENSOR



Thank you.


Go Up