1. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    I've been stuck on trying to debug this code. I have used the MPLAB debugger and it seems to work perfectly but when I put it on the chip its not doing what I want. The code as is on my PIC is configured to have oscillation pulses to display pixels through a vga port. My GPIO 0, 1 and 2 act as a 3 bit binary counter to display colors and resets when GPIO 3 is high. So I basically display black through white each HSYNC pulse. My GPIO 4 bit outputs a HSYNC frequency at 29.57Hz which is a little low but I can eventually change it to be faster. My problem lies on the GPIO 5 bit which acts as my VSYNC. My code is configured to display a color band per VSYNC drawing at 60 frames a second. So the first second of drawing displays black, red and so on in sequence. While the next second would start with red instead of black but would cycle through all the colors.

    For some weird reason my GPIO 5 bit is somehow being brought low within the main chunk of the code. The only time I set the VSYNC low is when I use the delay loop so that should give me around 60Hz. Instead I am reading 25.91KHz on my multimeter when I probe GPIO 5.

    I'm using header file P12F675.inc and linker script 12F675_g.lkr fyi. Don't know if that could affect why it isn't working.

    Any suggestions as to what is happening?

    Code ( (Unknown Language)):
    1.  
    2.  
    3. list      p=12f675            ; list directive to define processor
    4. #include <p12f675.inc>        ; processor specific variable definitions
    5.  
    6.     __CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
    7.  
    8. ;*************************** REGISTERS ********************************
    9.  
    10. cblock  0x20
    11.     DelayCounter                    ; register location DelayCounter will contain number of loops that GPIO 5 is low
    12.     GPCounter                       ; register location GPCounter will contain status of color to be drawn per second
    13.     VSYNC                           ; register location VSYNC will contain number of loops before GPIO is set low
    14.     PixelCounter                    ; register location PixelCounter will contain number of loops per line draw
    15.     NA                              ; unused file location
    16.     ThreeCount                      ; register location ThreeCount will contain number of loops outside loops for VSYNC
    17. endc
    18.  
    19. ;*************************** CONSTANTS ********************************
    20.  
    21. #define Bank0       banksel 0x00        ; first registerr bank = Bank 0
    22. #define Bank1       banksel 0x80        ;second register bank = Bank 1
    23. #define ConfigTRI   B'00001000'         ; Configure I/O
    24.  
    25. ;******************** INITIALIZATION PROTOCOL **************************
    26.  
    27.     org     0x000               ; BIG BANG
    28.     goto    Initialize          ; Initialization call
    29.     org     0x005               ; Start of Programm Memory Vector
    30.  
    31. Initialize
    32.  
    33.     Bank0                       ; Bank 0 located at 0x00h
    34.     movlw   03h                 ; store 03 in
    35.     movwf   ThreeCount          ; ThreeCount
    36.     movlw   0A0h                ; store A0 in
    37.     movwf   VSYNC               ; VSYNC which means VSYNC is set low when A0 * 3 loops have been iterated
    38.     movlw   07h                 ; store 07 in  
    39.     movwf   PixelCounter        ; PixelCounter so 7 colors can be drawn per line
    40.     movwf   CMCON               ; CMCON so digital configuration is set
    41.     movlw   30h                 ; move binary value 00110000
    42.     movwf   GPIO                ; Hsync and Vsync are set by having GPIO 5,4 high
    43.  
    44.     Bank1                       ; Bank 1 located at 0x20h
    45.     clrw                        ; clear w register     
    46.     clrf    ANSEL               ; clear ANSEL register which controls analog or digital configuration making DIGITAL   
    47.     movlw   ConfigTRI           ; loads constant ConfigTRI
    48.     movwf   TRISIO              ; loads w register into TRISIO register which assigns I/O for GPIO pins
    49.  
    50.     Bank0                       ; return to Bank0 address
    51.  
    52. Main
    53.     incf    GPIO,1              ; increments gpio every pixel draw showing all 7 colors
    54.     decfsz  PixelCounter,1      ; when 7 colors are drawn then restart line
    55.     goto    Main
    56.     movlw   20h                 ; move binary value 00100000 clears HSYNC
    57.     movwf   GPIO                ; clears GPIO 4
    58.     movlw   07h                 ; move 7 to register w
    59.     movwf   PixelCounter        ; PixelCounter gets reset to 7
    60.     movlw   10h                 ; move 10h to w
    61.     addwf   GPCounter,0         ; add that value to color status
    62.     addwf   GPIO,1              ; move the contents of w and GPIO into GPIO setting first color draw
    63.     decfsz  VSYNC,1             ; decrement VSYNC
    64.     goto    Main
    65.     movlw   0A0h                ; resets VSYNC with
    66.     movwf   VSYNC               ; A0h
    67.     decfsz  ThreeCount,1        ; decrements ThreeCount    
    68.     goto    Main
    69.     movlw   03h                 ; move 3 to register w
    70.     movwf   ThreeCount          ; reset ThreeCount
    71.     clrf    GPIO                ; clear GPIO for Hsync and Vsync low pulse
    72.     movlw   49h                 ; move 49h to
    73.     movwf   DelayCounter        ; DelayCounter which sets Vsync's low time 
    74.  
    75. ;Vsync and Hsync low pulse
    76.  
    77. DelayLoop                       ; This loop will eventually be used to configure pixels
    78.     nop
    79.     nop
    80.     nop
    81.     nop
    82.     nop
    83.     nop
    84.     nop
    85.     decfsz  DelayCounter        ; decrement until DelayCounter is 0
    86.     goto    DelayLoop           ; then skip loop
    87.     incf    GPCounter,1         ; increment GPCounter which keeps track of color to be drawn first
    88.     btfsc   GPCounter,3         ; check GPIO bit 3 and if set reset color sequence to original
    89.     call    RGPCounter          ; reset GPCounter
    90.     movlw   30h                 ; set Hsync and Vsync to start drawing again
    91.     addwf   GPIO,1              ; add it to GPIO
    92.     movf    GPCounter,0         ; move contents in GPCounter to w
    93.     addwf   GPIO,1              ; add w and GPIO and then place in GPIO register
    94.     goto    Main                ; return to main loop
    95.  
    96. RGPCounter
    97.     movlw   00h                         ; move binary value 00110111
    98.     movwf   GPCounter                   ; Hsync and Vsync is set being the 5th and 6th bit on GPIO 
    99.     return
    100. end
    101.  
    102.  
     
Loading...