Pages: [1] 2   Go Down
Author Topic: Error: Arduino Mega 2560 - VGA OUTPUT  (Read 2803 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Hi,

I have a little problem with my VGA-Output and the Arduino Mega 2560.  smiley
I have built a little display with 26 LED’s, and I display on this random numbers form 0-99.
I want to display different texts that fit to the numbers with the VGA-Output. I tried to do the output like in this TuT
http://www.gammon.com.au/forum/?id=11608
And I got the source from here http://gammon.com.au/Arduino/VGA_output.zip
 
But if I try to upload the code on the Arduino then there is an Error: 
‘UCPHA0’ was not declared in this scope.

I must admit I don’t understand all of the code and I don’t finde the Error smiley-cry

Could somebody help me?
David
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12179
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The exact registers and their names do differ between Uno (ATmega328) and the Mega (ATmega2560) so you will have to compare
datasheets to see what the equivalent is.
Logged

[ I won't respond to messages, use the forum please ]

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As MarkT says, that code was designed around the Atmega328. It could be converted but you would need to check the datasheet for the timers (it uses two from memory) plus the UART in SPI mode.

Unfortunately something that is very hardware-specific (for timing reasons) can't be expected to be ported to a different processor and just work.
Logged


Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12179
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

[ I won't respond to messages, use the forum please ]

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
#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.)
« Last Edit: November 20, 2012, 06:38:53 pm by stimmer » Logged


Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink

-David
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok
i change the code like this
Quote
#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  smiley-cry

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


Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK I got some resistors  smiley-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?
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 22, 2012, 12:24:16 pm by stimmer » Logged


Pages: [1] 2   Go Up
Jump to: