View previous topic :: View next topic |
Author |
Message |
ali6094
Joined: 31 Jan 2007 Posts: 18
|
MAX517 !! error |
Posted: Sun Apr 15, 2007 10:51 pm |
|
|
hello
i am using PIC16F877A and max517 .. the purpose it to generate different analogue signals ... i have designed the circuit and the code is down it was taken from the CCS code library but no out puts -- circuit is like dead the code is as follow...
Code: |
#include <16F877A.h>
#device ICD=TRUE
#device ADC=10 // Use 10bits ADC
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000) // 20Mhz Crystal is Used
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <MAX517.c> //Call for MAX517.c function
#define TRIGGER PIN_E0
#define SAMPLE1 PIN_C4
#define SAMPLE2 PIN_D2
#define SAMPLE3 PIN_C5
int1 data_end = 0;
void main(void)
{
set_tris_d( 0xff );
set_tris_c( 0xbf );
set_tris_e( 0xff );
Begin:
if (TRIGGER)
{
data_end = 0 ;
}
else
goto Begin ;
while(1)
{
if (!TRIGGER && !data_end)
{
if (!SAMPLE1)
{
output_high(PIN_A0); //LED ON
write_dac(0xFF); //DAC output 5V
delay_ms(5000); //Delay
output_low(PIN_A0); //LED OFF
write_dac(0x00); //DAC output 0V
delay_ms(5000); //Delay
data_end = 1 ;
}
else
if (!SAMPLE2)
{
output_high(PIN_A0); //LED ON
write_dac(0xFF); //DAC output 5V
delay_ms(5000); //Delay
output_low(PIN_A0); //LED OFF
write_dac(0x00); //DAC output 0V
delay_ms(5000); //Delay
data_end = 1 ;
}
else
if (!SAMPLE3)
{
output_high(PIN_A0); //LED ON
write_dac(0xFF); //DAC output 5V
delay_ms(5000); //Delay
output_low(PIN_A0); //LED OFF
write_dac(0x00); //DAC output 0V
delay_ms(5000); //Delay
data_end = 1 ;
}
}
else
goto Begin ;
}
}
|
here is the circuit
http://www.mediafire.com/?9w2qmm4oihy
[/list] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 16, 2007 11:56 am |
|
|
Start with a small test program and use the CCS driver instead of
something you found in the Code Library. Here's the driver location:
Quote: | c:\Program Files\Picc\Drivers\MAX517.c |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Apr 16, 2007 12:38 pm |
|
|
This ain't going to work, change this line to Code: | if (input(TRIGGER)) |
Same note applies to SAMPE1, SAMPLE2 and SAMPLE3.
The use of the goto statement in the C-language is discouraged as it often leads to difficult to maintain code. More elegant solutions are possible, for example you can replace Code: | Begin:
if (input(TRIGGER))
{
data_end = 0 ;
}
else
goto Begin ;
| by Code: | while (input(TRIGGER))
{
// Do nothing while waiting
}
data_end = 0; // note that this line is not required, you already initialized the global variable to zero. |
Code: | set_tris_d( 0xff );
set_tris_c( 0xbf );
set_tris_e( 0xff ); |
By default the CCS compiler is using 'standard I/O' in which the compiler sets the right TRIS values for you. This means that the lines above are not required and can change compiler defined values. |
|
|
ali6094
Joined: 31 Jan 2007 Posts: 18
|
no out put |
Posted: Sun Apr 22, 2007 4:55 pm |
|
|
Well i am doing alot of things but nothing is really working can u plz check my circuit diagram is it fine i dont know whats wrong i am getting my LED fine lit but no out puts i.e Zero volts.... can any body tell me why.....
[/img]
Push switch for input is a selector switch to choose between the POT or DAC but DAC is giving no output just for start
my code is Code: |
#include <16F877A.h>
#device ICD=TRUE
#device ADC=10 // Use 10bits ADC
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000) // 2016Mhz Crystal is Used
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <MAX517.c> //Call for MAX517.c function
#define TRIGGER PIN_E0
#define SAMPLE1 PIN_C4
#define SAMPLE2 PIN_D2
#define SAMPLE3 PIN_C5
void main(void)
{
while(1)
{
output_high(PIN_A0); //LED ON
write_dac(0xFF); //DAC output 5V
delay_ms(5000); //Delay
delay_ms(5000); //Delay
delay_ms(5000); //Delay
write_dac(0xF0); //DAC output 5V
write_dac(0xF0);
delay_ms(5000);
delay_ms(5000);
delay_ms(5000);
output_low(PIN_A0); //LED OFF
write_dac(0x00); //DAC output 0V
delay_ms(5000); //Delay
}
} |
Can there be any proble, with the address of the device eith me the routine is Code: |
void write_dac(int data_byte) {
i2c_start();
[b]i2c_write(0x5e); [/b] // Send the address of the device
i2c_write(0);
i2c_write(data_byte); // Send the data to the device
i2c_stop();
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 22, 2007 7:03 pm |
|
|
The slave address of 0x5E is not correct for your hardware connections.
For your hardware, it's actually 0x58. You need to edit the write_dac()
function and change it.
Also, your schematic shows capacitor C21 is installed backwards.
The '+' side should go to Vdd. If you install a polarized capacitor
backwards, it can blow, or it can leak fluid, or it can slowly eat
through the membrane and turn into a resistor. All of these are bad.
Fix the schematic and replace the capacitor with a new one. |
|
|
ali6094
Joined: 31 Jan 2007 Posts: 18
|
|
Posted: Mon Apr 23, 2007 3:24 pm |
|
|
Thanx PCM programmer
those were the real two problems and now i have fixed both of them and i am getting the desired out put ... u have always been a sourse of great help and i would like to show my gratitude for your support
Ali
|
|
|
|