CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

MAX7456 Problems

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
guest1234
Guest







MAX7456 Problems
PostPosted: Mon Mar 09, 2009 3:57 pm     Reply with quote

Hey guys, I'm working on an On Screen Display project for my senior design course and I'm running into some problems.
CCS Version: 4.084
MPLAB Version: 8.15a
PIC: 18F4520
OSD Chip: MAX7456
Programming is really not my thing, I haven't had too many classes on it. I have studied the manual to the MAX7456 from back to front and cannot find the answers to my problems. I have the following program as an example to program the letters 'ABC' into the middle of the screen. Each time I program it into the PIC18F4520 different letters show up in the middle of the screen. If I turn the power off to the PIC and MAX7456 the same characters show up, but not the ones I want to show based off the table in the MAX7456 manual.

Also, there are big black underscores between each possible spot for the characters on the screen. I have tried setting registers to different values to try to get rid of these underscores, but it was to no avail.

Any advice you have would be greatly appreciated. I want to add a whole lot more features but I have to get the simple stuff working before moving on.


Code:

#include <18F4520.h>

#device adc=8
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC                    //Internal RC Osc
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#include <float.h>
#include <math.h>
#include <string.h>
 // SPI modes
int8 max7456_add_reg;
int8 max7456_data_reg;
int8 OSD_AUTO_BLACK;
#define MAX7456_VIDEO_0_REG_ADD 0x00
#define MAX7456_VIDEO_1_REG_ADD 0x01
#define MAX7456_CHARACTER_MEMORY_ADDRESS_HIGH_WRITE 0x09
#define MAX7456_CHARACTER_MEMORY_ADDRESS_HIGH_READ 0x89
#define MAX7456_VIDEO_0_REG_ADD_RD 0x80
#define MAX7456_VIDEO_1_REG_ADD_RD 0x81
#define MAX7456_VIDEO_STATUS_REG_ADD_RD 0xA0
#define MAX7456_DISPLAY_MEMORY_MODE_REG_ADD 0x04
#define MAX7456_DISPLAY_MEMORY_ADDRESS_HIGH 0x05
#define MAX7456_DISPLAY_MEMORY_ADDRESS_LOW 0x06
#define MAX7456_DISPLAY_DATA_IN 0x07
#define MAX7456_OSD_BLACK_LEVEL_WRITE 0x6C
#define MAX7456_OSD_BLACK_LEVEL_READ 0xEC
#define MAX7456_DMM_REG_ADD_RD 0x84
#define MAX7456_DM_ADDRESS_HIGH_RD 0x85
#define MAX7456_DM_ADDRESS_LOW_RD 0x86
#define MAX7456_DISPLAY_DATA_IN_RD 0x87
#define VIDEO_REG_0_DEFAULT_VALUE 0x04
#define VIDEO_REG_0_DEFAULT_VALUE_RESET 0x05
#define ENABLE_VIDEO_BUFFER 0x00
#define DISABLE_VIDEO_BUFFER 0x01
#define ENABLE_DISPLAY_OSD_IMAGE 0x08
#define VIDEO_1_REG_DATA 0x00
#define AUTO_ADDRESS_INCREMENT_ON 0x01
#define AUTO_ADDRESS_INCREMENT_OFF 0x00
#define ENABLE_MAX7456_OSD_IMAGE 0x0C
#define TOTAL_BIT_NEED_TO_SEND 8
#define BIT_7_IS_SET 0x80
#define BITS_NEED_TO_SHIFT 0x01
#define DATA_MASK_OFF 0xFF


#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)


void main()

{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_MODE_0|SPI_CLK_DIV_4);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_4MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
output_high(PIN_D0);

/* DISABLE VIDEO OUTPUT */
max7456_add_reg = MAX7456_VIDEO_0_REG_ADD;     //clear all Display memory
max7456_data_reg = 0x01;
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);
/* SEND ADDRESS */

delay_ms (10);        //Once cleared register is not available for 20us to write to again.

max7456_add_reg = MAX7456_VIDEO_0_REG_ADD;    //Enables Autosync and NTSC
max7456_data_reg = 0x00;
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);
/* SEND ADDRESS */

max7456_add_reg = MAX7456_DISPLAY_MEMORY_ADDRESS_HIGH;  //Sets video display to uppper half of screen
max7456_data_reg = 0x00;
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);

max7456_add_reg = MAX7456_DISPLAY_MEMORY_ADDRESS_LOW;   //Sets display to middle of screen
max7456_data_reg = 0xE0;
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);
/* SEND DATA */

max7456_add_reg = MAX7456_DISPLAY_DATA_IN;
max7456_data_reg = 0x0B;               //Corresponds to the letter 'A'
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);

/* SEND ADDRESS */
max7456_add_reg = MAX7456_DISPLAY_MEMORY_ADDRESS_HIGH;
max7456_data_reg = 0x00;
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);

max7456_add_reg = MAX7456_DISPLAY_MEMORY_ADDRESS_LOW;
max7456_data_reg = 0xE1;
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);
/* SEND DATA */

max7456_add_reg = MAX7456_DISPLAY_DATA_IN;   
max7456_data_reg = 0x0C;         //Letter 'B'
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);

/* SEND ADDRESS */
max7456_add_reg = MAX7456_DISPLAY_MEMORY_ADDRESS_HIGH;
max7456_data_reg = 0x00;
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);

max7456_add_reg = MAX7456_DISPLAY_MEMORY_ADDRESS_LOW;
max7456_data_reg = 0xE2;         
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);
/* SEND DATA */

max7456_add_reg = MAX7456_DISPLAY_DATA_IN;
max7456_data_reg = 0x0D;            //Letter 'C'
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);

//ENABLE VIDEO OUTPUT
max7456_add_reg = MAX7456_VIDEO_0_REG_ADD;
max7456_data_reg = 0x08;         //Enables Display of OSD
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);

max7456_add_reg = MAX7456_OSD_BLACK_LEVEL_READ;    //read osd black level register
OUTPUT_LOW (PIN_D0);                        
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
OSD_AUTO_BLACK = SPI_READ (0);
OUTPUT_HIGH (PIN_D0);

max7456_add_reg = MAX7456_OSD_BLACK_LEVEL_WRITE;
bit_clear (OSD_AUTO_BLACK, 4);               //clears bit 4, enables OSD to automatically control black levels
max7456_data_reg = OSD_AUTO_BLACK;
OUTPUT_LOW (PIN_D0);
/* send 8 bit address */
SPI_WRITE (max7456_add_reg);
/* send 8 bit data */
SPI_WRITE (max7456_data_reg);
OUTPUT_HIGH (PIN_D0);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 09, 2009 4:29 pm     Reply with quote

The first thing you need to do is to get rid of all that inline code.
Use routines for the low level access functions to the chip. See the
write routine below for an example. This cleans up your code.
Also get rid of most of the comments, and get rid of the traditional C
"block" comments. They dazzle you with the asterisks, and they get
in the way of seeing what you're doing. Also, you don't need most of
the CCS Wizard code. It's just turning off peripherals that are turned
off anyway by default, upon power-up of the PIC.

Here's an example of a cleaner program. Notice that I added a delay
after the initial setup of the SPI port. The MAX7456 data sheet says
there is a power-on delay of 50 ms typical. (See page 5 ).
Also, function names are normally in lower case, or mixed case.
All caps is reserved for constants.

Other than checking the power-up delay, SCLK frequency, SPI write
protocol, and that it uses SPI mode 0, I didn't really check your code.
I mean that I didn't check the details of programming the chip's registers.
Code:

#include <18F4520.h>
#fuses INTRC, NOWDT, NOPROTECT, BROWNOUT, BORV20, PUT
#use delay(clock=4000000)

#define MAX7456_CS  PIN_D0

void max7456_write(int8 addr, int8 data)
{
output_low(MAX7456_CS);
spi_write(addr);
spi_write(data);
output_high(MAX7456_CS);
}

//======================================
void main()
{
setup_spi(SPI_MASTER|SPI_MODE_0|SPI_CLK_DIV_4);
output_high(MAX7456_CS);
delay_ms(100);   // Minimum power-up delay is 50 ms

max7456_write(MAX7456_VIDEO_0_REG_ADD, 0x01);
delay_ms (10);
max7456_write(MAX7456_DISPLAY_MEMORY_ADDRESS_HIGH, 0x00);
max7456_write(MAX7456_DISPLAY_MEMORY_ADDRESS_LOW, 0xE0);

etc.
.
.
.



while(1);
}
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 3:49 am     Reply with quote

The other thing to note is that the decoupling capacitors which need to be close to the max7456, are most probably essential, and the spi wire/trace length need to be kept to a minimum.
guest1234
Guest







PostPosted: Tue Mar 10, 2009 8:52 am     Reply with quote

Thanks for the advice. Its been awhile since I learned about calling a function, but this will reduce the size of my code substantially.

The SPI wires are about 4 inches in length. Is this a problem? I will continue to mess with the programming and circuit today and hopefully make some progress
Guest








PostPosted: Fri Apr 03, 2009 9:21 am     Reply with quote

I wrote this program for RTCKBD (w w w.blackboxcamera.com/pic-osd/rtckbd.htm). 16f628 is used on that unit. In order not to use spi module on the chip I wrote a software spi algorithm. When running program, it will appear "FATIH" on left-top of display.
Code:

#include <16f628.h>
#fuses INTRC, NOWDT, NOPROTECT, BROWNOUT,  PUT
#use delay(clock=4000000)

#define MAX7456_CS  PIN_A1
#define SCKL  PIN_A0
#define SIN  PIN_A2

int i;

void spi_write(int8 data) //software spi
{
   for(i=0; i<=7; ++i) {

   output_low(SCKL);

   if(bit_test(data, 7-i)) output_high(SIN);
   if(!bit_test(data, 7-i)) output_low(SIN);

   output_high(SCKL);
   }

output_low(SCKL);
output_low(SIN);
}
//-----------------------------------------------
void max7456_write(int8 addr, int8 data)
{
output_low(MAX7456_CS);
spi_write(addr);
spi_write(data);
output_high(MAX7456_CS);
}

//-----------------------------------------------
void main()
{
output_high(MAX7456_CS);

delay_ms(50);   // Minimum power-up delay is 50 ms

max7456_write(0x00, 0b01001000); //enable osd , PAL
max7456_write(0x04, 0b01000000); //8-bit operation mode

while(1)
{

max7456_write(0x00, 0b01001000); //enable osd

max7456_write(0x06, 0b00000000); //horizontal position
max7456_write(0x07, 'F');
max7456_write(0x06, 0b00000001);
max7456_write(0x07, 'A');
max7456_write(0x06, 0b00000010);
max7456_write(0x07, 'T');
max7456_write(0x06, 0b00000011);
max7456_write(0x07, 'I');
max7456_write(0x06, 0b00000100);
max7456_write(0x07, 'H');

delay_ms(1000);

max7456_write(0x00, 0b01000000); //disable osd

delay_ms(1000);
}
}


Best Regards,
Fatih
juanf5426
Guest







Problem with OSD display
PostPosted: Tue May 12, 2009 11:24 am     Reply with quote

Hi, I´m also working in a OSD project using MAX7456. My problem is the visualization of the input signal at VOUT, I can see the OSD characters but the background is just gray color.
I´ve read the MAX´s manual many times and I can´t find a solution.

I´m working in 16bit operation mode, NTSC input signal, external SYNC mode and the chip is PIC16F877

This is the registers configuration.

VMO (00H)= 00101000 ; NTSC, EXTERNAL SYNC, OSD ENABLE

MV1 (01H)= 01000111 ; IS REGISTER´S DEFAULT, BIT 7 CONTROLS BACKGROUND MODE

DMM (04H)= 00000000 ; DEFAULT, 16 BIT OPERATION MODE, BACKGROUND PIXELS AS THE VIDEO INPUT.

Can anyone help me???....
Guest








PostPosted: Tue May 12, 2009 3:32 pm     Reply with quote

Do you have an input video signal? If no video input i think the background is gray.
juanf5426
Guest







PostPosted: Tue May 12, 2009 9:14 pm     Reply with quote

Anonymous wrote:
Do you have an input video signal? If no video input i think the background is gray.


of course!!!... My input device is a Panasonic CCTV Camera, model WV-CP220. I also use a DVD player but I´m not sure about if it works for this application.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group