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 support@ccsinfo.com

Serial data setup for dual channel D/A

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



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

Serial data setup for dual channel D/A
PostPosted: Thu Apr 13, 2006 2:32 am     Reply with quote

I am attempting to load a Maxim Dual channel D/A (MAX5523). I have successfully done just one serial word and am now moving on to do all three words that will set the reference voltage and the two D/A registers.
On the scope I see the three chip selects performing correctly. However, the clocks and data are all now only about 500 mV rather than the 3V as they should be. Additionally the time before the next bust of three chip selects is 120 msec, whereas when only a single word is sent they repeat one after the other??? Also the print statement, to let me know if I got through the loop does not show up on the debugger monitor. I checked the three pins going to the D/A using a simple pin hi, pin lo test and they do achieve the full three volts. A form of this has also worked successfully on the 5V development board. I have added the delays upon recommendation from Ttelma on a previous question. Once I get this working I feel that I could eliminate the delays by utilizing the fast_io function. Also I will only write this seqence occasionally if need be for calibration reasons. The looping is only for my checkout of the code and electronics.

Code:

#include <16F877A.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=5000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use rs232(debugger)
#define maxsel PIN_B1   // Low activates the D/A
#define maxclk PIN_B4   // D/A clock
#define maxdat PIN_B2   // D/A data

   main()
   {
      long vref,offset,const_ref;
      int j=0;
      int i=0;

         output_high(maxsel);    // D/A chip select disabled

         while(1)
         {
         output_low(maxsel);     // D/A chip select enabled
         for (i=0; i<=15; i++)   // write the reference word
         {
         vref=0xd800; // D800 hex  1101 1000 0000 0000
         output_bit(maxdat,shift_left(&vref,2,0));
         delay_us(2);
         output_high(maxclk);
         delay_us(2);
         output_low(maxclk);
         }
         delay_us(2);
         output_high(maxsel);    // write the value clocked out
         delay_us(2);
         output_low(maxsel);     // D/A chip select enabled
         delay_us(2);
         for (i=0; i<=15; i++)   // write the offset word
         {
         offset=0x2698;  //0010 0110 1001 1000
         output_bit(maxdat,shift_left(&offset,2,0));
         delay_us(2);
         output_high(maxclk);
         delay_us(2);
         output_low(maxclk);
         }
         delay_us(2);
         output_high(maxsel);   
         delay_us(2);
         output_low(maxsel);     // D/A chip select enabled
         delay_us(2);
         for (i=0; i<=15; i++)   // write the reference word
         {
         const_ref=0x9D34;    //1001 1101 0011 0100
         output_bit(maxdat,shift_left(&const_ref,2,0));
         delay_us(2);
         output_high(maxclk);
         delay_us(2);
         output_low(maxclk);
         }
         delay_us(5);
         output_high(maxsel);    // write the value clocked out
         printf("Through the loop ");           
         }
      }

JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

Ooops
PostPosted: Thu Apr 13, 2006 10:14 am     Reply with quote

I see that I put the data word inside the if() loops. However, all of the other problems are still in effect.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 13, 2006 11:03 am     Reply with quote

Before you do anything else, disable the Low Voltage Programming mode.
Add the parameter shown in bold below.
Quote:
#fuses HS,NOWDT,NOPROTECT, NOLVP


There are three very important "essentials" that you should do
in every CCS program.

1. Add NOLVP to the #fuses statement.

This prevents the PIC from locking up if you take the PGM pin high.
The PGM pin is typically pin B3 or B5. This assumes that your PIC
supports LVP mode and has a PGM pin - not all of them do.


2. Add ERRORS to your #uses rs232() statement.

This prevents the UART from locking up if you get a receive
overrun error. This parameter only works with a hardware UART.


3. Add a while(1) statement at the end of main().

This prevents the program from executing a hidden SLEEP instruction
that the compiler inserts at the end of main(). If that instruction
is executed, the PIC will stop running. Any characters that were
hardware UART's transmit buffer will not be sent.
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

PostPosted: Thu Apr 13, 2006 11:30 am     Reply with quote

Since I am running this project from 3V, don't I need to exclude that fuse?
Pin B3 is devoted only to programming and the MCLR pin is isolated with a resistor and a Schotky diode.
I have had some problems with the computer's USB port going to the ICD and have had to remove the cable and let it re-initialize.

Jim
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 13, 2006 11:36 am     Reply with quote

1. Are you using a Low Voltage Programmer ?
If not, then you need the NOLVP fuse.

2. Are you using the "LF" version of the 16F877A ?
You need to use that version if you're running at 3 volts.

3. Is the diode in series with the MCLR resistor ?
You don't need a diode, provided that you use a 10K resistor
on MCLR. (Use 47K with CCS ICD).
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

PostPosted: Thu Apr 13, 2006 12:49 pm     Reply with quote

I am using the CCS ICD-U40. The chip is the "LF" version. The diode is connected in series with the 47K resistor going to the MCLR* pin. I thought the diode would protect all of the other LV devices on the board.
I was assured by CCS that this programmer would interface with the 3V logic OK.
I have had some peculiar issues with the ICD. It always erases the EEPROM on the 3V board, even though the setting is for no erase but it works OK on the 5V development board. Depending on whether or not I run ICD from within the CCS compiler, under the "tools" menu and when I run it from the ICD shortcut in the Start, Programs" menus in WinXP. I sometimes get different results.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 13, 2006 1:17 pm     Reply with quote

Quote:
I am using the CCS ICD-U40

The ICDU40 is a high voltage programmer. Therefore, you should
use the NOLVP fuse setting.

Quote:

The diode is connected in series with the 47K resistor going to the MCLR*
pin. I thought the diode would protect all of the other LV devices on the
board.

Assuming that the circuit has Vdd (+3v in your case) applied to it
while the Vpp is applied, the diode shouldn't be necessary.
With a 47K resistor, you'll have +13v on one side, and +3v on the other.
That's a 10v drop across the resistor. The current through it is 10v/47K
which is 0.2 ma. The voltage regulator on the Vdd side will easily be
able to maintain regulation of the +3v, even though 0.2ma is being
sourced into the Vdd supply through the resistor.

The only way there would be a problem is if Vpp were turned on
without the target board being powered. But I don't think that
ever happens.

Go to this CCS page and scroll down to the circuit diagram.
They don't show a diode.
http://www.ccsinfo.com/faq.php?page=icd_connection

If you use a diode, you block the path for any positive ESD voltage
to bleed off into the Vdd power supply. If you use a silicon diode
(instead of a Schottky), then you reduce the margin of the MCLR
voltage above the spec'ed minimum Vih value.
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

Up and running except for..........
PostPosted: Sat Apr 15, 2006 1:54 pm     Reply with quote

Questions?

First of all thanks again for the help.

1. Could you expand on your comment about using "error" in the #use RS232(debugger) line. Could not find any reference to this.

2. Should one be able to interchange the SHIFT_LEFT and ROTATE_LEFT, i.e.
output_bit(maxdat, shift_left(&vref,2,0));
output_bit(maxdat, rotate_left(&vref,2));
I am not having success with rotate_left function.

3. If vref, in 2 above, is only an int8, would one use a 1 or a 2 if there are 16 shifts and vref needs to be the MSB? The compiler manual implies that a 1 is the correct answer. I changed vref to int16 for it to work properly but would like to keep it at int8. Less code required when reading from the eeprom.

4. When running from the development board (+5V) the debugger monitor works pretty good. (Just little glitches now and then.) But when operating with the real hardware (+3V) there is no response on the monitor nor does the "No erase the eeprom" work correctly. Have searched for help with this on this board and the CCSC website with no results.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 16, 2006 3:58 pm     Reply with quote

Quote:
1. Could you expand on your comment about using "error" in the #use RS232(debugger) line. Could not find any reference to this.
It doesn't apply to the debugger output.


Quote:
I am not having success with rotate_left function.
If vref, in 2 above, is only an int8, would one use a 1 or a 2 if there
are 16 shifts and vref needs to be the MSB? The compiler manual
implies that a 1 is the correct answer.

An int8 only has 8 bits. If you do more than 7 shift-left operations,
you will shift all bits out of the int8 variable. The variable would then
become 0 (Assuming the "shift in" value is specified as 0).
If this answer doesn't help, then post a very small but complete test
program that shows the problem. Post all variable declarations.



Quote:
When running from the development board (+5V) the debugger monitor works pretty good. (Just little glitches now and then.) But when operating with the real hardware (+3V) there is no response on the monitor

I don't have the CCS ICD so I can't really help. My advice is to search
the Programmer/Debugger forum for hints. If that doesn't work, then
call CCS support on the telephone (instead of emailing them).
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