EcoModder.com

EcoModder.com (https://ecomodder.com/forum/)
-   OpenGauge / MPGuino FE computer (https://ecomodder.com/forum/opengauge-mpguino-fe-computer.html)
-   -   I need your help (MPGuino code change for Arduino mega 2560?) (https://ecomodder.com/forum/showthread.php/i-need-your-help-mpguino-code-change-arduino-26674.html)

josemapiro 08-14-2013 04:51 AM

I need your help (MPGuino code change for Arduino mega 2560?)
 
In MPGuino V0.86 entries for the injector and VSS Pins are made ​​with these,
injector open D2 (int0)
injector closed D3 (int1)
speed C0 (pcint8)

I needed to change the code of these Pins, so that work in Arduino mega 2560, which has D2 as (int4) and D3 as (INT5) and C0 there is no pcint8.

What parts should I change the code and how should I do.

Thank you
José Rodrigues

Quezacotl 08-15-2013 08:53 AM

find:
#define RISING 3
#define FALLING 2
These into whatever interruptpins you are using.
find:
#define vssBit ( 1 << 0 )
0 into whatever analog pin you are using.

josemapiro 08-16-2013 07:19 AM

Quote:

Originally Posted by Quezacotl (Post 385332)
find:
#define RISING 3
#define FALLING 2
These into whatever interruptpins you are using.
find:
#define vssBit ( 1 << 0 )
0 into whatever analog pin you are using.

I've done some changes but the result is still not expected.
Later I will post here the changes I made and a video with the result.

Thank you
José Rodrigues

josemapiro 08-16-2013 02:55 PM

Not changed the (# define RISING 3) (# define FALLING 2), because I use the pin 2 and 3, which amends and the INT0 and INT1, which belongs to pins 20 and 21.

Part code of injectors.
Code:

        injectorSettleTime = injhold;
        //int0Func = processInjOpen;                                                  // original code
        int4Func = processInjOpen;                                                  // code changed
        //int1Func = processInjClosed;                                                // original code
        int5Func = processInjClosed;                                                // code changed

        //set up the external interrupts
        //EICRB = (EICRB & ~((1 << ISC00) | (1 << ISC01)))                            // original code
        EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41)))                            // code changed
                        //| ((parms[injEdgeIdx] == 1 ? RISING : FALLING) << ISC00);  // original code
                        | ((parms[injEdgeIdx] == 1 ? RISING : FALLING) << ISC40);  // code changed
        //EIMSK |= (1 << INT0);                                                      // original code
        EIMSK |= (1 << INT4);                                                      // code changed
        //EICRB = (EICRB & ~((1 << ISC10) | (1 << ISC11)))                            // original code
        EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51)))                            // code changed
                        //| ((parms[injEdgeIdx] == 1 ? FALLING : RISING) << ISC10);  // original code
                        | ((parms[injEdgeIdx] == 1 ? FALLING : RISING) << ISC50);  // code changed
        //EIMSK |= (1 << INT1);                                                      // original code
        EIMSK |= (1 << INT5);

The value of "# define vssBit (1 << 0)" is not the bit value of the pin?
Or put the value of the pin?
The pin that I use is the "A8" which uses pin "62" on the arduino mega.

If you have something wrong, please correct me.

As shown in the video, the program starts fine, but then when I trigger any of the buttons does a reset type, do not know what causes it.

https://www.youtube.com/watch?v=_oFHlihGZog

If I can help I thank
José Rodrigues

t vago 08-16-2013 09:34 PM

Quote:

Originally Posted by josemapiro (Post 385656)
The value of "# define vssBit (1 << 0)" is not the bit value of the pin?
Or put the value of the pin?

Those lines should really read:

Code:

#define vssBit (1 << PINC0)
#define lbuttonBit (1 << PINC3)
#define mbuttonBit (1 << PINC4)
#define rbuttonBit (1 << PINC5)

Quote:

Originally Posted by josemapiro (Post 385656)
As shown in the video, the program starts fine, but then when I trigger any of the buttons does a reset type, do not know what causes it.

It sounds like you might have connected your buttons by mistake to the reset pin. Somebody who is more familiar with the Arduino Mega may be able to verify that.

josemapiro 08-17-2013 05:41 AM

Quote:

Originally Posted by t vago (Post 385706)
Those lines should really read:

Code:

#define vssBit (1 << PINC0)
#define lbuttonBit (1 << PINC3)
#define mbuttonBit (1 << PINC4)
#define rbuttonBit (1 << PINC5)

It sounds like you might have connected your buttons by mistake to the reset pin. Somebody who is more familiar with the Arduino Mega may be able to verify that.

If you set the pins as indicated, but for the mega pins gives error.

mpguino_alt3_ino:251: error: 'PINK11' was not declared in this scope
mpguino_alt3_ino:251: error: 'PINK12' was not declared in this scope
mpguino_alt3_ino:251: error: 'PINK13' was not declared in this scope
mpguino_alt3_ino.ino: In function 'void __vector_10()':
mpguino_alt3_ino:398: error: 'PINK8' was not declared in this scope
mpguino_alt3_ino.ino: In function 'void mainloop()':
mpguino_alt3_ino:577: error: 'PINK11' was not declared in this scope
mpguino_alt3_ino:577: error: 'PINK13' was not declared in this scope
mpguino_alt3_ino:584: error: 'PINK12' was not declared in this scope
mpguino_alt3_ino:608: error: 'PINK11' was not declared in this scope
mpguino_alt3_ino:608: error: 'PINK12' was not declared in this scope
mpguino_alt3_ino:608: error: 'PINK13' was not declared in this scope
mpguino_alt3_ino:613: error: 'PINK11' was not declared in this scope
mpguino_alt3_ino:613: error: 'PINK12' was not declared in this scope
mpguino_alt3_ino:613: error: 'PINK13' was not declared in this scope
mpguino_alt3_ino.ino: In function 'void editParm(byte)':
mpguino_alt3_ino:1368: error: 'PINK11' was not declared in this scope
mpguino_alt3_ino:1368: error: 'PINK13' was not declared in this scope
mpguino_alt3_ino:1379: error: 'PINK12' was not declared in this scope
mpguino_alt3_ino:1407: error: 'PINK11' was not declared in this scope
mpguino_alt3_ino:1407: error: 'PINK12' was not declared in this scope
mpguino_alt3_ino:1407: error: 'PINK13' was not declared in this scope
mpguino_alt3_ino:1412: error: 'PINK11' was not declared in this scope
mpguino_alt3_ino:1412: error: 'PINK12' was not declared in this scope
mpguino_alt3_ino:1412: error: 'PINK13' was not declared in this scope

Here is a picture to help with the mega pins.
http://imageshack.us/a/img826/1596/l293.th.jpg

Thank you
José Rodrigues

Quezacotl 08-17-2013 06:09 AM

PinK? :)

josemapiro 08-17-2013 08:46 AM

Quote:

Originally Posted by Quezacotl (Post 385765)
PinK? :)

Yes the Analogue pins in arduino mega, are PF0-7 and PK0-7, the pin PC in Atmega 328 were Analogue, in arduino mega are digital, you can confirm the image.

http://imageshack.us/a/img826/1596/l293.th.jpg

josemapiro 08-19-2013 07:04 AM

The error above was my mistake, define, # define vssBit (1 << PINK8); # define lbuttonBit (1 << PINK11); # define mbuttonBit (1 << PINK12); # define rbuttonBit (1 << pink13), but these pins is not are the correct, the correct are# define vssBit (1 << PINK0); # define lbuttonBit (1 << pink3); # define mbuttonBit (1 << PINK4); # define rbuttonBit (1 << PINK5), the K Pins are 0 to 7.
I've been a bit sleep.
But even with these changes, the problem remains. Will be a registration on the changes I made, what needs to be changed too?
Any registration that points to a different Pin.

Thank you
José Rodrigues

t vago 08-19-2013 12:11 PM

Can you give us a list of the interrupt vectors you're using? Such as -

Code:

ISR( TIMER2_OVF_vect ) { // system timer interrupt handler
ISR( INT0_vect ) { // fuel injector open event handler
ISR( INT1_vect ) { // fuel injector close event handler
ISR( PCINT1_vect ) { // button and VSS pin change vector
ISR( ADC_vect ) { // (freewheeling) A/D conversion completed vector
ISR( USART_UDRE_vect ) { // serial UART transmit data ready vector

I am asking because I had the hardest time trying to get my serial output routine to work as interrupt driven code. I'd write a change into the code, program my MPGuino, turn on serial output via parameter, then watch my MPGuino continually reset.

It turns out that the Arduino compiler would blindly accept anything placed within the "ISR()" parentheses. For my serial output ISR, I could have written:

Code:

ISR( this_is_not_defined_vect ) { // serial UART transmit data ready vector
And Arduino would have compiled it with no error.

The reason that is important is because if Arduino does not have the actual interrupt vector that is found in interrupts.h (mentioned near the beginning of the MPGuino code), then whatever is inside the ISR() parentheses will default to interrupt vector 0. That happens to be the processor reset vector.

josemapiro 08-19-2013 04:44 PM

Quote:

Originally Posted by t vago (Post 386092)
Can you give us a list of the interrupt vectors you're using?

The vectors I'm using are the original version 0.86, has no change, what are these.
Code:

ISR(TIMER2_OVF_vect)
ISR(INT0_vect)
ISR(INT1_vect)
ISR( PCINT1_vect )

Thank you
José Rodrigues

josemapiro 08-20-2013 06:49 AM

I think the problem is the injector pins, together with the interruptions. I've been doing some more experiments in the code of the injectors, and did not do a reset, but the image did not change the lcd, even By pressing the buttons.

Thank you
José Rodrigues

josemapiro 08-27-2013 06:58 AM

I've been looking on the internet and found that the Timer2 in atmega 328 controls with pins 3 and 11, and with the mega, pins 9 and 10.
Is that the problem I have?
What is the advice you give, change the Timer2 or change the pins and keep the Timer2.
In the mega, the Timer0 and Timer2 are 8bits as the atmega 328, and the rest are 16bit.
To change the timer and keep 8bits, could only be with Timer0, which somewhat limits the options, I think the best is to change the pins and keep the Timer2.
What is your opinion regarding this issue.
Note: Pins that are occupied on my arduino mega are 13 and 11, the remaining PWM are free, I changed the lcd for Pins PA0, PA1, PA2, PA3, PA4 and PA5 Pins that are 22, 23, 24 , 25, 26 and 27.

Thank you
José Rodrigues

t vago 08-27-2013 09:21 AM

Quote:

Originally Posted by josemapiro (Post 387430)
I've been looking on the internet and found that the Timer2 in atmega 328 controls with pins 3 and 9, and with the mega, pins 9 and 10.

You should change the pins, then. The AtMega2560 has a hardware configuration that is different from the AtMega168/328, as you have seen, so anything you can do to modify the MPGuino code to fit the AtMega2560 will help you.

As to whether it's causing your continual resets... That's a good question. Only thing I can suggest is to keep on finding the spots in the MPGuino code that are hardware dependent, and change them. That, and keep good notes.

Quote:

Originally Posted by josemapiro (Post 387430)
What is the advice you give, change the Timer2 or change the pins and keep the Timer2.
In the mega, the Timer0 and Timer2 are 8bits as the atmega 328, and the rest are 16bit.
To change the timer and keep 8bits, could only be with Timer0, which somewhat limits the options, I think the best is to change the pins and keep the Timer2.
What is your opinion regarding this issue.

Keep Timer2, if at all possible. The MPGuino code is written to use Timer2, so changing the timer will cause you to have to extensively re-write the code. Concentrate on getting the code to work with the AtMega2560 hardware, first.

Quote:

Originally Posted by josemapiro (Post 387430)
Note: Pins that are occupied on my arduino mega are 13 and 11, the remaining PWM are free, I changed the lcd for Pins PA0, PA1, PA2, PA3, PA4 and PA5 Pins that are 22, 23, 24 , 25, 26 and 27.

Sounds like you have set yourself up to be able to simplify your LCD output routines.

josemapiro 08-28-2013 03:18 PM

I've been checking the Timer2 perishes not be related to the INT0 and INT1, but with the PWM pins OC1A and OC2B.
If I understand correctly, the Timer2, control the Pins 3 and 11, but as PWM output.
Please correct me if I'm wrong.

Quote:

Originally Posted by t vago (Post 387442)
Sounds like you have set yourself up to be able to simplify your LCD output routines.

Apparently this was the easiest part, the idea was to release the PWM pins for possible upgrades, while staying with the PWM pins free, for play with one or the other to make the injectors work.

Thank you
José Rodrigues

t vago 08-30-2013 12:09 PM

Quote:

Originally Posted by josemapiro (Post 387660)
I've been checking the Timer2 perishes not be related to the INT0 and INT1, but with the PWM pins OC1A and OC2B.
If I understand correctly, the Timer2, control the Pins 3 and 9, but as PWM output.

Not sure if you mean "pins 3 and 9" on your AtMega2560. On the AtMega328 (and presumably earlier chips), brightness is mapped to Port B bit 1, which is pin 15; and contrast is mapped to Port D bit 6, which is pin 12.

josemapiro 08-30-2013 02:02 PM

I apologize for the mistake, not the pin 3 and 9 but 3 and 11.

Quote:

Originally Posted by t vago (Post 387949)
Not sure if you mean "pins 3 and 9" on your AtMega2560. On the AtMega328 (and presumably earlier chips), brightness is mapped to Port B bit 1, which is pin 15; and contrast is mapped to Port D bit 6, which is pin 12.

I meant the atmega 328, Port D bit 3, pin 5, and Port B bit 3, pin 17.
The statement 3 and 11, is that recorded on board the arduino uno, so does the pins 9 and 10 of the Arduino Mega, once again I apologize for the confusion, I usually use the sheets with pinout of pighixxx.com , and this is reason to use that number and not the actual number of pins of the atmega chip.

This information was gathered from this site: Arduino 101: Timers and Interrupts | Let's Make Robots!
I leave here also the image of the pinout atmega 328 I use
http://www.pighixxx.com/pgdev/Temp/A...Pinout_Web.png
Might be useful to someone

Thank you
José Rodrigues

t vago 10-15-2013 08:01 PM

How do you have your LCD hooked up to your Mega?

josemapiro 10-23-2013 02:10 PM

Quote:

Originally Posted by t vago (Post 395608)
How do you have your LCD hooked up to your Mega?

I apologize for my lack of attention, I just concentrated on another post, I did not see your question. I will not answer now because I have done in another post, but if you have any questions feel free to ask.

Thank you
José Rodrigues


All times are GMT -4. The time now is 06:35 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Content Relevant URLs by vBSEO 3.5.2
All content copyright EcoModder.com