Verifying alignment of OC1A, OC1B waveforms in mode 15

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Freaks!

 

Recently, I've been dabbling in some VGA generation on an ATmega88PA.

I came up with a method of generating aligned sync pulses, as per VESA:

 

 

Here's a minimal code example for generating the syncs only (for clarity, the actual code is in assembly and quite lengthy):

#include <avr/io.h>
#include <avr/interrupt.h>

#define HTOTAL 800
#define HSYNC 96
#define VTOTAL 525
#define VSYNC 2

int main(void)
{
    /// set OC1A, OC1B as outputs, pullups on the rest
    DDRB = (1<<OC1A_BIT)|(1<<OC1B_BIT);
    PORTB = 0xff;
    /// drive RGB lines low
    DDRC = 0x3f;
    PORTC = 0x00;

    OCR1A = HTOTAL-1;
    OCR1B = HSYNC-1;
    TIMSK1 = 1<<OCIE1A;
    TCCR1A = (1<<COM1A1)|(1<<COM1A0)|(1<<COM1B1)|(1<<COM1B0)|(1<<WGM11)|(1<<WGM10);
    TCCR1B = (1<<WGM13)|(1<<WGM12)|(1<<CS10);

    sei();
    for (;;);
}

ISR(TIMER1_COMPA_vect)
{
    static uint16_t line;
    uint16_t next = line+1; /// setting up vsync for next scanline

    if (next == VTOTAL) {
        next = 0; /// reset scanline counter
        TCCR1A |= (1<<COM1A0); /// vsync on - inverting mode
    } else if (next == VSYNC) {
        TCCR1A &= ~(1<<COM1A0); /// vsync off - noninverting mode
    }
    line = next;
}

How is this supposed to work?

  1. a HSYNC waveform is generated on OC1B in inverting mode
  2. an interrupt is generated at the beginning ov every scanline as well
  3. in the interrupt, COM1A bits are changed based on what VSYNC (OC1A) state should be during the NEXT scanline

The idea in 3. is that since the timer is in mode 15, OCR1A = TOP by definition, so OC1A permanently outputs a 100% duty cycle PWM.

Changing between inverting and noninverting mode should give transitions perfectly aligned to HSYNC falling edges/timer resets.

 

So far, so good... This does generate syncs that my monitor accepts, but that tells me nothing about the syncs being aligned or not.

So, my question boils down to: does the above code produce aligned pulses or not?

 

Unfortunately, I don't have a scope and cannot check that easily...

I realize that asking someone else to put the circuit together might be a bit too much, but any input is appreciated!

 

This topic has a solution.
Last Edited: Tue. Jan 7, 2020 - 12:39 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Antimonn wrote:

So, my question boils down to: does the above code produce aligned pulses or not?

 

Unfortunately, I don't have a scope and cannot check that easily...

I realize that asking someone else to put the circuit together might be a bit too much, but any input is appreciated!

 

It's no trouble at all. I just uploaded it to an Arduino nano, since the mega328p and the mega88 are from the same subfamily, it's very easy.

Just added this to the code

#define OC1A_BIT 1
#define OC1B_BIT 2

 

Here you go, the pulses are aligned perfectly:

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you see the VGA tutorial?  https://www.avrfreaks.net/forum/...

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, glad to see it works as predicted!

 

El Tangas wrote:

Just added this to the code

#define OC1A_BIT 1
#define OC1B_BIT 2

 

Do you use a compiler other than avr-gcc? If not, that's weird, my installation already had these defines in the IO headers.

 

ki0bk wrote:

Have you see the VGA tutorial?  https://www.avrfreaks.net/forum/...

Jim

 

 

Sure! It has certainly been helpful, but I guess at this point I want to do things my own way.

For now, I'm bitbanging from the AVR only. I already have stable video output; this question was concerned only with my sync generation method.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Antimonn wrote:

Do you use a compiler other than avr-gcc? If not, that's weird, my installation already had these defines in the IO headers.

 

 

I used the Arduino IDE, I usually do for quick tests. The compiler is gcc 7.3.0 but for some reason it complained about those defines missing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Be sure to watch the video & links here...lots of good information you might enjoy

http://www.linusakesson.net/scene/craft/

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

Be sure to watch the video & links here...lots of good information you might enjoy

http://www.linusakesson.net/scene/craft/

 

I know lft's awesome demos too!

Analysing the code has been a great learning experience.

In fact, a lot of my video code is based on lft's work.

 

El Tangas wrote:
I used the Arduino IDE, I usually do for quick tests. The compiler is gcc 7.3.0 but for some reason it complained about those defines missing.

 

Hmm, maybe they were added in later versions? I'm using 9.2.0.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Antimonn wrote:
Unfortunately, I don't have a scope and cannot check that easily...
I'm astonished that anyone has got to:

Antimonn wrote:
. I already have stable video output;
without one!!

 

You can get a logic analyser or basic scope from ebay for just a few dollars. Such a thing would be invaluable in exploring the signals for video generation.

 

Shame you just missed Santa who could probably have dropped one off!