logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[ATMEGA32][Bascom] Wyświetlanie obrazu na TV.

MacFis 29 Cze 2009 13:38 5593 4
REKLAMA
  • #1 6717586
    MacFis
    Poziom 17  
    Witam!

    Mam do dyspozycji Atmega32, Atmega8 i Attiny2313. Chciałbym zbudować prosty generator obrazu TV. Wejście wideo podłączam do Atmegi32 przez rezystor 1K i 330Ohm.

    ................................................/ -rezystor 1k------ ----- PORTD.5
    Wejście Wideo (Chinch)------<
    ................................................\-rezystor 330Ohm ---- PORTD.6

    I mam problem z programem. A konkretnie to nie wiem jak go napisać. Od czego zacząć? W pomocy Bascom'a nic takiego nie znalazłem...
  • REKLAMA
  • #2 6719120
    PiotrEtenM500
    Poziom 19  
    
    '  ************************************************************************************** 
    '  *                                                                                    * 
    '  * Mega 8 PAL Video Test Pattern 64 Colours ( noninterlaced )                         * 
    '  *                                                                                    * 
    '  * V3.1.38 (c) 2008 Moshtech                                                           * 
    '  *                                                                                    * 
    '  ************************************************************************************** 
    ' 
    '  Device -> Analog Devices AD722 or ( AD724 ) 
    ' 
    '  Note: This chip needs to have the correct timing !!! 
    '        If the HSync pulse is to short or long no colour burst will not occour ! 
    '        The RGB input must be set to zero ( Black ) during sync and colour burst or it will cause problems 
    '        Also, the RGB must be at black level at the end of the line. ( distorts next few lines ) 
    ' 
    '        The Mega 8 is overclocked to 24Mhz with an external OSC module, it will work at 20 or 16Mhz, 
    '        However, less time is available to draw the screen, higher clock = smaller pixels. 
    '        24Mhz gives about ~60 useable pixels per horizontal line ( in basic ) 
    ' 
    '  RED   X1 - PC5       6 Bit Video data, 64 colours inc black 
    '  RED   X2 - PC4 
    '  GREEN X1 - PC3 
    '  GREEN X2 - PC2 
    '  BLUE  X1 - PC1 
    '  BLUE  X2 - PC0 
    ' 
    '  HSYNC - PB1          Syncs are both active low, to chip via 100 Ohm 
    '  VSYNC - PB0          Not used, pull high 
    ' 
    '  Option: Put blanking buffer here, between the AVR port & the resistor network. 
    '  74F AND or NAND gate with pullups on the outputs, or Buffer with enable, etc... 
    '         \/ 
    '                             VCC 
    '                              | 
    '                              | 
    '                             10pf 
    '                              | 
    '                              | 
    '   X1  -------- 10K ----------* 
    '                              | 
    '   X2  ---- 10K ----- 10K ----*----- 100n ----- RGB IN (AD722) <- or to maxim buffer chip for RGB out 
    '                              | 
    '                              | 
    '   OPT ----- 10K X4 ----------* 
    '                              | 
    '   OPT ----- 10K X8 ----------*     <- to add more bits 
    '                              | 
    '   OPT ----- 10K X16 ---------* 
    '                              | 
    '                              | 
    '              ---->        680 ohm 
    '             |                | 
    '  Fixed  -> 1K       or       | 
    '              ---->      500 ohm pot <- colour adjust 
    '                              | 
    '                              | 
    '                             GND 
    ' 
    '  Repeat above circuit for other colours 
    ' 
    '  References :   Analog Devices          AD722.pdf 
    '                 Analog Devices          AD722AN.pdf 
    '                 Maxim                   AN734.pdf 
    '                 Silicon Chip Magazine   June 2004 p24 ( Dr Video Mk.2 ) 
    '                 Silicon Chip Magazine   June 2006 p28 ( Pocket AV Generator ( AD724 )) 
    '                 Silicon Chip Magazine   September 2006 p84 ( S-Video to Composite converter ) 
    '                 PAL Standards info      http://www.kolumbus.fi/pami1/video/pal_ntsc.html 
    ' 
    ' ****************************************************************************************************************************** 
    '$sim 
    $regfile = "m8def.dat"                                      ' * Mega 8 
    $crystal = 24000000                                         ' * 24 MHz External OSC ( 16Mhz part OVERCLOCKED !!! ) 
    $hwstack = 128                                              ' * default use 32 for the hardware stack 
    $swstack = 128                                              ' * default use 10 for the SW stack 
    $framesize = 64                                             ' * default use 40 for the frame space 
    ' ****************************************************************************************************************************** 
    Const Pause = 500                                           ' *  250 * Delay ms main loop 
    Const Hsync_delay = 1471                                    ' * 1471 * Value to load timer1 (HSync) with, 1536 = 64us @ 24Mhz 
    Const Vid_start = 146                                       ' *  146 * Delay from start of HSync untill the start of the video data 
    Const Sync_del = 3.201                                      ' * 3.201 * Delay to pad out HSync low ( total 4.7us ) 
    Const Grid = 1.85                                           ' *  1.85 * box size 
    ' ****************************************************************************************************************************** 
    Colour Alias Portc                                          ' * port C video data, 2 bit RGB 
    Hsync Alias Portb.1                                         ' * Horizontal Sync Output ( on timer 1 ouput pin OC1A, not used ) 
    Vsync Alias Portb.0                                         ' * Vertical Sync Output 
    ' ****************************************************************************************************************************** 
    Dim Current_line As Word                                    ' * Horizontal line counter 
    Dim Current_block As Byte                                   ' * Horizontal block counter 
    Dim Video As Byte                                           ' * video data ( used for, for next loops ) 
    Dim Tick As Word                                            ' * Vsync counter 50 ticks per second PAL                                         ' 
    Dim Colour_rnd As Byte                                      ' * random colour per field 
    Dim New_colour As Byte                                      ' * new colour for cycling bars 
    Dim Temp As Byte 
    ' ****************************************************************************************************************************** 
    Config Hsync = Output 
    Config Vsync = Output 
    Config Colour = Output 
    ' ****************************************************************************************************************************** 
    Set Hsync                                                   ' * active low 
    Set Vsync                                                   ' * active low 
    Colour = 0                                                  ' * colour data ( black ) 
    ' ****************************************************************************************************************************** 
    ' ********** Configure Timer 0  : Delay from start of HSync untill Video data start ( Only active during Horizontal line ) 
    Config Timer0 = Timer , Prescale = 1 
    On Timer0 Vid_line                                          ', Nosave 
    Load Timer0 , Vid_start 
    Enable Timer0 
    ' ****************************************************************************************************************************** 
    ' ********** Configure Timer 1  : 64us PAL HSync timer 
    Config Timer1 = Timer , Prescale = 1 
    On Timer1 Sync_h 
    Load Timer1 , Hsync_delay 
    Enable Timer1 
    Start Timer1 
    ' ****************************************************************************************************************************** 
    Enable Interrupts 
    ' ********** Main Loop 
    Do 
    
       New_colour = Colour_rnd 
    
       Waitms Pause 
    
    Loop 
    
    ' ****************************************************************************************************************************** 
    ' *                                                                                                                            * 
    ' *  Horizontal Sync IRQ, uses timer1 for a total of 64us, 4.7us low pulse. Counts lines and starts video IRQ                  * 
    ' *                                                                                                                            * 
    ' ****************************************************************************************************************************** 
    
    Sync_h: 
    
       Toggle Hsync                                             ' * Set HSync Low, Start H cycle 
       Load Timer1 , Hsync_delay                                ' * Reload the timer ( total cycle PAL = 64us ) 
       Load Timer0 , Vid_start                                  ' * Load timer0 with delay value for start of video data 
       Start Timer0                                             ' * enable the timer only during HSync IRQ, Hsync must finish before timer0 IRQ hits 
       If Current_line = 1 Then Toggle Hsync                    ' * if first line, Start VSync pulse 
       If Current_line = 3 Then Toggle Hsync                    ' * if 3rd line, End Vsync pulse 
       Waitus Sync_del                                          ' * wait ( total from start IRQ code ) 4.7us 
       Toggle Hsync                                             ' * Set HSync High, End H cycle 
    
       Incr Current_line                                        ' * increment line counter 
       If Current_line = 301 Then Colour_rnd = Rnd(&B00111111)  ' * for colour cycling bar 
       If Current_line = 311 Then Toggle Vsync                  ' * sync for scope trigger 
       If Current_line = 312 Then Incr Tick                     ' * increment system tick counter ( once per field 50Hz PAL ) 
       If Current_line = 313 Then Current_line = 0              ' * last line ( non interlaced ) 
    
    Return 
    
    ' ****************************************************************************************************************************** 
    ' *                                                                                                                            * 
    ' * Display Video Data IRQ, uses timer0 to delay the start of video data to the same point per line, aprox 10.5us              * 
    ' *                                                                                                                            * 
    ' ****************************************************************************************************************************** 
    
    Vid_line: 
       Stop Timer0                                              ' * Stop timer0 untill next video line ( it will retrigger before the line ends if we don't ! ) 
       On Current_block Gosub Lin0 , Lin1 , Lin2 , Lin3 , Lin4 , Lin5 , Lin6 , Lin7 , Lin8 , Lin9 , Lin10 , Lin11 , Lin12 , Lin13 , Lin14 , Lin15 , Lin16 , Lin17 
    Return                                                      ' * Use on gosub ( quicker than if a< or a> then gosub etc... ) 
    
    ' * first block ******************************************************************************************** colour bars 
    Lin0:                                                       ' * Blank line ( No data all set black ) 
       Colour = 0 
       If Current_line = 23 Then Incr Current_block             ' * start line is normaly 23 
    Return 
    
    Lin1: 
    For Video = 0 To 47 Step 1 
       Colour = 0                                               ' * insert black between colours 
       Colour = Timer1                                          ' * electricky ;-) 
    Next Video 
       Colour = 0                                               ' * must end with black !!!!!! 
       If Current_line = 50 Then Incr Current_block             ' * next block 
    Return 
    
    ' * second block ******************************************************************************************* colour blocks 1 
    Lin2:                                                       ' * Blank line 
       Colour = 0 
       If Current_line = 60 Then Incr Current_block             ' * next block 
    Return 
    
    Lin3: 
    For Video = 0 To 15 Step 1 
       Colour = 0 
       Colour = Video 
       Waitus Grid 
    Next Video 
       Colour = 0                                               ' * must end with black !!!!!! 
       If Current_line = 84 Then Incr Current_block             ' * next block 
    Return 
    
    ' * third block ******************************************************************************************** colour blocks 2 
    Lin4:                                                       ' * Blank line 
       Colour = 0 
       If Current_line = 90 Then Incr Current_block             ' * next block 
    Return 
    
    Lin5: 
    For Video = 16 To 31 Step 1 
       Colour = 0 
       Colour = Video 
       Waitus Grid 
    Next Video 
       Colour = 0                                               ' * must end with black !!!!!! 
       If Current_line = 114 Then Incr Current_block            ' * next block 
    Return 
    
    ' * forth block ******************************************************************************************** colour blocks 3 
    Lin6:                                                       ' * Blank line 
       Colour = 0 
       If Current_line = 120 Then Incr Current_block            ' * next block 
    Return 
    
    Lin7: 
    For Video = 32 To 47 Step 1 
       Colour = 0 
       Colour = Video 
       Waitus Grid 
    Next Video 
       Colour = 0                                               ' * must end with black !!!!!! 
       If Current_line = 144 Then Incr Current_block            ' * next block 
    Return 
    
    ' * fith block ******************************************************************************************** colour blocks 4 
    Lin8:                                                       ' * Blank line 
       Colour = 0 
       If Current_line = 150 Then Incr Current_block            ' * next block 
    Return 
    
    Lin9: 
    For Video = 48 To 63 Step 1 
       Colour = 0 
       Colour = Video 
       Waitus Grid 
    Next Video 
       Colour = 0                                               ' * must end with black !!!!!! 
       If Current_line = 174 Then Incr Current_block            ' * next block 
    Return 
    
    ' * sixth block ******************************************************************************************** colour cycle blocks 
    Lin10:                                                      ' * Blank line 
       Colour = 0 
       If Current_line = 180 Then Incr Current_block            ' * next block 
    Return 
    
    Lin11: 
    For Video = 0 To 31 Step 2 
       Colour = 0 
       Temp = New_colour + Timer1 
       Colour = Temp + Video 
       Waitus 1.36 
    Next Video 
       Colour = 0                                               ' * must end with black !!!!!! 
       If Current_line = 200 Then Incr Current_block            ' * next block 
    Return 
    
    ' * seventh block ******************************************************************************************** grey blocks 
    Lin12:                                                      ' * Blank line 
       Colour = 0 
       If Current_line = 206 Then Incr Current_block 
    Return 
    
    Lin13: 
    For Video = 1 To 3 Step 1 
       Colour = 0 
       Colour = Lookup(video , Grey) 
       Waitus 12.4 
    Next Video 
       Colour = 0                                               ' * must end with black !!!!!! 
       If Current_line = 232 Then Incr Current_block            ' * next block 
    Return 
    
    ' * eighth block ******************************************************************************************** rainbow 
    Lin14:                                                      ' * Blank line 
       Colour = 0 
       If Current_line = 238 Then Incr Current_block            ' * next block 
    Return 
    
    Lin15: 
    For Video = 1 To 59 Step 1 
       Incr Colour 
    Next Video 
       Colour = 0                                               ' * must end with black !!!!!! 
       If Current_line = 264 Then Incr Current_block            ' * next block 
    Return 
    
    ' * last block ********************************************************************************************** colour fall 
    Lin16:                                                      ' * Blank line 
       Colour = 0 
       If Current_line = 270 Then Incr Current_block            ' * next block 
    Return 
    
    Lin17: 
    For Video = 0 To 200 Step 4 
       Colour = Video + Current_line                            ' * more electricky ;-) 
    Next Video 
       Colour = 0                                               ' * must end with black !!!!!! 
       If Current_line = 300 Then Current_block = 0             ' * last block, reset to zero  ( normaly at line 288 ) 
    Return 
    
    End 
    
    ' * Data for grey bars, block #7 
    Grey: 
    Data &B00000000 
    Data &B00000111 
    Data &B00111000 
    Data &B00111111 
    
  • REKLAMA
  • REKLAMA
  • #4 6719981
    PiotrEtenM500
    Poziom 19  
    nie wiem co chcesz osiągnąć więc podałem taki przykład
    zobacz kit z AVT2853. To jest proste i tanie

    Tu bardzo ładny projekt, ze źródełkiem i opisem
    Link
  • #5 7589696
    Marcin_xx1
    Poziom 21  
    Był podobny temat w bascom tyle ze dla monitora, trzeba zmienić (zwiększyć)
    czasy impulsów dla telewizora https://www.elektroda.pl/rtvforum/topic1210857.html z attiny na powyższe procesory chyba nie jest trudno
    przenieść kod.

    Dodano po 13 [minuty]:

    Jeżeli powyższy układ pracuje w trybie vga to być może wystarczy obniżyć częstotliwość kwarcu o polowe i odchylanie poziome będzie się zgadzać z telewizyjnym, nie wiem jak tam działa obliczanie ramki, dla telewizora trzeba około 50 hz, trzeba by jeszcze przerobić wyjście impulsów synchronizacji
    by wszystkie były na jednym pinie.
REKLAMA