Go Down

Topic: Error: Arduino Mega 2560 - VGA OUTPUT (Read 3423 times) previous topic - next topic

derdem2


Hi,

I have a little problem with my VGA-Output and the Arduino Mega 2560.  :)
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 =(

Could somebody help me?
David

MarkT

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.
[ I won't respond to messages, use the forum please ]

Nick Gammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

stimmer

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?
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

Nick Gammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon


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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

MarkT

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...
[ I won't respond to messages, use the forum please ]

Nick Gammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

stimmer

#8
Nov 21, 2012, 12:37 am Last Edit: Nov 21, 2012, 12:38 am by stimmer Reason: 1
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: [Select]

#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.)
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

derdem2

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 ;)

-David

derdem2

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  =(

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



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.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

derdem2


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 ;)

derdem2

OK I got some resistors  ;)
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?

stimmer

#14
Nov 22, 2012, 06:22 pm Last Edit: Nov 22, 2012, 06:24 pm by stimmer Reason: 1
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.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

Go Up