Error: Arduino Mega 2560 - VGA OUTPUT

I could try and look at this myself as I've already got VGA set up on a breadboard for my other experiments, however I only have a Mega 1280. Before I start could anyone confirm that the mega 1280 and 2560 are similar enough for it to be worth my while? As far as I know they are almost exactly the same, aren't they?

Certainly it should work. I just checked the data sheet. The USART in SPI mode is supported, and of course the timers are there, it just has more of them. It would be a case of checking the exact names for the registers, and making sure that the timers settings are correct.

You would need to check the timer output pins since I use the hardware timer for vertical and horizontal sync. I'm confident it will work, it's just that I'm on another project right now.

stimmer:
Before I start could anyone confirm that the mega 1280 and 2560 are similar enough for it to be worth my while?

Yes, one just has more RAM etc. than the other.

Any thoughts on the Arduino Due and VGA? Personally I've only used a Parallax Propeller for driving VGA, as it will drive larger screens happily (1024x768 as 64 lines of 128 characters in 8 bit colour for instance). In fact I'd never really considered the Arduino for this, but with faster Arduinos this might become interesting...

The timing was the critical thing. You just don't get the required time to draw a pixel in VGA on a 16 MHz processor.

The pixel time at a horizontal resolution of 800 is 39.68 nS. You can't do that with a processor with a clock of 62.5 nS.

But the Due? With a clock of 84 MHz that should give the edge to allow individual pixels to be drawn. I reckon the clock must be 11.904 nS so that means you have a couple (three?) clock cycles to get a pixel out.

I'll give it a try when I get my hands on one.

We've been lucky. Only minimal changes are needed to get the program to comple and run. The compilation error was caused by a missing #define which is easily fixed. Then it is a simple matter of changing the hsync and vsync pins as the mega has them mapped to different pins.

Simply change the code near the beginning to this:

#define UCPHA0 1
const byte pixelPin = 1;     // <------- Pixel data
const byte hSyncPin = 9;     // <------- HSYNC
const byte MSPIM_SCK = 4;    // <-- we aren't using it directly
const byte vSyncPin = 12;    // <------- VSYNC

hsync is now on pin 9, vsync is on pin 12. I have not been able to test I2C yet. (Incidentally, MSPIM_SCK isn't connected to an external pin on the Mega - this does not affect the functioning of the code.)

Hi,
the kompiling works now. THX

If i am at home i will try it on my Arduino. When it works it would by nice ^^

thx for helping :wink:

-David

ok
i change the code like this

#define UCPHA0 1
const byte pixelPin = 1; // <------- Pixel data
const byte hSyncPin = 9; // <------- HSYNC
const byte MSPIM_SCK = 4; // <-- we aren't using it directly
const byte vSyncPin = 12; // <------- VSYNC

and I switch DB 3 with 9 and DB 10 with 12

ther should be an output with "Line i - hello!" on the display but i see nothing =(

if I put the VGA cable into my output, only the message “NO CONECTION” goes away and the screen gets black.

Or is this a problem with the resistors?
On V & H Sync I have 70 ohm and on RGB I have 475 ohm

Yes, you should see "Line 000 - hello!" "Line 001 - hello!" etc. Your resistors sound ok, I am using 68R and 470R

Things to try: experiment with the values of the resistors. My monitor refuses to sync if the values are too low.
At lines 283 and 291, try changing CLEAR_B_ON_COMPARE to SET_B_ON_COMPARE for one, other or both lines.
If you have an oscilloscope or frequency meter, check the vsync and hsync outputs to see that you are getting something. Or at least check the vsync output with headphones and make sure you hear a buzz.

stimmer:
Yes, you should see "Line 000 - hello!" "Line 001 - hello!" etc. Your resistors sound ok, I am using 68R and 470R

Things to try: experiment with the values of the resistors. My monitor refuses to sync if the values are too low.
At lines 283 and 291, try changing CLEAR_B_ON_COMPARE to SET_B_ON_COMPARE for one, other or both lines.
If you have an oscilloscope or frequency meter, check the vsync and hsync outputs to see that you are getting something. Or at least check the vsync output with headphones and make sure you hear a buzz.

Ok
I tried all combinations on lines 283 and 291. It did not work.
I will try to get 68 ohm and 470 ohm resistors and try it again :wink:

OK I got some resistors :wink:
V & H sync I got 68,5 ( i had no better one)
RGB I got 473 (also the best I found)
I checked all connection, they are ok.
I heard on all Pins a buzz with my headset (R,G,B -> HIGH frequency& loud , V Sync -> low frequency & loud, H Sync -> low frequency & very quiet)
Also I checked my monitor and it is ok, but as a precaution I took a second monitor. But also no signal (black screen)
I have no idea what the problem is
Should I give the H Sync a lower resistor?

When you say 473 do you mean 473 ohms (unusual value, but possible if it is a high precision resistor) or does the resistor have 473 written on it (which could mean 47000 ohms)? If you are unsure, check it with a multimeter.

For V and H sync just experiment, the value shouldn't be too critical, try whatever resistors you have between 10 ohms and 100 ohms.

Are the monitors LCD or CRT? Both should work, though LCD monitors can sometimes be a bit random.

stimmer:
When you say 473 do you mean 473 ohms (unusual value, but possible if it is a high precision resistor) or does the resistor have 473 written on it (which could mean 47000 ohms)? If you are unsure, check it with a multimeter.

For V and H sync just experiment, the value shouldn't be too critical, try whatever resistors you have between 10 ohms and 100 ohms.

Are the monitors LCD or CRT? Both should work, though LCD monitors can sometimes be a bit random.

473 Ohms :wink:
I had check it with a multimeter ( i had only 2 different resistors, that i but together so i checked)
both are LCD monitors
ok i try other resistors for V & H

I GOT IT ^^ :grin: :grin: :grin:
22 Ohm to V& H and it works on both ^^

i can use SET_B_ON_COMPARE or CLEAR_B_ON_COMPARE (same result)

thx for helping XD

Fantastic :slight_smile:

It runs know, but if I put in my code for the LEDs and the random numbers, the Screen is splinted into many black bars. :stuck_out_tongue:
I think the problem is that the Arduino draw the line, then it edited my code(=no monitor signal) and then it draw a line again.

My question is now:
Can the arduino handle two different codes to the same time?

No, only one processor and the VGA output uses all the horsepower...

hmmm...
Are you shure that the Arduino Mega cant handle it
I want to use 1 Arduino for that VGA, for my LEDs & Buttons and for my DCF 77 time modul. I thought if I buy the big on he can handle this.

Are you shure that the Arduino Mega cant handle it

That is not what you asked. You asked:-

Can the arduino handle two different codes to the same time?

Without more than one core the processor can only do one thing at once. However if you do the code rapadly one after the other it will look like to you that two things are happening at the same time.