I2C and DAC advice please

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
User avatar
rene
Posts: 56
Joined: Sun Sep 13, 2009 11:27 am
Location: Dordrecht - Nederland
Has thanked: 5 times
Been thanked: 2 times

I2C and DAC advice please

Post by rene »

Hi,

I have to heat and cool water treatment equipment and I'm planning to build a circuit using a PIC controller :P

Components that I would like to use:

16F877a and 18F4520 for me the most common Proccesor
I2C bus
Temperature sensor (LM75)
2 x Analog output for heating. ½ (DAC7573)
2x Analog output for cooling. ½ (DAC7573)
USB Comunication ...

I would like to know if someone with more experience with I2C / Flowcode and DACs, think this is a good choice.
Maybe it should be done differently and better with other compenents.
I have not much experience with I2C and flowcode4.
An example of such a DAC or other type would be helpful.

Ideas how things should be, are very welcome to. :idea:

Thanks

Rene

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I2C and DAC advice please

Post by Benj »

Hello Rene,

I would change the target PIC processor to a 18F2455 or a 18F4455 to allow for the USB communications.

This chip has I2C master functionality to allow your I2C devices to use the I2C hardware.

The Flowcode v4 I2C help file has a breakdown of how I2C communications take place so this could be a good starting point for you. We also have I2C examples as part of the main v4 examples download.

Maybe an ECIO would suit your needs as this contains all the hardware for the chip to run, predefined configuration and clock values in Flowcode and includes the hardware for the USB connection. You could then simply use veroboard to create your circuitry or use a EB061 ECIO expansion board and then use E-block style connections to your external devices.

User avatar
rene
Posts: 56
Joined: Sun Sep 13, 2009 11:27 am
Location: Dordrecht - Nederland
Has thanked: 5 times
Been thanked: 2 times

Re: I2C and DAC advice please

Post by rene »

Benj,

Thanks for your answer ...
I will go for the ECIO .. which are very easy to use, and I've had some experience with them.

At the monent I try to use an LM75, but.......
I have no idea, how to join the two received bytes togheter with flowcode4, and get a useful value..on a display...
The added code is a working c-code as it may work ..
I do not know how to do this in flowcode?

Do you or someone have any idea?
Maybe someone have a litle example how to use this LM75 to start with?

Code: Select all

    // Two reveived bytes of LM75
    temp_H=tptr[0];           // High bits
    temp_L=tptr[1];           // Low bits

    // Compute Centigrade
    cvalue=(temp_H<<8)|temp_L;
    cent_buf[0]=' ';
    if(cvalue&0x80==1)
    {
       cvalue=~cvalue+1;         // Calculate Base Complement
       cent_buf[0]='-';
    }
    cvalue=cvalue>>5;
    cvalue=cvalue * 1.25;
    cent_buf[1]=cvalue/100+48;
    cent_buf[2]=(cvalue/10)%10+48;
    cent_buf[3]='.';
    cent_buf[4]=cvalue%10+48;
    cent_buf[5]=' ';
	cent_buf[6]='\0';

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I2C and DAC advice please

Post by Benj »

Hello,

This is taken from the I2C component help file.

A typical I²C device (24 series EEPROM)

Here is how to send and receive data to and from a typical I²C device.

Sending Data

Output a start condition //Starts the device listening to the I²C bus.
Transmit the External Device address with the LSB cleared. //Enables the device and sets to write mode. address = 0x90 for LM75 with add bits all 0.
Transmit the Internal address. //Sets the address to start writing data to.
Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached
....
Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached
Output a stop condition //Stops the device listening to the I²C bus.

Alternatively use the Send_Byte_Transaction macro.

Receiving Data

Output a start condition //Starts the device listening to the I²C bus.
Transmit the External Device address with the LSB cleared. //Enables the device and sets to write mode. address = 0x90 for LM75 with add bits all 0.
Transmit the Internal address. //Sets the address to start reading data from.
Output a restart condition //Restarts the device listening to the I²C bus.
Transmit the External Device address with the LSB set. //Enables the device and sets to read mode. address = 0x91 for LM75 with add bits all 0.
Receive a byte of data with last byte 0. //Device will send data and increment internal address until page limit is reached
....
Receive a byte of data with last byte 1. //Device will send data.
Output a stop condition //Stops the device listening to the I²C bus.

Alternatively use the Receive_Byte_Transaction macro.

To combine bytes in Flowcode you would simply use a calulcation icon to store two byte variables into an int variable.

intvar = bytelow | ( bytehigh << 8 )

Post Reply