How to reduce Current consumption

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I am using Atmel studio 7 for programming atmegax16d4 to control the dac ltc2621.here in atmel studio I am generating Internal 32 MHz clock.the overall current consumption is 0.025mA.i want to reduce the above current to 0.010mA.for that I have reduce the clock multiplication factor,as soon as I reduce it current consumption came down by 0.05mA when current comes down the microcontroller is not giving clock output.

kindly guide me to solve the above problem

 

here I am attaching clk generating file.

 


#include <avr/io.h>
#include "ccp.h"

/* System Clock Init */

/*
--------------------------------------------------------------------------
CLK - Clock System
--------------------------------------------------------------------------
*/

//void SysClk_Init(void)
//{
 /* Enable 32MHz OSC */
 //OSC.CTRL = OSC_RC32MEN_bm;
 
 //while (!(OSC.STATUS & OSC_RC32MRDY_bm)) {
  /* Do nothing */
 //}
// ccp_write_io((uint8_t *)&CLK.CTRL, CLK_SCLKSEL_RC32M_gc);
  
 /* Disable 2MHz OSC */
 //ccp_write_io((uint8_t *)&OSC.CTRL, (OSC.CTRL &= ~OSC_RC2MEN_bm));

 //ccp_write_io((uint8_t *)&CLK.LOCK,CLK_LOCK_bm);
//}

// With PLL
void SysClk_Init(void)
{
 //Enable 32MHz OSC
 OSC.CTRL = OSC_RC32MEN_bm;
 ccp_write_io((uint8_t *)&OSC.CTRL, (OSC.CTRL &= ~OSC_RC2MEN_bm));
 
 while (!(OSC.STATUS & OSC_RC32MRDY_bm)) {
  // Do nothing
 }
 
 // Load the PLL with Mul factor
 OSC.PLLCTRL = (OSC_PLLSRC_RC32M_gc) | 0x06;  //0x09
 // Enable PLL
 OSC.CTRL |= OSC_PLLEN_bm;
 // Wait till PLL is locked
 while (!(OSC.STATUS & OSC_PLLRDY_bm)) {
  // Do nothing
 }

 
 // Disable 2MHz OSC
 //ccp_write_io((uint8_t *)&OSC.CTRL, (OSC.CTRL &= ~OSC_RC2MEN_bm));

 ccp_write_io((uint8_t *)&CLK.CTRL, CLK_SCLKSEL_PLL_gc);
 ccp_write_io((uint8_t *)&CLK.LOCK,CLK_LOCK_bm);
}

 

microcontroller program:

/**
 * \file
 *
 * \brief Empty user application template
 *
 */
/* http://www.atmel.com/Images/Atmel-42456-Low-Power-Consumption-Techniques-for-XMEGA-XPLAINED-Kits_Application-Note_AT11487.pdf */
/* SPI clock is doubled - main1_4_3.c */
/* changes done to achieve 17Microsec - main1_4_3_2.c */
#include <asf.h>
#include <stdint.h>
#include "common.h"
#include "spi_driver.h"
#include "usart_spi_drv.h"
#include "gpio.h"

/*! \brief Number of test data bytes. */
#define SLAVE_RX_NUM_BYTES   2
#define MASTER_TX_NUM_BYTES   3

const uint16_t PROGMEM OutVoltDac1_01[256]  = {
 0X0F8,
 0X0100,
 0X0106,
 0X010E,
 0X0115,
 0X011C,
 0X0125,
 0X012B,
 0X0132,
 0X139,
 0X141,
 0X148,
 0X14F,
 0X156,
 0X15D,
 0X164,
 0X16B,
 0X172,
 0X179,
 0X180,
 0X187,
 0X18F,
 0X196,
 0X19D,
 0X1A5,
 0X1AC,
 0X1B3,
 0X1BB,
 0X1C2,
 0X1C9,
 0X1D1,
 0X1D8,
 0X1E0,
 0X1E8,
 0X1EF,
 0X1F7,
 0X1FF,
 0X207,
 0X20F,
 0X217,
 0X21F,
 0X227,
 0X22F,
 0X237,
 0X23F,
 0X247,
 0X24F,
 0X257,
 0X260,
 0X268,
 0X270,
 0X279,
 0X282,
 0X28B,
 0X293,
 0X29B,
 0X2A4,
 0X2AD,
 0X2B6,
 0X2BF,
 0X2C8,
 0X2D1,
 0X2DA,
 0X2E3,
 0X2EC,
 0X2F5,
 0X2FF,
 0X308,
 0X311,
 0X31B,
 0X324,
 0X32E,
 0X337,
 0X341,
 0X34B,
 0X354,
 0X35E,
 0X368,
 0X372,
 0X37C,
 0X386,
 0X390,
 0X39A,
 0X3A4,
 0X3AF,
 0X3B9,
 0X3C4,
 0X3CE,
 0X3D9,
 0X3E3,
 0X3EE,
 0X3F9,
 0X403,
 0X40E,
 0X419,
 0X424,
 0X42F,
 0X43A,
 0X445,
 0X451,
 0X45C,
 0X467,
 0X473,
 0X47E,
 0X48A,
 0X495,
 0X4A1,
 0X4AD,
 0X4B8,
 0X4C4,
 0X4D0,
 0X4DC,
 0X4E8,
 0X4F4,
 0X500,
 0X50C,
 0X519,
 0X525,
 0X531,
 0X53E,
 0X533,
 0X540,
 0X54D,
 0X559,
 0X566,
 0X573,
 0X57F,
 0X58C,
 0X599,
 0X5A6,
 0X5B3,
 0X5C1,
 0X5CE,
 0X5DB,
 0X5E8,
 0X5F6,
 0X604,
 0X611,
 0X61F,
 0X62D,
 0X63B,
 0X649,
 0X658,
 0X666,
 0X674,
 0X683,
 0X691,
 0X69F,
 0X6AE,
 0X6BD,
 0X6CC,
 0X6DB,
 0X6EA,
 0X6F9,
 0X709,
 0X718,
 0X728,
 0X737,
 0X747,
 0X757,
 0X766,
 0X776,
 0X786,
 0X797,
 0X7A7,
 0X7B7,
 0X7C7,
 0X7D9,
 0X7E9,
 0X7FA,
 0X80B,
 0X81B,
 0X82D,
 0X83E,
 0X84F,
 0X861,
 0X872,
 0X884,
 0X896,
 0X8A8,
 0X8BA,
 0X8CC,
 0X8DF,
 0X8F1,
 0X904,
 0X917,
 0X92A,
 0X93D,
 0X950,
 0X962,
 0X976,
 0X989,
 0X99D,
 0X9B1,
 0X9C5,
 0X9D9,
 0X9ED,
 0XA01,
 0XA15,
 0XA2A,
 0XA3E,
 0XA53,
 0XA69,
 0XA7D,
 0XA92,
 0XAA7,
 0XABD,
 0XAD3,
 0XAE8,
 0XAFF,
 0XB15,
 0XB2A,
 0XB41,
 0XB57,
 0XB6D,
 0XB84,
 0XB9B,
 0XBB2,
 0XBC9,
 0XBE0,
 0XBD7,
 0XBEF,
 0XC07,
 0XC1F,
 0XC37,
 0XC4E,
 0XC67,
 0XC7F,
 0XC98,
 0XCB0,
 0XCCA,
 0XCE2,
 0XCFC,
 0XD16,
 0XD2E,
 0XD40,
 0XD5B,
 0XD76,
 0XD91,
 0XDAC,
 0XDC7,
 0XDE3,
 0XDFF,
 0XE1B,
 0XE38,
 0XE54,
 0XE71,
 0XE8E,
 0XEAB,
 0XECE,

};

const uint16_t PROGMEM OutVoltDac1_10[256]  = {
 0X164,
 0X16A,
 0X16F,
 0X175,
 0X17A,
 0X17F,
 0X185,
 0X18B,
 0X190,
 0X196,
 0X19C,
 0X1A2,
 0X1A8,
 0X1AE,
 0X1B4,
 0X1BA,
 0X1BF,
 0X1C6,
 0X1CE,
 0X1D4,
 0X1DB,
 0X1E1,
 0X1E8,
 0X1EE,
 0X1F4,
 0X1FB,
 0X201,
 0X208,
 0X20F,
 0X215,
 0X21C,
 0X222,
 0X229,
 0X230,
 0X237,
 0X23E,
 0X245,
 0X24B,
 0X252,
 0X259,
 0X260,
 0X268,
 0X26F,
 0X276,
 0X27E,
 0X286,
 0X28D,
 0X295,
 0X29C,
 0X2A7,
 0X2AE,
 0X2B6,
 0X2BE,
 0X2C6,
 0X2CE,
 0X2D7,
 0X2DF,
 0X2E7,
 0X2EF,
 0X2F6,
 0X2FD,
 0X307,
 0X312,
 0X31F,
 0X32B,
 0X332,
 0X339,
 0X342,
 0X349,
 0X351,
 0X359,
 0X361,
 0X369,
 0X372,
 0X37A,
 0X383,
 0X38C,
 0X395,
 0X39E,
 0X3A7,
 0X3B0,
 0X3BA,
 0X3C3,
 0X3CD,
 0X3D7,
 0X3E0,
 0X3EA,
 0X3F3,
 0X3FE,
 0X408,
 0X412,
 0X41C,
 0X426,
 0X430,
 0X43A,
 0X444,
 0X44E,
 0X458,
 0X463,
 0X46D,
 0X478,
 0X482,
 0X48C,
 0X497,
 0X4A1,
 0X4AC,
 0X4B7,
 0X4C1,
 0X4CC,
 0X4D7,
 0X4E2,
 0X4ED,
 0X4F8,
 0X504,
 0X50E,
 0X51A,
 0X525,
 0X530,
 0X53C,
 0X548,
 0X553,
 0X55D,
 0X56B,
 0X576,
 0X582,
 0X58F,
 0X59B,
 0X5A6,
 0X5B3,
 0X5C0,
 0X5CC,
 0X5D8,
 0X5E5,
 0X5F1,
 0X5FE,
 0X60B,
 0X618,
 0X625,
 0X632,
 0X63F,
 0X64C,
 0X65A,
 0X667,
 0X675,
 0X683,
 0X691,
 0X69E,
 0X6AC,
 0X6BB,
 0X6C9,
 0X6D4,
 0X6E5,
 0X6F3,
 0X702,
 0X711,
 0X71F,
 0X72E,
 0X73D,
 0X74C,
 0X75B,
 0X76B,
 0X77A,
 0X789,
 0X799,
 0X7A9,
 0X7B8,
 0X7C8,
 0X7D8,
 0X7E9,
 0X7F8,
 0X809,
 0X819,
 0X82A,
 0X83A,
 0X84B,
 0X85C,
 0X86D,
 0X87F,
 0X890,
 0X8A1,
 0X8B3,
 0X8C5,
 0X8D7,
 0X8E8,
 0X8FB,
 0X90D,
 0X91F,
 0X932,
 0X944,
 0X957,
 0X96A,
 0X97D,
 0X991,
 0X9A4,
 0X9B7,
 0X9C8,
 0X9DE,
 0X9F3,
 0XA03,
 0XA1B,
 0XA2F,
 0XA44,
 0XA59,
 0XA6D,
 0XA82,
 0XA97,
 0XAAD,
 0XAC2,
 0XAD8,
 0XAEE,
 0XB04,
 0XB1A,
 0XB31,
 0XB47,
 0XB5D,
 0XB75,
 0XB8B,
 0XBA2,
 0XBBA,
 0XBD2,
 0XBE9,
 0XC02,
 0XC1A,
 0XC32,
 0XC4B,
 0XC64,
 0XC7D,
 0XC94,
 0XCAD,
 0XCC9,
 0XCE3,
 0XCFE,
 0XD15,
 0XD32,
 0XD4D,
 0XD69,
 0XD84,
 0XD9D,
 0XDBB,
 0XDD4,
 0XDF4,
 0XE10,
 0XE2D,
 0XE47,
 0XE68,
 0XE84,
 0XEA3,
 0XEC4,
 0XEE3,
 0XF06,

};

const uint16_t PROGMEM OutVoltDac2_01[256]  = {
 0X10C,
 0X114,
 0X11A,
 0X122,
 0X129,
 0X130,
 0X138,
 0X13F,
 0X146,
 0X14D,
 0X154,
 0X15B,
 0X162,
 0X169,
 0X170,
 0X177,
 0X17E,
 0X185,
 0X18C,
 0X193,
 0X19A,
 0X1A1,
 0X1A9,
 0X1B0,
 0X1B7,
 0X1BE,
 0X1C6,
 0X1CD,
 0X1D4,
 0X1DC,
 0X1E3,
 0X1EA,
 0X1F2,
 0X1FA,
 0X201,
 0X209,
 0X211,
 0X219,
 0X221,
 0X229,
 0X230,
 0X238,
 0X240,
 0X248,
 0X250,
 0X258,
 0X260,
 0X268,
 0X271,
 0X279,
 0X281,
 0X28A,
 0X293,
 0X29B,
 0X2A4,
 0X2AD,
 0X2B6,
 0X2BE,
 0X2C7,
 0X2D0,
 0X2D9,
 0X2E2,
 0X2EB,
 0X2F4,
 0X2FD,
 0X306,
 0X310,
 0X319,
 0X322,
 0X32C,
 0X335,
 0X33F,
 0X348,
 0X352,
 0X35C,
 0X365,
 0X36F,
 0X379,
 0X383,
 0X38D,
 0X397,
 0X3A1,
 0X3AB,
 0X3B5,
 0X3C0,
 0X3CA,
 0X3D4,
 0X3DF,
 0X3E9,
 0X3F4,
 0X3FF,
 0X409,
 0X414,
 0X41E,
 0X42A,
 0X434,
 0X43F,
 0X44B,
 0X455,
 0X461,
 0X46D,
 0X478,
 0X483,
 0X48E,
 0X49A,
 0X4A5,
 0X4B1,
 0X4BD,
 0X4C8,
 0X4D4,
 0X4E0,
 0X4EB,
 0X4F8,
 0X504,
 0X50F,
 0X51B,
 0X528,
 0X534,
 0X540,
 0X54D,
 0X56E,
 0X57B,
 0X588,
 0X595,
 0X5A2,
 0X5AF,
 0X5BC,
 0X5C9,
 0X5D7,
 0X5E4,
 0X5F2,
 0X5FF,
 0X60D,
 0X61B,
 0X628,
 0X636,
 0X644,
 0X652,
 0X660,
 0X66F,
 0X67D,
 0X68B,
 0X69A,
 0X6A9,
 0X6B7,
 0X6C6,
 0X6D5,
 0X6E4,
 0X6F3,
 0X702,
 0X712,
 0X721,
 0X730,
 0X73F,
 0X74F,
 0X75F,
 0X76F,
 0X77F,
 0X78E,
 0X79F,
 0X7AF,
 0X7BF,
 0X7CF,
 0X7E0,
 0X7F1,
 0X801,
 0X812,
 0X824,
 0X835,
 0X845,
 0X857,
 0X868,
 0X87A,
 0X88B,
 0X89D,
 0X8AF,
 0X8C1,
 0X8D3,
 0X8E5,
 0X8F8,
 0X90A,
 0X91C,
 0X92F,
 0X941,
 0X954,
 0X967,
 0X97B,
 0X98E,
 0X9A2,
 0X9B5,
 0X9C9,
 0X9DC,
 0X9F0,
 0XA05,
 0XA18,
 0XA2D,
 0XA42,
 0XA56,
 0XA6B,
 0XA80,
 0XA95,
 0XAAA,
 0XAC0,
 0XAD4,
 0XAE9,
 0XAFF,
 0XB15,
 0XB2B,
 0XB41,
 0XB58,
 0XB6E,
 0XB84,
 0XB9B,
 0XBB1,
 0XBC8,
 0XBE0,
 0XBF6,
 0XC0E,
 0XC25,
 0XC3D,
 0XC73,
 0XC8B,
 0XCA3,
 0XCBC,
 0XCD4,
 0XCED,
 0XD06,
 0XD1F,
 0XD38,
 0XD51,
 0XD6B,
 0XD84,
 0XD9E,
 0XDBA,
 0XDD3,
 0XDF7,
 0XE13,
 0XE2F,
 0XE4A,
 0XE66,
 0XE82,
 0XE9E,
 0XEBB,
 0XED8,
 0XEF5,
 0XF12,
 0XF30,
 0XF4E,
 0XF6B,
 0XF8E,

 };

const uint16_t PROGMEM OutVoltDac2_10[256]  = {
 0X16C,
 0X174,
 0X17A,
 0X181,
 0X188,
 0X18E,
 0X195,
 0X19C,
 0X1A2,
 0X1A9,
 0X1B0,
 0X1B7,
 0X1BE,
 0X1C5,
 0X1CC,
 0X1D3,
 0X1DA,
 0X1E1,
 0X1E6,
 0X1ED,
 0X1F5,
 0X1FC,
 0X203,
 0X20A,
 0X211,
 0X219,
 0X220,
 0X228,
 0X22F,
 0X236,
 0X23E,
 0X245,
 0X24D,
 0X255,
 0X25C,
 0X264,
 0X26C,
 0X273,
 0X27B,
 0X283,
 0X28B,
 0X293,
 0X29B,
 0X2A3,
 0X2AC,
 0X2B3,
 0X2BC,
 0X2C4,
 0X2CC,
 0X2D3,
 0X2DB,
 0X2E4,
 0X2EC,
 0X2F5,
 0X2FD,
 0X307,
 0X310,
 0X319,
 0X321,
 0X328,
 0X330,
 0X334,
 0X339,
 0X33D,
 0X341,
 0X348,
 0X34F,
 0X35C,
 0X368,
 0X370,
 0X378,
 0X381,
 0X389,
 0X392,
 0X39B,
 0X3A4,
 0X3AD,
 0X3B6,
 0X3BF,
 0X3C9,
 0X3D2,
 0X3DC,
 0X3E6,
 0X3F0,
 0X3FA,
 0X404,
 0X40E,
 0X418,
 0X423,
 0X42D,
 0X438,
 0X442,
 0X44C,
 0X457,
 0X461,
 0X46B,
 0X475,
 0X480,
 0X48B,
 0X496,
 0X4A0,
 0X4AB,
 0X4B5,
 0X4C1,
 0X4CB,
 0X4D6,
 0X4E1,
 0X4EC,
 0X4F7,
 0X503,
 0X50E,
 0X519,
 0X525,
 0X530,
 0X53B,
 0X547,
 0X553,
 0X55E,
 0X56A,
 0X576,
 0X582,
 0X58C,
 0X59A,
 0X5A6,
 0X5B2,
 0X5BF,
 0X5CB,
 0X5D7,
 0X5E4,
 0X5F1,
 0X5FE,
 0X60A,
 0X617,
 0X624,
 0X631,
 0X63F,
 0X64C,
 0X659,
 0X666,
 0X674,
 0X681,
 0X68F,
 0X69D,
 0X6AB,
 0X6B9,
 0X6C7,
 0X6D5,
 0X6E3,
 0X6F2,
 0X700,
 0X70C,
 0X71D,
 0X72C,
 0X73B,
 0X74A,
 0X759,
 0X768,
 0X777,
 0X787,
 0X796,
 0X7A6,
 0X7B5,
 0X7C5,
 0X7D5,
 0X7E5,
 0X7F5,
 0X805,
 0X815,
 0X826,
 0X836,
 0X847,
 0X858,
 0X869,
 0X87A,
 0X88A,
 0X89C,
 0X8AD,
 0X8BF,
 0X8D0,
 0X8E2,
 0X8F4,
 0X907,
 0X919,
 0X92B,
 0X93E,
 0X950,
 0X962,
 0X975,
 0X988,
 0X99C,
 0X9AF,
 0X9C2,
 0X9D6,
 0X9E9,
 0X9FD,
 0XA0E,
 0XA25,
 0XA39,
 0XA4B,
 0XA62,
 0XA77,
 0XA8C,
 0XAA1,
 0XAB6,
 0XACB,
 0XAE0,
 0XAF6,
 0XB0C,
 0XB22,
 0XB39,
 0XB4F,
 0XB65,
 0XB7C,
 0XB93,
 0XBAA,
 0XBC1,
 0XBD8,
 0XBF0,
 0XC08,
 0XC20,
 0XC38,
 0XC50,
 0XC69,
 0XC81,
 0XC9A,
 0XCB4,
 0XCCD,
 0XCE4,
 0XCFD,
 0XD1A,
 0XD35,
 0XD4F,
 0XD67,
 0XD85,
 0XDA0,
 0XDBC,
 0XDD7,
 0XDF0,
 0XE0F,
 0XE28,
 0XE48,
 0XE65,
 0XE82,
 0XE9D,
 0XEBE,
 0XEDA,
 0XEF9,
 0XF1A,
 0XF3A,
 0XF5E,

 };

uint16_t OutVoltDac1_00[256] = {
 0X2A8,
 0X25C,
 0X268,
 0X272,
 0X27E,
 0X289,
 0X294,
 0X2A0,
 0X2AA,
 0X2B5,
 0X2C0,
 0X2CA,
 0X2D5,
 0X2DF,
 0X2EA,
 0X2F4,
 0X2FE,
 0X309,
 0X313,
 0X31D,
 0X326,
 0X330,
 0X339,
 0X343,
 0X34B,
 0X355,
 0X35D,
 0X367,
 0X370,
 0X379,
 0X380,
 0X389,
 0X392,
 0X39B,
 0X3A3,
 0X3AB,
 0X3B3,
 0X3BC,
 0X3C4,
 0X3CC,
 0X3D4,
 0X3DC,
 0X3E4,
 0X3EC,
 0X3F4,
 0X3FC,
 0X403,
 0X40B,
 0X413,
 0X41A,
 0X422,
 0X429,
 0X432,
 0X438,
 0X441,
 0X448,
 0X450,
 0X458,
 0X45E,
 0X466,
 0X46E,
 0X474,
 0X47C,
 0X484,
 0X48B,
 0X493,
 0X499,
 0X4A1,
 0X4A9,
 0X4B0,
 0X4B7,
 0X4BE,
 0X4C5,
 0X4CD,
 0X4D5,
 0X4DC,
 0X4E2,
 0X4EB,
 0X4F1,
 0X4F9,
 0X500,
 0X507,
 0X50E,
 0X517,
 0X51D,
 0X525,
 0X52C,
 0X533,
 0X53B,
 0X542,
 0X549,
 0X550,
 0X557,
 0X55E,
 0X567,
 0X56E,
 0X575,
 0X57D,
 0X583,
 0X58A,
 0X592,
 0X59B,
 0X5A1,
 0X5A9,
 0X5B1,
 0X5B8,
 0X5C0,
 0X5C8,
 0X5CE,
 0X5D7,
 0X5DE,
 0X5E6,
 0X5ED,
 0X5F5,
 0X5FD,
 0X604,
 0X60C,
 0X613,
 0X61B,
 0X622,
 0X62B,
 0X633,
 0X63B,
 0X642,
 0X64A,
 0X652,
 0X659,
 0X661,
 0X669,
 0X672,
 0X67A,
 0X682,
 0X68A,
 0X692,
 0X69A,
 0X6A2,
 0X6AA,
 0X6B3,
 0X6BB,
 0X6C4,
 0X6CC,
 0X6D5,
 0X6DD,
 0X6E5,
 0X6EE,
 0X6F7,
 0X6FF,
 0X708,
 0X711,
 0X71A,
 0X723,
 0X72C,
 0X735,
 0X73E,
 0X748,
 0X751,
 0X75A,
 0X765,
 0X76E,
 0X777,
 0X782,
 0X78B,
 0X794,
 0X79F,
 0X7A9,
 0X7B4,
 0X7BD,
 0X7C8,
 0X7D4,
 0X7DD,
 0X7E9,
 0X7F2,
 0X7FD,
 0X809,
 0X814,
 0X820,
 0X82B,
 0X836,
 0X843,
 0X84E,
 0X85A,
 0X867,
 0X873,
 0X87F,
 0X88B,
 0X899,
 0X8A5,
 0X8B3,
 0X8BF,
 0X8CD,
 0X8DA,
 0X8E7,
 0X8F6,
 0X904,
 0X912,
 0X921,
 0X92F,
 0X93E,
 0X94D,
 0X95C,
 0X96B,
 0X97B,
 0X98A,
 0X99B,
 0X9AA,
 0X9B9,
 0X9CA,
 0X9DB,
 0X9EB,
 0X9FB,
 0XA0D,
 0XA1E,
 0XA30,
 0XA42,
 0XA53,
 0XA66,
 0XA78,
 0XA8A,
 0XA9D,
 0XAB1,
 0XAC4,
 0XAD7,
 0XAEA,
 0XAFE,
 0XB13,
 0XB27,
 0XB3C,
 0XB4F,
 0XB66,
 0XB7A,
 0XB90,
 0XBA6,
 0XBBC,
 0XBD2,
 0XBE8,
 0XC00,
 0XC16,
 0XC2D,
 0XC44,
 0XC5D,
 0XC74,
 0XC8D,
 0XCA6,
 0XCBE,
 0XCD7,
 0XCF1,
 0XD0B,
 0XD25,
 0XD40,
 0XD59,
 0XD77,

};

uint16_t OutVoltDac2_00[256] = {
   0X2BA,
   0X26E,
   0X27A,
   0X284,
   0X290,
   0X29B,
   0X2A6,
   0X2B2,
   0X2BC,
   0X2C7,
   0X2D2,
   0X2DC,
   0X2E7,
   0X2F1,
   0X2FC,
   0X306,
   0X310,
   0X31B,
   0X325,
   0X32F,
   0X338,
   0X342,
   0X34B,
   0X355,
   0X35D,
   0X367,
   0X36F,
   0X379,
   0X382,
   0X38B,
   0X392,
   0X39B,
   0X3A4,
   0X3AD,
   0X3B5,
   0X3BD,
   0X3C5,
   0X3CE,
   0X3D6,
   0X3DE,
   0X3E6,
   0X3EE,
   0X3F6,
   0X3FE,
   0X406,
   0X40E,
   0X415,
   0X41D,
   0X425,
   0X42C,
   0X434,
   0X43B,
   0X444,
   0X44A,
   0X453,
   0X45A,
   0X462,
   0X46A,
   0X470,
   0X478,
   0X480,
   0X486,
   0X48E,
   0X496,
   0X49D,
   0X4A5,
   0X4AB,
   0X4B3,
   0X4BB,
   0X4C2,
   0X4C9,
   0X4D0,
   0X4D7,
   0X4DF,
   0X4E7,
   0X4EE,
   0X4F4,
   0X4FD,
   0X503,
   0X50B,
   0X512,
   0X519,
   0X520,
   0X529,
   0X52F,
   0X537,
   0X53E,
   0X545,
   0X54D,
   0X554,
   0X55B,
   0X562,
   0X569,
   0X570,
   0X579,
   0X580,
   0X587,
   0X58F,
   0X595,
   0X59C,
   0X5A4,
   0X5AD,
   0X5B3,
   0X5BB,
   0X5C3,
   0X5CA,
   0X5D2,
   0X5DA,
   0X5E0,
   0X5E9,
   0X5F0,
   0X5F8,
   0X5FF,
   0X607,
   0X60F,
   0X616,
   0X61E,
   0X625,
   0X62D,
   0X634,
   0X63D,
   0X645,
   0X64D,
   0X654,
   0X65C,
   0X664,
   0X66B,
   0X673,
   0X67B,
   0X684,
   0X68C,
   0X694,
   0X69C,
   0X6A4,
   0X6AC,
   0X6B4,
   0X6BC,
   0X6C5,
   0X6CD,
   0X6D6,
   0X6DE,
   0X6E7,
   0X6EF,
   0X6F7,
   0X700,
   0X709,
   0X711,
   0X71A,
   0X723,
   0X72C,
   0X735,
   0X73E,
   0X747,
   0X750,
   0X75A,
   0X763,
   0X76C,
   0X777,
   0X780,
   0X789,
   0X794,
   0X79D,
   0X7A6,
   0X7B1,
   0X7BB,
   0X7C6,
   0X7CF,
   0X7DA,
   0X7E6,
   0X7EF,
   0X7FB,
   0X804,
   0X80F,
   0X81B,
   0X826,
   0X832,
   0X83D,
   0X848,
   0X855,
   0X860,
   0X86C,
   0X879,
   0X885,
   0X891,
   0X89D,
   0X8AB,
   0X8B7,
   0X8C5,
   0X8D1,
   0X8DF,
   0X8EC,
   0X8F9,
   0X908,
   0X916,
   0X924,
   0X933,
   0X941,
   0X950,
   0X95F,
   0X96D,
   0X97C,
   0X98C,
   0X99B,
   0X9AC,
   0X9BB,
   0X9CA,
   0X9DB,
   0X9EC,
   0X9FC,
   0XA0C,
   0XA1E,
   0XA2F,
   0XA41,
   0XA53,
   0XA65,
   0XA78,
   0XA89,
   0XA9B,
   0XAAE,
   0XAC2,
   0XAD6,
   0XAE8,
   0XAFC,
   0XB0F,
   0XB24,
   0XB38,
   0XB4D,
   0XB60,
   0XB77,
   0XB8B,
   0XBA1,
   0XBB8,
   0XBCD,
   0XBE4,
   0XBF9,
   0XC11,
   0XC27,
   0XC3E,
   0XC56,
   0XC6E,
   0XC86,
   0XC9E,
   0XCB7,
   0XCCF,
   0XCE8,
   0XD02,
   0XD1C,
   0XD36,
   0XD51,
   0XD6B,
   0XD88,

};

/* Global variables. */
// uint16_t spiOutfreq_u16=0;
// uint16_t spiOutfreq2_u16=0;

/*! \brief SPI master on PORT D. */
 static SPI_Master_t spiMasterD;

/*! \brief SPI slave on PORT C. */
 static SPI_Slave_t spiSlaveC = {NULL, NULL};

 //uint8_t slaveRxData[SLAVE_RX_NUM_BYTES];
 //uint8_t slaveRxCnt = 0;
 //uint8_t slaveRxStatus = 0;
 //uint8_t parallelRxStatus = 0;

  uint8_t freqIndex_pal = 0;
  uint8_t freqBand_pal = 0;
 static uint8_t pal_byteRead= 0;

 //static uint8_t inType = 0; /* serial = 1, parallel = 0 */

 //uint8_t palInData[SLAVE_RX_NUM_BYTES] = { 0, 0 };

 USART_t *UspiMaster_DAC   = &USARTD0;
 SPI_t   *spiMaster_DAC    = &SPID;
 SPI_t   *spiSlv_In        = &SPIC;

 PORT_t *port_a = &PORTA;
 PORT_t *port_b = &PORTB;
 PORT_t *port_d = &PORTD;
 PORT_t *port_r = &PORTR;
 
 uint8_t inType, inType_old;

 //uint8_t pal_byteRead = 0;

int main (void)
{
 SysClk_Init();
 
 /* Init SS pin as output with wired AND and pull-up. */
 //PORTD.DIRSET = PIN4_bm;
 //PORTD.PIN4CTRL = PORT_OPC_WIREDANDPULL_gc;

 /* Set SS output to high. (No slave addressed). */
 //PORTD.OUTSET = PIN4_bm;
 
 GPIO_set_PinDirection(port_r, 0, GPIO_OUT_PORT); /* Probe 1 */
 GPIO_set_PinDirection(port_r, 1, GPIO_OUT_PORT);  /* Probe 2 */
 GPIO_set_PinDirection(port_b, 0 ,GPIO_IN_PORT); /* serial/Parallel input indication pin */
 GPIO_set_PortDirection(port_a, GPIO_IN_PORT); /* Parallel input */
 GPIO_set_PinDirection(port_d, 0, GPIO_OUT_PORT); /* Transmit ready - TR */
 GPIO_set_PinDirection(port_d, 4, GPIO_OUT_PORT); /* SS  DAC */
 GPIO_Set_pin(port_d,4); /* SS DAC */
 
 GPIO_set_PinDirection(port_b, 1, GPIO_IN_PORT);
 GPIO_set_PinDirection(port_b, 2, GPIO_IN_PORT);
 
 GPIO_Reset_pin(port_r,0); /* Probe 1 */
 GPIO_Reset_pin(port_r,1); /* Probe 2 */
    GPIO_Set_pin(port_d,0); /* TR = 1 */
 
 cli();
 /** Parallel IN interrupt Init */
 port_b->INTCTRL = 0x08;   /* INT0 - disable INT 0, INT1 - Medium level */
 
 port_b->INT0MASK = 0x02;  /*INT0 - parallel data strobe - Port B pin 1 */
 port_b->INT1MASK = 0x01;  /*INT1 - Serial/parallel IN pin - Port B pin 0 */
 
 port_b->PIN0CTRL = 0x00;  /** INT 1 - port B pin 0 - Both Edge */ 
 port_b->PIN1CTRL = 0x01;  /** INT 0 - port B pin 1 - Rising Edge */

 
 /* Initialize SPI master on port D. */
 SPI_MasterInit( &spiMasterD,
     &SPID,
     &PORTD,
     false,
     SPI_MODE_0_gc,
     SPI_INTLVL_OFF_gc,
     true,
     SPI_PRESCALER_DIV4_gc);

 /* Initialize SPI slave on port C. */
 SPI_SlaveInit( &spiSlaveC,
       &SPIC,
             &PORTC,
                false,
                SPI_MODE_0_gc,
                SPI_INTLVL_OFF_gc);
      
    /** UART-SPI Init */      
    USART_SPI_MasterInit(UspiMaster_DAC, port_d);
    USART_SPI_TXenable(UspiMaster_DAC);       

 /* Enable low and medium level interrupts in the interrupt controller. */
 PMIC.CTRL |= (PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm);
  
 uint8_t inType = GPIO_Get_pin(port_b, 0);
 if(inType == 1)
 {
  //Serial Input
  port_b->INTCTRL = 0x08; 
  spiSlv_In->INTCTRL = SPI_INTLVL_MED_gc;
 }
 else
 {
  // Parallel In
  port_b->INTCTRL = 0x0A;
  spiSlv_In->INTCTRL = SPI_INTLVL_OFF_gc;
 }

 sei(); 
 while(1)
 { 
  ;    
 }              
}

/** Serial Input - SPIC */
ISR(SPIC_INT_vect, ISR_NAKED)
{
 cli();

 uint8_t freqBand = SPI_SlaveReadByte(&spiSlaveC);
spiSlv_In->STATUS = 0x00;
    while(!(SPI_SlaveDataAvailable(&spiSlaveC)));
 
 uint8_t freqIndex = SPI_SlaveReadByte(&spiSlaveC);
 
 //GPIO_Reset_pin(port_d,0); /* TR = 0 */
    port_d->OUT &= ~(0x01 << 0);
 
 uint16_t spiOutfreq_u16 = 0;
 uint16_t spiOutfreq2_u16 = 0;   
 switch(freqBand)
 {
  case 0:
   spiOutfreq_u16 = OutVoltDac1_00[freqIndex];
   spiOutfreq2_u16 = OutVoltDac2_00[freqIndex];
   GPIO_Reset_pin(port_r,0);
   GPIO_Reset_pin(port_r,1);
  break;  
  case 1:
   spiOutfreq_u16 = pgm_read_word(&(OutVoltDac1_01[freqIndex]));
   spiOutfreq2_u16 = pgm_read_word(&(OutVoltDac2_01[freqIndex]));
   GPIO_Set_pin(port_r,0);
   GPIO_Reset_pin(port_r,1); 
  break;  
  case 2:
   spiOutfreq_u16 = pgm_read_word(&(OutVoltDac1_10[freqIndex]));
   spiOutfreq2_u16 = pgm_read_word(&(OutVoltDac2_10[freqIndex]));
   GPIO_Reset_pin(port_r,0);
   GPIO_Set_pin(port_r,1);
  break;  
  case 3:
   spiOutfreq_u16 = 0x0FFF;
   spiOutfreq_u16 <<= 4;
   spiOutfreq2_u16 = spiOutfreq_u16;
   GPIO_Set_pin(port_r,0);
   GPIO_Set_pin(port_r,1);
  break;   
  default:
  //Reset to ZERO
  break;
 }
 spiOutfreq2_u16 <<= 4;
 spiOutfreq_u16 <<= 4; 
 
 // Pull /SS high DAC
        GPIO_Set_pin(port_d,4);  
 UARTSPI_MasterTransceiveByte(spiMaster_DAC, UspiMaster_DAC, spiOutfreq2_u16, spiOutfreq_u16);
 GPIO_Reset_pin(port_d,4); // Pull /SS low DAC
 
 //GPIO_Set_pin(port_d,0); //TR = 1
 port_d->OUT |= (0x01 << 0);

 sei();
 reti();   
}
 
 
ISR(PORTB_INT0_vect, ISR_NAKED)
{
  cli();
 uint8_t freqBand_pal = port_a->IN;

 //while(!(GPIO_Get_pin(port_b, 1)));
 port_b->INTFLAGS = 0x03;
 while((port_a->INTFLAGS & 0x01));
 uint8_t freqIndex_pal = port_a->IN;
 
 //GPIO_Reset_pin(port_d,0); /* TR = 0 */
 port_d->OUT &= ~(0x01 << 0);
 uint16_t spiOutfreq_u16 = 0;
 uint16_t spiOutfreq2_u16 = 0;
 switch(freqBand_pal)
 {
  case 0:
  spiOutfreq_u16 = OutVoltDac1_00[freqIndex_pal];
  spiOutfreq2_u16 = OutVoltDac2_00[freqIndex_pal];
  GPIO_Reset_pin(port_r,0);
  GPIO_Reset_pin(port_r,1);
  break;
  case 1:
  spiOutfreq_u16 = pgm_read_word(&(OutVoltDac1_01[freqIndex_pal]));
  spiOutfreq2_u16 = pgm_read_word(&(OutVoltDac2_01[freqIndex_pal]));
  GPIO_Set_pin(port_r,0);
  GPIO_Reset_pin(port_r,1);
  break;
  case 2:
  spiOutfreq_u16 = pgm_read_word(&(OutVoltDac1_10[freqIndex_pal]));
  spiOutfreq2_u16 = pgm_read_word(&(OutVoltDac2_10[freqIndex_pal]));
  GPIO_Reset_pin(port_r,0);
  GPIO_Set_pin(port_r,1);
  break;
  case 3:
  spiOutfreq_u16 = 0x0FFF;
  spiOutfreq_u16 <<= 4;
  spiOutfreq2_u16 = spiOutfreq_u16;
  GPIO_Set_pin(port_r,0);
  GPIO_Set_pin(port_r,1);
  break;
  default:
  //Reset to ZERO
  break;
 }
 spiOutfreq2_u16 <<= 4;
 spiOutfreq_u16 <<= 4;
 
 // Pull low SPI Master /SS
 GPIO_Set_pin(port_d,4);
 UARTSPI_MasterTransceiveByte(spiMaster_DAC, UspiMaster_DAC, spiOutfreq2_u16, spiOutfreq_u16);
 GPIO_Reset_pin(port_d,4); // Pull high /SS DAC
 
 //GPIO_Set_pin(port_d,0); //TR = 1
 port_d->OUT |= (0x01 << 0);
 port_b->INTFLAGS = 0x03;
 //port_b->INTCTRL = 0x02;   /* INT0 - Medium level INT, INT1 - low Int Lvl */
 sei();
    reti();
 //port_b->INTCTRL = 0x04;   /* INT0 - disable INT, INT1 - low Int Lvl */
}

/** Serial/parallel IN enable */
ISR(PORTB_INT1_vect, ISR_NAKED)
{
  cli();
  //Reset TR
  port_d->OUT &= ~(0x01 << 0);
  uint8_t inType = GPIO_Get_pin(port_b, 0);
  if(inType == 1)
  {
   //Serial Input
   port_b->INTCTRL = 0x08;
   spiSlv_In->INTCTRL = SPI_INTLVL_MED_gc;
   spiSlv_In->STATUS = 0x00;
  }
  else
  {
   // Parallel In
   port_b->INTCTRL = 0x0A;
   spiSlv_In->INTCTRL = SPI_INTLVL_OFF_gc;
  } 
  port_b->INTFLAGS = 0x03;
  spiSlv_In->STATUS = 0x00;
  sei();
  //Set TR
  port_d->OUT |= (0x01 << 0);
     reti(); 
}

 

thanks in advance

 

 

Last Edited: Tue. Dec 19, 2017 - 10:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, and welcome roshancheluva -

 

Your current numbers don't make much sense. You write, for example,

the overall current consumption is 0.025mA.i want to reduce the above current to 0.10mA.

 0.1mA is larger, not smaller, than 0.025mA! It is very hard to "reduce" 0.025mA to 0.1mA. Perhaps, you mean 0.01mA?

 

You will also get lots of complaints about the code formatting. Here is a suggestion. Go back and edit your original post. Highlight & copy all of the code. Then click "<>" near the end of the tool list at the top of the edit window. Paste the copied code into the new code window. Then click "OK" in the code window and "Post" out of your message window. That should go a long way to fix things.

 

Jim

 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Tue. Dec 19, 2017 - 06:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nothing to do with Studio, moving to Xmega forum

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
Then click "<>" near the end of the tool list at the top of the edit window

 

Illustrated examples here: https://www.avrfreaks.net/comment...

 

Note that you really need to be on a desktop system - not mobile - to do this.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi,

Thanks for reply,it was mistaken it should be 0.010 not 0.10mA.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and are you going to attend to the code formatting ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...