CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sat Dec 15, 2018 3:53 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu May 29, 2014 8:23 am 
Offline

Joined: Thu Feb 20, 2014 8:17 pm
Posts: 11
Hello everybody,

I need some help! I'm preparing library for I2C PCF8591 (A/D and D/A converter). It doesn't work....

Data sheet: PCF8591

I think the problem might be writing the control byte...

Lib, device description and project are attached to this post.

Does anyone have any suggestions or finds an error?

BR
Kdebu

Attachment:
PCF8591.zip

Attachment:
PCF8591.rar


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Fri May 30, 2014 11:56 am 
Offline

Joined: Thu Feb 20, 2014 8:17 pm
Posts: 11
Nobody any suggestions?


Top
   
PostPosted: Sat May 31, 2014 9:46 am 
Offline

Joined: Fri Apr 18, 2014 5:36 pm
Posts: 70
Hi,

You are writing 00 into Control register after init. I think that you have to enable analog output (bit 7 in control register), so you have to write:
Code:
write8(control, 16#80); // Control Byte


Device address 4F is ok if you have A0,A1,A2 connected to Vdd. Please check this.

Because you only set channel number in control register to 00, you can only read AIN0.

I hope this will help.
Please report the result.

BR
Zdenko.


Top
   
PostPosted: Sat May 31, 2014 11:07 am 
Offline

Joined: Thu Feb 20, 2014 8:17 pm
Posts: 11
Hi Zdenko,

To enable the DAC i have to write 0x40 (0100 0000) into the control register.

Reading AIN0: 0x00 (or 0x40 with enabled DAC) - single ended input
Reading AIN1: 0x01 (or 0x41 with enabled DAC) - single ended input
Reading AIN2: 0x02 (or 0x42 with enabled DAC) - single ended input
Reading AIN3: 0x03 (or 0x43 with enabled DAC) - single ended input

The device address 0x4F must be correct. A0, A1 and A2 are connected to Vdd. I checked this also with i2c-tools.

Reading the ADC-inputs and writing into the DAC-register still does not work correctly. The read ADC-values and the DAC-output voltage (measured with a multimeter) are not correct.

I checked the function of my board with a c- and python-script. The PCF8591 worked correctly... So it must be a "CODESYS-problem".

BR
kdebu


Top
   
PostPosted: Sat May 31, 2014 11:25 am 
Offline

Joined: Fri Apr 18, 2014 5:36 pm
Posts: 70
Hi Kdebu,

yes, you are right. To enable DAC you have to write 0x40 into control register. I missed one bit.

But in your case, you are not writing this value in the device control register nowhere. Please make sure that write value to control register will be performed before reading/writing DAC/ADCs.

BR
Zdenko.


Top
   
PostPosted: Fri Jun 06, 2014 7:33 pm 
Offline

Joined: Thu Feb 20, 2014 8:17 pm
Posts: 11
Hello Zdenko,

i updated my project (see attached file(s)) but it still doesn't work... :cry:

I think the program logic should be correct... Please take a look again.

BR
kdebu


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Sat Jun 07, 2014 5:55 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3018
Hi,

we need more description, what exactly does not work,
any screenshot of debugging it, would be great.

BR
Edwin


Top
   
PostPosted: Fri Sep 25, 2015 5:34 pm 
Offline

Joined: Mon Sep 14, 2015 9:57 am
Posts: 4
I have the same problem i cant get PCF8591 to send a signal from my potentiometer

im useing this code in a ST POU

PROGRAM PCF8591_Test
VAR
Potentiometer : LREAL;
END_VAR

PCF8591.CNF := 16#40;
Potentiometer := BYTE_TO_LREAL(PCF8591.IN_A);

//Christos


Top
   
PostPosted: Tue Sep 29, 2015 9:31 am 
Offline

Joined: Mon Sep 14, 2015 9:57 am
Posts: 4
I just wrote a program in python and tried out the PCF8591 with a potentiometer connected to the first port and the program ran nicely everything worked. So i know now the ic works 100%. But i can still not get it to work in codesys Ive added an i2c master and under that the device PCF8591 wich i downloaded from the forum. Part of the problem is i cant understand the functionblock 100% as I understand it know you want me to send the init byte to PCF8591.CNF and that will activate the ports to be able to recive data. Right now im running and ST program that looks like this:

PCF8591.CNF := 16#48;

Potentiometer := BYTE_TO_LREAL(PCF8591.IN_A);
Potentiometer1 := BYTE_TO_LREAL(PCF8591.IN_B);
Potentiometer2 := BYTE_TO_LREAL(PCF8591.IN_C);
Potentiometer2 := BYTE_TO_LREAL(PCF8591.IN_D);

Im out of ideas, so i hope someone on the forum have any.

//Christos


Top
   
PostPosted: Tue Sep 29, 2015 2:17 pm 
Offline

Joined: Mon Sep 14, 2015 9:57 am
Posts: 4
I solved it forgot to write an address on my PCF8591 device.

Address the device you add under the I2C master with the value 16#48

and just make an ST POU and write:

input0 := BYTE_TO_REAL (PCF8591.IN_A);

and you should get a value on IN_A if you connected something to the first port on the IC.

//Christos


Top
   
PostPosted: Tue Nov 27, 2018 11:14 pm 
Offline

Joined: Tue Oct 31, 2017 7:04 pm
Posts: 4
Ok im only can read from one input like

PCF8591.in0 or 1 or 2 or 3 switching to PCF8591.control :=16#40/41/42/43

How to read all ?


Top
   
PostPosted: Wed Nov 28, 2018 9:12 pm 
Offline

Joined: Tue Oct 31, 2017 7:04 pm
Posts: 4
Working all is on Forum Repo ;]
viewtopic.php?f=23&t=5872&p=10868#p11015
The End.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 4 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited