Atmega (1284p) Multiwii -=Almost Fully Functional=-
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Atmega (1284p) Multiwii -=Almost Fully Functional=-
Has anyone written an FAQ or guide for configuring this software for non-standard "Arduino" controllers?
I would like to build one with the Atmega 1284p and getting obvious compiling issues. For instance LED and buzzerpin of which I assume this is due to the pinout differences? I scrolled through the config and some of the other scripts and nothing obvious is jumping out at me. Where can these changes can be made?
I would like to build one with the Atmega 1284p and getting obvious compiling issues. For instance LED and buzzerpin of which I assume this is due to the pinout differences? I scrolled through the config and some of the other scripts and nothing obvious is jumping out at me. Where can these changes can be made?
Last edited by wastevenson on Thu Mar 31, 2016 4:37 am, edited 1 time in total.
Re: Customizing for Non-Standard Atmegas (1284p)
those are defined for each mcu separately and differently.
You must create a new section for your mcu. Best to follow what gets done for the mega mcu in def.h
You must create a new section for your mcu. Best to follow what gets done for the mega mcu in def.h
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Customizing for Non-Standard Atmegas (1284p)
Thanks. I will start there.
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Customizing for Non-Standard Atmegas (1284p)
Well, I've done some copy/paste and editing with the code, guessing where I need to. Getting a compiling error that hopefully someone can help me with please:
Here is some code additions that I made:
In def.h
Here definitely needs some more work by me though not sure it is causing compiling error at this point?
In output.cpp
\sketch\Output.cpp: In function 'void initOutput()':
Output.cpp:538: error: 'PWM_PIN' was not declared in this scope
pinMode(PWM_PIN[i],OUTPUT);
^
exit status 1
'PWM_PIN' was not declared in this scope
Here is some code additions that I made:
In def.h
Code: Select all
#if defined(__AVR_ATmega1284P__)
#define Atmega1284P
#endif
Here definitely needs some more work by me though not sure it is causing compiling error at this point?
Code: Select all
/************************** Atmega1284P ***********************************/
#if defined(Atmega1284P)
#define LEDPIN_PINMODE pinMode (18, OUTPUT);pinMode (19, OUTPUT);
#define LEDPIN_TOGGLE PINB |= (1<<7); PINC |= (1<<7);
#define LEDPIN_ON PORTC |= (1<<7); PORTC |= (1<<7);
#define LEDPIN_OFF PORTC &= ~(1<<7);PORTC &= ~(1<<7);
#define BUZZERPIN_PINMODE pinMode (21, OUTPUT);
#if defined PILOTLAMP
#define PL_PIN_ON PORTC |= 1<<5;
#define PL_PIN_OFF PORTC &= ~(1<<5);
#else
#define BUZZERPIN_ON PORTC |= 1<<5;
#define BUZZERPIN_OFF PORTC &= ~(1<<5);
#endif
#if !defined(DISABLE_POWER_PIN)
#define POWERPIN_PINMODE pinMode (37, OUTPUT);
#define POWERPIN_ON PORTC |= 1<<0;
#define POWERPIN_OFF PORTC &= ~(1<<0);
#else
#define POWERPIN_PINMODE ;
#define POWERPIN_ON ;
#define POWERPIN_OFF ;
#endif
#define I2C_PULLUPS_ENABLE PORTC |= 1<<0; PORTC |= 1<<1; // PIN 20&21 (SDA&SCL)
#define I2C_PULLUPS_DISABLE PORTC &= ~(1<<0); PORTC &= ~(1<<1);
#define PINMODE_LCD pinMode(0, OUTPUT);
#define LCDPIN_OFF PORTE &= ~1; //switch OFF digital PIN 0
#define LCDPIN_ON PORTE |= 1;
#define STABLEPIN_PINMODE pinMode (20, OUTPUT);
#define STABLEPIN_ON PORTC |= 1<<6;
#define STABLEPIN_OFF PORTC &= ~(1<<6);
#if defined(PPM_ON_THROTTLE)
//configure THROTTLE PIN (A8 pin) as input witch pullup and enabled PCINT interrupt
#define PPM_PIN_INTERRUPT DDRK &= ~(1<<0); PORTA |= (1<<0); PCICR |= (1<<2); PCMSK2 |= (1<<0);
#else
#define PPM_PIN_INTERRUPT attachInterrupt(4, rxInt, RISING); //PIN 19, also used for Spektrum satellite option
#endif
#if !defined(RX_SERIAL_PORT)
#define RX_SERIAL_PORT 1
#endif
//RX PIN assignment inside the port //for PORTK
#define THROTTLEPIN 0 //PIN 62 = PIN A8
#define ROLLPIN 1 //PIN 63 = PIN A9
#define PITCHPIN 2 //PIN 64 = PIN A10
#define YAWPIN 3 //PIN 65 = PIN A11
#define AUX1PIN 4 //PIN 66 = PIN A12
#define AUX2PIN 5 //PIN 67 = PIN A13
#define AUX3PIN 6 //PIN 68 = PIN A14
#define AUX4PIN 7 //PIN 69 = PIN A15
#define V_BATPIN A0 // Analog PIN 0
#define PSENSORPIN A2 // Analog PIN 2
#define PCINT_PIN_COUNT 8
#define PCINT_RX_BITS (1<<2),(1<<4),(1<<5),(1<<6),(1<<7),(1<<0),(1<<1),(1<<3)
#define PCINT_RX_PORT PORTD
#define PCINT_RX_MASK PCMSK2
#define PCIR_PORT_BIT (1<<2)
#define RX_PC_INTERRUPT PCINT2_vect
#define RX_PCINT_PIN_PORT PINK
#define SERVO_1_PINMODE pinMode(34,OUTPUT);pinMode(44,OUTPUT); // TILT_PITCH - WING left
#define SERVO_1_PIN_HIGH PORTC |= 1<<3;PORTL |= 1<<5;
#define SERVO_1_PIN_LOW PORTC &= ~(1<<3);PORTL &= ~(1<<5);
#define SERVO_2_PINMODE pinMode(35,OUTPUT);pinMode(45,OUTPUT); // TILT_ROLL - WING right
#define SERVO_2_PIN_HIGH PORTC |= 1<<2;PORTL |= 1<<4;
#define SERVO_2_PIN_LOW PORTC &= ~(1<<2);PORTL &= ~(1<<4);
#define SERVO_3_PINMODE pinMode(33,OUTPUT); pinMode(46,OUTPUT); // CAM TRIG - alt TILT_PITCH
#define SERVO_3_PIN_HIGH PORTC |= 1<<4;PORTL |= 1<<3;
#define SERVO_3_PIN_LOW PORTC &= ~(1<<4);PORTL &= ~(1<<3);
#define SERVO_4_PINMODE pinMode (37, OUTPUT);pinMode(7,OUTPUT); // new - alt TILT_ROLL
#define SERVO_4_PIN_HIGH PORTC |= 1<<0; PORTH |= 1<<4;
#define SERVO_4_PIN_LOW PORTC &= ~(1<<0);PORTH &= ~(1<<4);
#define SERVO_5_PINMODE pinMode(6,OUTPUT); // BI LEFT
#define SERVO_5_PIN_HIGH PORTH |= 1<<3;
#define SERVO_5_PIN_LOW PORTH &= ~(1<<3);
#define SERVO_6_PINMODE pinMode(2,OUTPUT); // TRI REAR - BI RIGHT
#define SERVO_6_PIN_HIGH PORTE |= 1<<4;
#define SERVO_6_PIN_LOW PORTE &= ~(1<<4);
#define SERVO_7_PINMODE pinMode(5,OUTPUT); // new
#define SERVO_7_PIN_HIGH PORTE |= 1<<3;
#define SERVO_7_PIN_LOW PORTE &= ~(1<<3);
#define SERVO_8_PINMODE pinMode(3,OUTPUT); // new
#define SERVO_8_PIN_HIGH PORTE |= 1<<5;
#define SERVO_8_PIN_LOW PORTE &= ~(1<<5);
#endif
In output.cpp
Code: Select all
#if defined(Atmega1284p)
uint8_t PWM_PIN[4] = {6,7,12,13}; //for a quad+: rear,right,left,front
#endif
Code: Select all
/**************** Specific PWM Timers & Registers for the Atmega1284p *******************/
#if defined(Atmega1284p)// [1000:2000] => [8000:16000] for timer 1 & 3 for Atmega1284p
#if (NUMBER_MOTOR > 0)
#ifndef EXT_MOTOR_RANGE
OCR3A = motor[0]<<3; // pin 6
#else
OCR3A = ((motor[0]<<4) - 16000);
#endif
#endif
#if (NUMBER_MOTOR > 1)
#ifndef EXT_MOTOR_RANGE
OCR3B = motor[1]<<3; // pin 7
#else
OCR3B = ((motor[1]<<4) - 16000);
#endif
#endif
#if (NUMBER_MOTOR > 2)
#ifndef EXT_MOTOR_RANGE
OCR1A = motor[2]<<3; // pin 13
#else
OCR1A = ((motor[2]<<4) - 16000);
#endif
#endif
#if (NUMBER_MOTOR > 3)
#ifndef EXT_MOTOR_RANGE
OCR1B = motor[3]<<3; // pin 12
#else
OCR1B = ((motor[3]<<4) - 16000);
#endif
#endif
#endif
Code: Select all
/**************** Specific PWM Timers & Registers for the 1284P ******************/
#if defined(Atmega1284p)
#if (NUMBER_MOTOR > 0)
// init 16bit timer 3
TCCR3A |= (1<<WGM31); // phase correct mode
TCCR3A &= ~(1<<WGM30);
TCCR3B |= (1<<WGM33);
TCCR3B &= ~(1<<CS31); // no prescaler
ICR3 |= 0x3FFF; // TOP to 16383;
TCCR3A |= _BV(COM3C1); // connect pin 3 to timer 3 channel C
#endif
#if (NUMBER_MOTOR > 1)
TCCR3A |= _BV(COM3A1); // connect pin 5 to timer 3 channel A
#endif
#if (NUMBER_MOTOR > 2)
// init 16bit timer 4
TCCR4A |= (1<<WGM41); // phase correct mode
TCCR4A &= ~(1<<WGM40);
TCCR4B |= (1<<WGM43);
TCCR4B &= ~(1<<CS41); // no prescaler
ICR4 |= 0x3FFF; // TOP to 16383;
TCCR4A |= _BV(COM4A1); // connect pin 6 to timer 4 channel A
#endif
#if (NUMBER_MOTOR > 3)
TCCR3A |= _BV(COM3B1); // connect pin 2 to timer 3 channel B
#endif
#endif
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Customizing for Non-Standard Atmegas (1284p)
Well, getting a lot more define errors now that I'm going through it. Going to be some work. Hope I get it figured out. Heh.
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Customizing for Non-Standard Atmegas (1284p)
Just an update for anyone that was wondering.
I have finally run out of propellers to use on my quadcopter so I have gotten back to pissing around with this project to keep me occupied.
I have gotten the program to compile and run. I have all my sensors communicating with Multiwii and everything is being passed along the serial port to either my USB or GUI. Everything saving in EEPROM as it should, and GPS is working great as well.
I am now to the point where I am getting the receiver working on the analog port. Just starting to wrap my head around it and hope to have some progress soon.
I have finally run out of propellers to use on my quadcopter so I have gotten back to pissing around with this project to keep me occupied.
I have gotten the program to compile and run. I have all my sensors communicating with Multiwii and everything is being passed along the serial port to either my USB or GUI. Everything saving in EEPROM as it should, and GPS is working great as well.
I am now to the point where I am getting the receiver working on the analog port. Just starting to wrap my head around it and hope to have some progress soon.
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Customizing for Non-Standard Atmegas (1284p)
Looks like I have a 1284p Quadcopter Flight Controller working for the most part. GPS, Bluetooth, and 10dof sensor working great. Motors are all spinning. Have my Throttle, Yaw, Pitch, Aux1, Aux2 working.
But for some reason, my roll channel is coming up as AUX3, and AUX 4 at the same time in the GUI. Though I have removed them from the code from what I can tell. Can anyone give me some hints as to what may be the cause please?
In RX.cpp
In def.h
But for some reason, my roll channel is coming up as AUX3, and AUX 4 at the same time in the GUI. Though I have removed them from the code from what I can tell. Can anyone give me some hints as to what may be the cause please?
In RX.cpp
Code: Select all
"static uint8_t rcChannel[RC_CHANS] = {ROLLPIN, PITCHPIN, YAWPIN, THROTTLEPIN, AUX1PIN, AUX2PIN};"
In def.h
Code: Select all
//RX PIN assignment inside the port //for PORTC
#define THROTTLEPIN 2 //D18 = PC2
#define ROLLPIN 3 // D19 = PC3
#define PITCHPIN 4 // D20 = PC4
#define YAWPIN 5 // D21 = PC5
#define AUX1PIN 6 // D22 = PC6
#define AUX2PIN 7 // D23 = PC7
#define V_BATPIN A0 // Analog PIN 0
#define PSENSORPIN A2 // Analog PIN 2
#define PCINT_PIN_COUNT 6
#define PCINT_RX_BITS (1<<2),(1<<3),(1<<4),(1<<5),(1<<6),(1<<7)
#define PCINT_RX_PORT PORTC
#define PCINT_RX_MASK PCMSK2
#define PCIR_PORT_BIT (1<<2)
#define RX_PC_INTERRUPT PCINT2_vect
#define RX_PCINT_PIN_PORT PINC
Re: Customizing for Non-Standard Atmegas (1284p)
Just a wild guess. Your physical wiring? From the RX to the TX? I know, probably not. What GUI? Does the roll channel show up and not move, just the aux moves? Or is just the aux 3 and 4 on the GUI?
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Atmega (1284p) Multiwii -=Almost Fully Functional=-
There are no other pins on PortC.......
Best I can tell, and I can double-check tomorrow, is that D19/PC3 is for whatever reason reading as Aux3 and Aux4 (at the same time), and nothing reading on the Roll designation. Appears to be a software issue.
Best I can tell, and I can double-check tomorrow, is that D19/PC3 is for whatever reason reading as Aux3 and Aux4 (at the same time), and nothing reading on the Roll designation. Appears to be a software issue.
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Atmega (1284p) Multiwii -=Almost Fully Functional=-
Using Multiwiiconf for my Gui. I haven't tried it on the others at this point, but they work fine with my other flight controllers I have thrown together.
And that is correct. Aux3 and Aux4 move together in tandem. Nothing on the roll.
And that is correct. Aux3 and Aux4 move together in tandem. Nothing on the roll.
Re: Atmega (1284p) Multiwii -=Almost Fully Functional=-
wastevenson wrote:Using Multiwiiconf for my Gui. I haven't tried it on the others at this point, but they work fine with my other flight controllers I have thrown together.
And that is correct. Aux3 and Aux4 move together in tandem. Nothing on the roll.
Sounds to me like something in the GUI software.
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Atmega (1284p) Multiwii -=Almost Fully Functional=-
No, it is definitely the flight control software.
But I've pretty much got it figured out. I have everything where it needs to be now except for my AUX channels. Was up at 4am before work to get it sorted.
It seems it had to do with my limiting the PCINT_RX_BITS. And the fact that those bit settings seem to look for those defined numbers.
It was a lot of trial and error this morning to figure out what is doing what. Sometimes it seems random, but I'll confirm it tonight when I try to sort out my AUX channels.
At this point I think that my i2c on D16/D17 (PC0, and PC1), is interfering with the PCINT_RX_BITS. So I have to go through the code and see if I can figure it out by myself.
But I've pretty much got it figured out. I have everything where it needs to be now except for my AUX channels. Was up at 4am before work to get it sorted.
It seems it had to do with my limiting the PCINT_RX_BITS. And the fact that those bit settings seem to look for those defined numbers.
It was a lot of trial and error this morning to figure out what is doing what. Sometimes it seems random, but I'll confirm it tonight when I try to sort out my AUX channels.
At this point I think that my i2c on D16/D17 (PC0, and PC1), is interfering with the PCINT_RX_BITS. So I have to go through the code and see if I can figure it out by myself.
Re: Atmega (1284p) Multiwii -=Almost Fully Functional=-
I wish you the best of luck. I'm out of my league in this conversation.
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Atmega (1284p) Multiwii -=Almost Fully Functional=-
Thanks. It's been fun so far. And at this point, it's going to be a lot easier for me to get it working on other MCUs if I ever go that route. Heh.
-
- Posts: 33
- Joined: Thu Jan 07, 2016 5:33 am
Re: Atmega (1284p) Multiwii -=Almost Fully Functional=-
Well, I still haven't completely understood the code. But I have it working. Sort of. My i2c ports are definately showing the GUI that AUX3, and AUX4 are connected to something. At this point it doesn't appear to interfere with the i2c signal so I don't believe it to be an noticeable issue. But I don't like it. I still need to find a way to have those bits ignored, or switch those two (AUX3, and AUX4) over to different pins on a different port. Which means I just have to figure out how to manually set the pins.
In rx.cpp
In def.h
In rx.cpp
Code: Select all
static uint8_t rcChannel[RC_CHANS] = {THROTTLEPIN, ROLLPIN, PITCHPIN, YAWPIN, AUX1PIN, AUX2PIN, AUX3PIN, AUX4PIN};
In def.h
Code: Select all
//RX PIN assignment inside Port C
#define THROTTLEPIN 2
#define ROLLPIN 3
#define PITCHPIN 4
#define YAWPIN 5
#define AUX1PIN 6
#define AUX2PIN 7
#define AUX3PIN 1 //i2c
#define AUX4PIN 0 //i2c
#define V_BATPIN A0 // Analog PIN 0
#define PSENSORPIN A2 // Analog PIN 2
#define PCINT_PIN_COUNT 8
// ROLL YAW THR AUX1 AUX2 i2c i2c PTCH
#define PCINT_RX_BITS (1<<5),(1<<2),(1<<4),(1<<6),(1<<7),(1<<1),(1<<0),(1<<3)
#define PCINT_RX_PORT PORTC
#define PCINT_RX_MASK PCMSK2
#define PCIR_PORT_BIT (1<<2)
#define RX_PC_INTERRUPT PCINT2_vect
#define RX_PCINT_PIN_PORT PINC