basically i dont want to control the CS pin manually or use bit wise operators.
i figured out that one way of doing so will be to use the MCP 4822 header file available in the arduino library.
unfortunately i dont have the code that uses this header file. so if any one can help me with the code to op 0v and 5v from the DAC using this header file i would be very pleased.
If you have a library with a .h file the first thing to do is read the .h file to see what functions it provides, read any comments and then look for any examples in that library.
If its still mysterious the chances are the library is poorly documented - find another one if your can - or
write your own. This is a great exercise, all the messy low-level code in encapsulated in the library
for any other sketches to use.
still looking for answers on how to code MCP 4822. i just want some basic stuff to get started like code to output 1v and 5v from the dac. there is little provided in terms of examples in the IDE so any inputs will be appreciated.
cheers,
marrc
1. Check that you have connected the MCP4822 DAC as per following diagram (Fig-1).
Figure-1:
2. Connect a DVM in "DC Voltage Mode" between VOUTA and GND.
3. Upload the following sketch (taken from the example of IDE after including the MCP48xx.h Library in the IDE). The sketch has been compiled in my system but could not run as I don't own the chip.
#include <MCP48xx.h>
MCP4822 dac(10);
// We define an int variable to store the voltage in mV so 100mV = 0.1V
int voltage = 100;
void setup()
{
// We call the init() method to initialize the instance
dac.init();
// The channels are turned off at startup so we need to turn the channel we need on
dac.turnOnChannelA();
dac.turnOnChannelB();
// We configure the channels in High gain
// It is also the default value so it is not really needed
dac.setGainA(MCP4822::High);
dac.setGainB(MCP4822::High);
}
// We loop from 100mV to 2000mV for channel A and 4000mV for channel B
void loop()
{
// We set channel A to output 500mV
dac.setVoltageA(voltage);
// We set channel B to output 1000mV
dac.setVoltageB(voltage * 2);
// We send the command to the MCP4822
// This is needed every time we make any change
dac.updateDAC();
if (voltage * 2 > 4000) {
voltage = 100;
}
voltage = voltage + 100;
delay(1000);
}
4. Check that value of the DVM reading changes by 100 mV (0.1 V) in every second. At around 4V, the DVM will preset to 100 mV.
5. If Step-4 works, then connect the DVM across VOUTB and GND to check that Ch-B is working with an increase of 200 mV in every second. At around 4V, the DVM will preset to 100 mV.
[quote 5. If Step-4 works, then connect the DVM across VOUTB and GND to check that Ch-B is working with an increase of 200 mV in every second. At around 4V, the DVM will preset to 100 mV.
[/quote]
GolamMustafa! you are delighting as ever. one more thing can i use A6/A7 pins as CS? i know they r i/p pins but i have used up all other pins for PWM.
cheers,
marrc
GolamMostafa:
NANO does not allow the DIO operation of A6/A7; but, MEGA allows. You can use 74LS259 (serial latch) to expand IO lines.
74LS series logic is obsolete, LS I/O has different logic levels and input/output electrical characteristics that make it a bad choice for hobby use (or almost any use, really). The only reason we used it back in 1975, was that that CMOS wasn't fast enough yet.
We have these 74LS series in our local market to support the design of SAP computers in the college labs. I have suggested the OP to use the said non-programmable IO expander (just to get 3 extra IO lines) thinking that he might face difficulties to initialize the programmable expander like PCF8574 and similar.
I haven't read the data sheet, but if the SPI lines are not shared, the CS line on the peripheral can often just be permanently grounded or connected to Vdd (whichever makes it active). That would save a pin.
Electronics hobby shops here also carry a little bit of 74LS, but mostly they carry 74HC. HC parts are much more beginner friendly.
aarg:
I haven't read the data sheet, but if the SPI lines are not shared, the CS line on the peripheral can often just be permanently grounded or connected to Vdd (whichever makes it active). That would save a pin.
The CS/-pin of the DAC (MCP4822) can not be tied down to LOW as the method dac.updateDAC(); of the Library makes a transition (HIGH-LOW-HIGH) of the SS/-line of the Master to latch the data from input buffer into the actual register of the DAC.
Okay, I'll bite. What is a SAP computer?
SAP-1, 2, 3 (Simple As Possible) are three CPUs that are developed using "discrete TTL ICs" as course works in Digital Electronics Lab based on some American Text/Cook Books.
GolamMostafa:
The CS/-pin of the DAC (MCP4822) can not be tied down to LOW as the method dac.updateDAC(); of the Library makes a transition (HIGH-LOW-HIGH) of the SS/-line of the Master to latch the data from input buffer into the actual register of the DAC.
I don't think it can be connected to a pin expansion device either, for the same reason.