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 CCS Technical Support

About MAX528/529 driver

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



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

View user's profile Send private message Visit poster's website

About MAX528/529 driver
PostPosted: Tue Jul 10, 2012 12:13 am     Reply with quote

Hi,
I wonder if someone has written a driver for the MAX528 Octal DAC.

cheers
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jul 11, 2012 7:15 pm     Reply with quote

Just printout the datasheet, google 'max528 CCS C code'...see what comes up, try your hand at cutting the code. Also check similar 'family' type parts, say a quad DAC or dual DAC, it may be very, very similar.
Drivers are not magical...just common sense, line by line coding.
Take a stab at it, upload here so we can see how you're doing so we can 'fill in the blanks'.
I don't cut code without real parts on a breadboard to test as it's the ONLY way to verify the code does work.
Most datasheets will tell you 99% of what you have to know to get the product up and running, the other 1% deals with board layout, wiring, EMI,e tc.

hth
jay
scanan



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

View user's profile Send private message Visit poster's website

PostPosted: Wed Mar 26, 2014 9:15 am     Reply with quote

Code:
void max528(unsigned int8 chan,unsigned int8 value)
{
unsigned int8 data;
#bit dataMSBit=data.7;

/////////// zero all DAC output
output_high(PIN_D7);
output_low(PIN_D7);
for(m=0;m<25;m++){};
output_low(PIN_C3);

data=chan;

   for(jj=0;jj<8;jj++){
      output_low(PIN_C3);
      output_bit(PIN_C4,dataMSBit);
      for(m=0;m<25;m++){};
      output_high(PIN_C3);
      for(m=0;m<25;m++){};
     
      data<<=1;
   }

data=value;
   for(jj=0;jj<8;jj++){
      output_low(PIN_C3);
      output_bit(PIN_C4,dataMSBit);
      for(m=0;m<25;m++){};
      output_high(PIN_C3);
      for(m=0;m<25;m++){};
     
      data<<=1;
   }
output_high(PIN_D7);
output_low(PIN_C3);
}

_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 26, 2014 5:06 pm     Reply with quote

This is an SPI chip. You should be using either setup_spi() and spi_write()
or the other method, with #use spi() and spi_xfer().
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu Mar 27, 2014 5:37 am     Reply with quote

No guarantees, haven't got this chip to try.
However attached is a demo program and a concept driver:

main.c
Code:

#include <18F4520.h>  //change to suit your chip
#device ADC=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES BROWNOUT                 //Brownout enabled
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled

#use delay(crystal=10000000)
#use rs232(baud=9600,parity=N,UART1,bits=8,errors)

#define SSP_BAUD 2000000
//define this to suit the hardware Max 4.7Mhz with 1KR pull-up. See data sheet

//define the pins used for the SSP connection to max528/9
#define SSP_1
//Define this to use hardware SSP. SSP_1 or SSP_2.
//To use software SSP
//REM this out, and define pin numbers below
#define SSP_DO PIN_xx
#define SSP_DI PIN_xx
#define SSP_CLK PIN_xx

//define the CS pin here
#define SSP_CS PIN_A0

#include <max529.h> //include the driver

void main()
{
   int16 dac_val;
   setup_buffers(BUFF_01 | BUFF_23 | BUFF_45 | BUFF_67 | BUFF_FULL_0TO3 | BUFF_FULL_4TO7);
   //enable full buffering on all channels - change as needed
   while(TRUE)
   {
      for (dac_val=0;dac_val<256;dac_val++)
      {
         //count through all possible values (sawtooth waveform)
         //output inverse waveform on channels 4 to 7, and normal waveform on 0 to 3
         write_dac(DAC0 | DAC1 | DAC2 | DAC3, dac_val); //writing 4 channels at once.
         write_dac(DAC4 | DAC5 | DAC6 | DAC7, 255-dac_val);
         
         //delay for a moment
         delay_us(10);
      }
   }
}


max529.h
Code:

//Driver for Max528/529 DAC
//Setup the SPI port - uses settings made in the main.

#ifdef SSP_1
#USE SPI (MASTER, SPI1, MODE=3, BITS=8, BAUD=SSP_BAUD, BITS=16, STREAM=MAX529)
#else
  #ifdef SSP_2
    #USE SPI (MASTER, SPI2, MODE=3, BITS=8, BAUD=SSP_BAUD, BITS=16, STREAM=MAX529)
  #else
    #USE SPI (MASTER, DI=SSP_DI, DO=SSP_DO, CLK=SSP_CLK, MODE=3, BITS=8, BAUD=SSP_BAUD, BITS=16, STREAM=MAX529)
  #endif
#endif
//Port will tryt to use the highest rate it can below 'SSP_BAUD'. For hardware
//may get close, but software will be slower....

//defines for buffer programming
#define BUFF_01 0x20
#define BUFF_23 0x10
#define BUFF_45 0x4
#define BUFF_67 0x2 //buffer enables for channel pairs
#define BUFF_FULL_0TO3 0x8
#define BUFF_FULL_4TO7 0x1 //Enable full buffer as opposed to half buffer

//defines for DAC selection
#define DAC0 0x1
#define DAC1 0x2
#define DAC2 0x4
#define DAC3 0x8
#define DAC4 0x10
#define DAC5 0X20
#define DAC6 0x40
#define DAC7 0x80

void setup_buffers(unsigned int8 bmask)
{
   unsigned int16 templ;
   templ = bmask | 0x80;
   output_high(SSP_CS); //ensure CS starts high
   delay_cycles(1);
   output_low(SSP_CS);
   templ = spi_xfer(MAX529, templ, 16);
   //reading the result forces transaction to complete, even if using hardware
   output_high(SSP_CS);
}

void write_dac(unsigned int8 channels, unsigned int8 value)
{
   //set one or more DAC channels to 'value'
   int16 result;
   output_low(SSP_CS); //select chip
   result = spi_xfer(MAX529, make16(channels,value), 16);
   output_high(SSP_CS);
}


Completely untried, but should be pretty close. Allows you to program one or more channels at a time, and configure the buffer configuration. Demo outputs a sawtooth on four channels, and inverse sawtooth on the other four channels.

Best Wishes
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