Hi Andy -
I had my DS1050-025 running, for a while, but now I can only get about 3 to 10 cycles out it. I have gone back over changes I have made, but nothing seems to help. Here is the test code I am currently trying. I open the DS1050 i2c, using address 0x28 ( as shown by i2cdetect on my Raspberry Pi, which this hardware is on). Then I write 0x50 (set PMW command) followed by the data (shown as 0x10h - which should be 50% PWM).
I close the file descriptor, call the second function, where I open the DS1050 in i2c again, writing 0x50 (set PWM command) followed by the data 0x20 as shown on the DS1050 data sheet. Then again close the file descriptor. I have tried combining the two functions and write 0x50, 0x10, 0x50, 0x20 and the close i2c with the same results.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "/home/dvf/glg/include/GlgApi.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h> // read/write usleep
#include <inttypes.h> // uint8_t, etc
#include <linux/i2c-dev.h> // I2C bus definitions
#include <sys/ioctl.h> //Needed for I2C port
#include "/home/dvf/glg/include/GlgApi.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
#include <termios.h>
#include <stdio.h>
#include <sys/types.h> // open
#include <sys/stat.h> // open
#include <fcntl.h> // open
#include <unistd.h> // read/write usleep
#include <stdlib.h> // exit
#include <inttypes.h> // uint8_t, etc
#include <linux/i2c-dev.h> // I2C bus definitions
#include <sys/ioctl.h>
#include "PWM.h"
int PWM_Write2(void);
int fd_pwm, fd;
int16_t val;
uint8_t writeBuf[5], readBuf[2];
void main(void)
{
// open device on /dev/i2c-1
if ((fd_pwm = open("/dev/i2c-1", O_RDWR)) < 0)
{
printf("Error: Couldn't open I2C device\n");
return;
}
// connect to ads1115 as i2c slave
if (ioctl(fd_pwm, I2C_SLAVE, PWM_Addrs) < 0)
{
printf("Error: Couldn't find device on address!\n");
return;
}
// set config register and start conversion
writeBuf[0] = SetPWM; // config register is 1
writeBuf[1] = 0x10;
// Set newm PWM duty
if (write(fd_pwm, writeBuf, 4) != 4)
{
printf("Can't write to register 1\n");
return;
}
close(fd_pwm);
PWM_Write2();
while(1)
{
;
}
}
int PWM_Write2(void)
{
// open device on /dev/i2c-1
if ((fd = open("/dev/i2c-1", O_RDWR)) < 0) {
printf("Error: Couldn't open I2C device\n");
return 1;
}
printf("fd = %d\n",fd);
// connect to ads1115 as i2c slave
if (ioctl(fd, I2C_SLAVE, PWM_Addrs) < 0) {
printf("Error: Couldn't find device on address!\n");
return 1;
}
// set config register and start conversion
writeBuf[0] = SetPWM; // config register is 1
writeBuf[1] = 0x20;
// Set newm PWM duty
if (write(fd, writeBuf, 2) != 2)
{
printf("Can't write to register 1\n");
return 1;
}
close(fd);
}

Hope you can help,
David
YouTube "Sailing Solo at 70"



