Search This Blog

Friday, December 28, 2018

EG8010 PWM Testing VB.NET code


EG8010 PWM Testing VB.NET code

VB.net code to 
Set Voltage(%) (1-255)
Set Freq. and frequency Range

Setting given in the datasheet can be set as per requirement,
Dead Time setting 500ns, 1uS, 1.5 uS



EG8010 PWM Testing

Code downlaod Link
https://drive.google.com/open?id=1am4H0XIL9QlJuQE4scVRzdNoTYwF9PR3

Datasheet link

Thursday, December 27, 2018

Practical Experiment on RLC circuit


Practical Experiment on RLC circuit

Experiment -1 
Where, value of R= 5 m ohm, C=500 uF, L = 2.15mH,


Given input Voltage Vin= 24V
Maximum Voltage Vm=19 V, Time Period= 2.5 ms
Experiment -2 
Where, value of R= 10 m ohm, C=500 uF, L = 2.15mH,
Result – if we double Resistance value then Area, A double and time period T same.
Experiment -3 
Where, value of R= 10 m ohm, C=1000 uF , L = 2.24mH,
Result – if we double capacitance value then Area, A same and time period T same.
Experiment -4
Where, value of R= 10 m ohm, C=1000 uF , L = 1.14mH,
Result – if we Half inductor value then Area A same and time period T same, means shape same.
Experiment -5 
Where, value of R= 10 m ohm, C=1000 uF, L1+L2=1.01+1.14
Result – if we add two inductor who’s same as inductor rating of previous experiment- 3, result is different, 
Shape is double, time period is increase at 3.5ms and V=30 Vm


Conclusion : we see behaviour of RLC circuit most important fact are seeing that is behaviour of circuit according to it inductor , resistance and capacitance , if we double the  value of resistance then its shape is double to previous shape , if we half its inductor value nothing is change its shape and time period . and if we double capacitor value nothing affect it shape and time period. Interesting thing is shown on inductor value different different shape and time period at overall inductor value is 2.24mH with single inductor and use two inductor with summing value is same 2.24mH. In using two inductor cases shape of graph is double and also time period is increases you can see experiment- 3 and experiment-5.

Friday, November 30, 2018

Lightning Impulse Signal : Li Full and Li Chop simulation


Lightning Impulse Signal : Li Full and Li Chop simulation Code

Generate Li Full and Li Chop array points using Code (VB.net)

Li Full : T1 (Time to peak) 1.2uS
              T2 (Time to peak) 50uS
               Amplitude : 1 unit

Code:

        Dim k0 As Integer = 100
        Dim k1 As Single = 2.47
        Dim k2 As Single = 1 / 68.23
        Dim I As Single = 0
        IMPULSE_ARY(0) = 0
        Dim t As Single = 0.01

        ' IMPULSE_ARY(0-124)=0
        For I = 125 To 152
            IMPULSE_ARY(I) = 4.2 * t ^ 3
            t = t + 0.01
        Next
        t = 0.04
       ' exponential 
        For I = 150 To SAMPLES
            IMPULSE_ARY(I) = 1 / 0.9643 * (1 - Math.E ^ (-k1 * t)) * (Math.E ^ (-k2 * t))
            'IMPULSE_ARY(I) =  Math.E ^ (-k1 * t) - (Math.E ^ (-k2 * t))
            t = t + 0.01
        Next
        For I = 0 To SAMPLES Step 4
            IMPULSE_ARY(I) = IMPULSE_ARY(I) + (Rnd(1) - 0.5) * 0.0004
        Next
       ' plot this array and get 



















--------------------------------------------------------------------------------------------------------------------------

Li Chopped : T1 (Time to peak) 1.2uS
              Tc (Time to peak) 3.88uS
               Amplitude : 1 unit

Code:

        Dim k0 As Integer = 100
        Dim k1 As Single = 2.47
        Dim k2 As Single = 1 / 68.23
        Dim I As Single = 0
        Dim t As Single = 0.01
        ' IMPULSE_ARY(0-124)=0       
        For I = 125 To 152
            IMPULSE_ARY(I) = 4.2 * t ^ 3
            t = t + 0.01
        Next
        t = 0.04
        For I = 152 To 4000
            IMPULSE_ARY(I) = 1 / 0.9643 * (1 - Math.E ^ (-k1 * t)) * (Math.E ^ (-k2 * t))
            t = t + 0.01
        Next
        Dim A As Single = 450
        Dim B As Single = A + 27
        t = 0.01 * B
        Dim E_VAL As Single
        For I = B To B + 25
            IMPULSE_ARY(I) = IMPULSE_ARY(I) * Math.Cos(2 * (t - (B / 100))) * (Math.E ^ (-0.2 * (t - (B / 100))))
            t = t + 0.01
        Next
        t = t - 0.01
        For I = B + 25 To 4000
            E_VAL = (0.95 * Math.E ^ (-4 * (t - (B + 25) / 100))) + (0.05 * Math.E ^ (-0.3 * (t - (B + 25) / 100)))

            IMPULSE_ARY(I) = IMPULSE_ARY(B + 25) * E_VAL * Math.Cos(3 * (t - (B + 25) / 100))
            t = t + 0.01
        Next
        For I = 0 To 4000 Step 4
            IMPULSE_ARY(I) = IMPULSE_ARY(I) + (Rnd(1) - 0.5) * 0.0006
        Next
    ' plot this array and get



Thursday, November 29, 2018

ANALOG COMPARATOR C CODE cvAVR for Atmega32/Atmega16

ANALOG COMPARATOR C CODE cvAVR for Atmega32/Atmega16

Chip type               : ATmega32
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
*****************************************************/

#include
#include
// Alphanumeric LCD Module functions
// its customization
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include
void main(void)
{
    PORTA=0x00;
    DDRA=0x00;
    PORTB=0x00;
    DDRB=0x00;
    PORTC=0x00;
    DDRC=0xFF;
    PORTD=0x00;
    DDRD=0xFF;

Analog_init();
// LCD module initialization
lcd_init(16);

while (1)
      {
          if (ACSR.5 == 1)  {
                PORTD =0xFF;
            }
            else {
                PORTD =0x00;
            }
          delay_ms(100);
      };
}


//---------------------------- ANALOG COMPARATOR ----------------------//
void Analog_init(void) {
 
   ACSR |= (1 << ACBG); // enable internal reference voltage 1,1V 
   ACSR |= (1 << ACIE); // enable comparator interrupt

}

void Analog_end(void) {
 
   ACSR |= (1 << ACD);
}

ISR (ANALOG_COMP_vect) { 

   int ac1 = 0;
   int ac2 = 0;
   int k = 0;

   if (ACO == 0) {
     
      ac2 = ac1;

      ac1 = ACO;
   }
   else {
     
      ac2 = ac1;

      ac1 = ACO;
   }
   k++;

   if (k==6) {
     
      ac1=ACO;
     
      if (ac2==ac1) {
       
         DDRC <<1 nbsp="" p="">      }
      else {
       
         DDRC <<1 nbsp="" p="">         DDRC +=1;
      }
    k=1;
   }
 
   Analog_end();
 
   get_number(DDRC); 
}
//-------------------------- END ANALOG COMPARATOR----------------------//


Tuesday, November 27, 2018

BITS-wilp old PAPER

Few BITS WILP old  PAPER for M. TECH SOFTWARE SYSTEMS
Comprehensive and Regular Exams


SPWM - ATSAM3X8E Arduino UNO PWM Setup code

ATSAM3X8E Arduino UNO PWM Setup code

I have used this code for SPWM (sine wave PWM) with dead time
sine wave table generated separately and duty cycle of PWM is updated after particular interrupt.
Only setting up pwm with top, inverting with dead time is given below.
---------------------------------------------------------------------------------
void pwmSetup() 
  {
    //Configure PWM channels 0,1,2,3 PWML0,PWMH0,PWML1,PWMH1,PWML2,PWMH2,PWML3,PWMH3),
( arduino pins P34,P35,P36,P37,P38,P39,P40,P41)

    REG_PIOC_PDR = 0x3FC;  //B1111111100,
    REG_PIOC_ABSR = REG_PIOC_ABSR | 0x3FCu; //B1111111100,
    REG_PMC_PCER1 = REG_PMC_PCER1 | 16;

 //Register 1 (activate clock for PWM, id36, bit5 of PMC_PCSR1)
    REG_PWM_ENA = REG_PWM_SR | B1111; //PWM Enable Register | PWM
    PMC->PMC_PCER1 |= PMC_PCER1_PID36;                // PWM power ON
    PWM->PWM_DIS = PWM_DIS_CHID2;                         //

      PWM->PWM_CH_NUM[2].PWM_CMR = PWM_CMR_CPRE_CLKB;   
      PWM->PWM_CH_NUM[2].PWM_CPRD = 2000;                   //
      PWM->PWM_CH_NUM[2].PWM_CDTY = 100;                    //
      PWM->PWM_IER1 = PWM_IER1_CHID2;                       //
 
      PWM->PWM_ENA = PWM_ENA_CHID2;                         //

      REG_PIOC_PDR = 0x3FC;                     //B1111111100, PIO
      REG_PIOC_ABSR = REG_PIOC_ABSR | 0x3FCu;   //B1111111100,
 
      REG_PMC_PCER1 = REG_PMC_PCER1 | 16; //Peripheral Clock Enable
      REG_PWM_ENA = REG_PWM_SR | B1111;

PWM_SCM_SYNC5 | PWM_SCM_SYNC4 | PWM_SCM_SYNC3 | PWM_SCM_SYNC2 |
PWM_SCM_SYNC1 | PWM_SCM_SYNC0; // Set the PWM channels as sync
   
      REG_PWM_CMR0 = 0x10100; //Channe0 Mode Register: Dead Time
      REG_PWM_CMR1 = 0x10100; //Channe1 Mode Register: Dead Time
      REG_PWM_CMR2 = 0x10100; //Channe2 Mode Register: Dead Time
      REG_PWM_CMR3 = 0x10100; //Channe3 Mode Register: Dead Time

      //dead time calc according to if clk is 84Mhz
      // 0xFC00FC  - 3us       // 0xA800A8  - 2us    // 0x540054  -
      //       1us      //0x1500150  -  4us        //  0x01680168   - 5us   make   all same
      REG_PWM_DT0 = 0xFC00FC;  // 0xA800A8; // 2us  ;//0x1500150;
      REG_PWM_DT1 = 0xFC00FC;  // 0xA800A8;   ;//0x01680168;//
      REG_PWM_DT2 = 0xFC00FC;  // 0xA800A8;   ;//0xA800A8;
      REG_PWM_DT3 = 0xFC00FC;  // 0xA800A8;   ;//0xA800A8;
 
// top has to decide what should be your interupt rate
      REG_PWM_CPRD0 = top; //Cha0nne0 Period Register
      REG_PWM_CPRD1 = top; //Channe1 Period Register
      REG_PWM_CPRD2 = top; //Channe2 Period Register
      REG_PWM_CPRD3 = top; //Channe3 Period Register


      PWM->PWM_IER1 = PWM_IER1_CHID2;                       //
//Interrupt on Channel 2 Counter match
      NVIC_EnableIRQ(PWM_IRQn);                             //

  }

Monday, November 26, 2018

CRC C Code

// CRC C CODE USED FOR MODBUS COMMUNICATION
unsigned int CRC(unsigned char intSend[], int len)
{
int int_c = 0xFFFF;
int int_l;

int int_i=0, int_j=0;

for (int_i = 0; int_i < len; int_i++)
{
//intSend[int_i] = intSend[int_i] & 0x00FF;

int_c = int_c ^  intSend[int_i]  ;
for ( int_j = 0; int_j < 8; int_j++)
{
int_l = int_c & 0x0001;  // Mask of LSB
int_c = int_c >> 1;
int_c = int_c & 0x7FFF;  //0x7FFF
if (int_l == 1)
int_c = int_c ^ 0xA001;
}
}
//int_crc_byte_a = int_c & 0x00FF;
//int_crc_byte_b = (int_c >> 8) & 0x00FF;
return int_c;
}

Saturday, November 24, 2018

PWM Atmega32:Inverter Mode Register Settings

SPWM

  // INVERTED MODE
TCCR1A = _BV(COM1A0) | _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);

// NON INVERTED MODE                    // set on match
// TCCR1A =   _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);
TCCR1B = _BV(WGM13) | _BV(WGM12);

/* start with a duty */
OCR1A = 0;
OCR1B = 0;

/* enable interrupt on timer overflow */
TIMSK = _BV(TOIE1);
/* enable interrupt      */
 sei();

TCCR1B |= _BV(CS00);

These can be used as bipolar settings.
Use sine table entries and update OCR1A/B after a particular time/interupt.

Sine wave points dc (Duty cycle array) (top - TOP for timer)
for(j=0;j {
   val = (j  * PI)/points;
   val = 1000 * sin(val) + 1000;
   val = val/2000;
   val = (val-0.5)* percentage + 0.5;
   dc[j]=top * val;
}

Thursday, December 11, 2014

Read/Write Data From LABJACK

LabJack produces Low Cost USB/Ethernet/WiFi based measurement and automation devices which provide analog inputs/outputs, digital inputs/outputs, and more. They serve as an inexpensive and easy to use interface between computers and the physical world.

BSET for Automation (DAQ)

LABJACK

Application


Contact, to develop any Labjack based application. (vikas.sharma711@gmail.com)

Wednesday, December 10, 2014

http://www.gopaisa.com/ref/vikas_711

GoPaisa: Best Cashback Paying Website & Discount Coupons
http://www.gopaisa.com/ref/vikas_711

Friday, July 19, 2013

System BEEP using VB.NET

   Public Shared Function _
       aBeep(ByVal dwFreq As Integer, ByVal dwDuration As Integer)   As Boolean
        ' can leave body of the function empty.
    End Function

Use system dll for beep.

Now call aBeep(100,100), multiple time to make a rhythmic beep.

Writing To and Reading from a text file in LABVIEW

Block diagram and Front Panel 




Wednesday, July 17, 2013

Keyboard and Explorer shortcuts

sfc /scannow
chkdsk /f /r
net start spooler


RUN
services.msc
msconfig
eudcedit
%temp%

More than 100 Keyboard Shortcuts must read
SHARE IT........

Keyboard Shorcuts (Microsoft Windows)
1. CTRL+C (Copy)
2. CTRL+X (Cut)
3. CTRL+V (Paste)
4. CTRL+Z (Undo)
5. DELETE (Delete)
6. SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)
7. CTRL while dragging an item (Copy the selected item)
8. CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)
9. F2 key (Rename the selected item)
10. CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
11. CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
12. CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
13. CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
14. CTRL+SHIFT with any of the arrow keys (Highlight a block of text)
SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)
15. CTRL+A (Select all)
16. F3 key (Search for a file or a folder)
17. ALT+ENTER (View the properties for the selected item)
18. ALT+F4 (Close the active item, or quit the active program)
19. ALT+ENTER (Display the properties of the selected object)
20. ALT+SPACEBAR (Open the shortcut menu for the active window)
21. CTRL+F4 (Close the active document in programs that enable you to have multiple documents opensimultaneou sly)
22. ALT+TAB (Switch between the open items)
23. ALT+ESC (Cycle through items in the order that they had been opened)
24. F6 key (Cycle through the screen elements in a window or on the desktop)
25. F4 key (Display the Address bar list in My Computer or Windows Explorer)
26. SHIFT+F10 (Display the shortcut menu for the selected item)
27. ALT+SPACEBAR (Display the System menu for the active window)
28. CTRL+ESC (Display the Start menu)
29. ALT+Underlined letter in a menu name (Display the corresponding menu) Underlined letter in a command name on an open menu (Perform the corresponding command)
30. F10 key (Activate the menu bar in the active program)
31. RIGHT ARROW (Open the next menu to the right, or open a submenu)
32. LEFT ARROW (Open the next menu to the left, or close a submenu)
33. F5 key (Update the active window)
34. BACKSPACE (View the folder onelevel up in My Computer or Windows Explorer)
35. ESC (Cancel the current task)
36. SHIFT when you insert a CD-ROMinto the CD-ROM drive (Prevent the CD-ROM from automatically playing)
Dialog Box - Keyboard Shortcuts
1. CTRL+TAB (Move forward through the tabs)
2. CTRL+SHIFT+TAB (Move backward through the tabs)
3. TAB (Move forward through the options)
4. SHIFT+TAB (Move backward through the options)
5. ALT+Underlined letter (Perform the corresponding command or select the corresponding option)
6. ENTER (Perform the command for the active option or button)
7. SPACEBAR (Select or clear the check box if the active option is a check box)
8. Arrow keys (Select a button if the active option is a group of option buttons)
9. F1 key (Display Help)
10. F4 key (Display the items in the active list)
11. BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)

Microsoft Natural Keyboard Shortcuts
1. Windows Logo (Display or hide the Start menu)
2. Windows Logo+BREAK (Display the System Properties dialog box)
3. Windows Logo+D (Display the desktop)
4. Windows Logo+M (Minimize all of the windows)
5. Windows Logo+SHIFT+M (Restorethe minimized windows)
6. Windows Logo+E (Open My Computer)
7. Windows Logo+F (Search for a file or a folder)
8. CTRL+Windows Logo+F (Search for computers)
9. Windows Logo+F1 (Display Windows Help)
10. Windows Logo+ L (Lock the keyboard)
11. Windows Logo+R (Open the Run dialog box)
12. Windows Logo+U (Open Utility Manager)
13. Accessibility Keyboard Shortcuts
14. Right SHIFT for eight seconds (Switch FilterKeys either on or off)
15. Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)
16. Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off)
17. SHIFT five times (Switch the StickyKeys either on or off)
18. NUM LOCK for five seconds (Switch the ToggleKeys either on or off)
19. Windows Logo +U (Open Utility Manager)
20. Windows Explorer Keyboard Shortcuts
21. END (Display the bottom of the active window)
22. HOME (Display the top of the active window)
23. NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder)
24. NUM LOCK+Plus sign (+) (Display the contents of the selected folder)
25. NUM LOCK+Minus sign (-) (Collapse the selected folder)
26. LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder)
27. RIGHT ARROW (Display the current selection if it is collapsed, or select the first subfolder)
Shortcut Keys for Character Map
After you double-click a character on the grid of characters, you can move through the grid by using the keyboard shortcuts:
1. RIGHT ARROW (Move to the rightor to the beginning of the next line)
2. LEFT ARROW (Move to the left orto the end of the previous line)
3. UP ARROW (Move up one row)
4. DOWN ARROW (Move down one row)
5. PAGE UP (Move up one screen at a time)
6. PAGE DOWN (Move down one screen at a time)
7. HOME (Move to the beginning of the line)
8. END (Move to the end of the line)
9. CTRL+HOME (Move to the first character)
10. CTRL+END (Move to the last character)
11. SPACEBAR (Switch between Enlarged and Normal mode when a character is selected)
Microsoft Management Console (MMC)
Main Window Keyboard Shortcuts
1. CTRL+O (Open a saved console)
2. CTRL+N (Open a new console)
3. CTRL+S (Save the open console)
4. CTRL+M (Add or remove a console item)
5. CTRL+W (Open a new window)
6. F5 key (Update the content of all console windows)
7. ALT+SPACEBAR (Display the MMC window menu)
8. ALT+F4 (Close the console)
9. ALT+A (Display the Action menu)
10. ALT+V (Display the View menu)
11. ALT+F (Display the File menu)
12. ALT+O (Display the Favorites menu)

MMC Console Window Keyboard Shortcuts
1. CTRL+P (Print the current page or active pane)
2. ALT+Minus sign (-) (Display the window menu for the active console window)
3. SHIFT+F10 (Display the Action shortcut menu for the selected item)
4. F1 key (Open the Help topic, if any, for the selected item)
5. F5 key (Update the content of all console windows)
6. CTRL+F10 (Maximize the active console window)
7. CTRL+F5 (Restore the active console window)
8. ALT+ENTER (Display the Properties dialog box, if any, for theselected item)
9. F2 key (Rename the selected item)
10. CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)
Remote Desktop Connection Navigation
1. CTRL+ALT+END (Open the Microsoft Windows NT Security dialog box)
2. ALT+PAGE UP (Switch between programs from left to right)
3. ALT+PAGE DOWN (Switch between programs from right to left)
4. ALT+INSERT (Cycle through the programs in most recently used order)
5. ALT+HOME (Display the Start menu)
6. CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)
7. ALT+DELETE (Display the Windows menu)
8. CTRL+ALT+Minus sign (-) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)
9. CTRL+ALT+Plus sign (+) (Place asnapshot of the entire client window area on the Terminal server clipboardand provide the same functionality aspressing ALT+PRINT SCREEN on a local computer.)

Microsoft Internet Explorer Keyboard Shortcuts
1. CTRL+B (Open the Organize Favorites dialog box)
2. CTRL+E (Open the Search bar)
3. CTRL+F (Start the Find utility)
4. CTRL+H (Open the History bar)
5. CTRL+I (Open the Favorites bar)
6. CTRL+L (Open the Open dialog box)
7. CTRL+N (Start another instance of the browser with the same Web address)
8. CTRL+O (Open the Open dialog box,the same as CTRL+L)
9. CTRL+P (Open the Print dialog box)
10. CTRL+R (Update the current Web )

SHARE IT WITH YOUR FRIENDS........

Disable close button on Title Bar in vb.net

place this code in the form code

'declare constant
Private Const DIS_CLOSE_BUTTON As Integer = &H200

'code
    Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim p As CreateParams = MyBase.CreateParams
            p.ClassStyle = p.ClassStyle Or DIS_CLOSE_BUTTON
            '   p.ClassStyle = p.ClassStyle Or &H200
            Return p  
        End Get
    End Property

Atmega16 I2C example and writing to EEPROM


#include
#include
#include
#define high_byte(x) ((x & 0xFF00) >> 8)
#define NO 0x00 // Value representing NO
// I2C Bus functions
#asm
   .equ __i2c_port=0x12 ;PORTD
   .equ __sda_bit=3
   .equ __scl_bit=2
#endasm
#include
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include
// Declare your global variables here
unsigned char read_byte (unsigned int address);    
void write_byte (unsigned char data_out, unsigned int address);
void READ_FREQ_COUNTER(void);  
void READ_PC_COUNTER(void);  
void WRITE_TO_EEPROM(void);

void WRITE_TO_EEPROM2(void);
unsigned int FREQ_COUNTER=1;
unsigned int PC_COUNTER=3;
void main(void)
{
unsigned char b[20];
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0xff;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0xff;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0xff;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
PORTD.2=0;
PORTD.3=0;
// I2C Bus initialization
i2c_init();

//unsigned char i2c_start(void);
//unsigned char i2c_read(unsigned char ack);
//unsigned char i2c_write(unsigned char data);
//write_byte((unsigned char)eeprom_address , 1);
//eeprom_address1=  read_byte(1);

//READ_PC_COUNTER();
delay_ms(200);
READ_FREQ_COUNTER();

sprintf(b,"FREQ - %u ,PC - %u",FREQ_COUNTER,PC_COUNTER) ;
lcd_init(40);
lcd_clear();
lcd_putsf("ETM");
delay_ms(2000);
while (1)
      {
       
        sprintf(b,"FREQ - %u ,PC - %u",FREQ_COUNTER,PC_COUNTER) ;
        lcd_clear();
        lcd_puts(b);        
       
          if (PINB.1 == 0)
          {
             FREQ_COUNTER++;
             WRITE_TO_EEPROM();
             delay_ms(200);
          }
           
         
           if (PINB.2 == 0)
          {
              PC_COUNTER++;
             WRITE_TO_EEPROM();
             delay_ms(200);
          }  
         
           if (PINB.3 == 0)
          {
               READ_FREQ_COUNTER();
              // READ_PC_COUNTER();
                delay_ms(200);
          }  
         
         delay_ms(600);
      };
}


void write_byte (unsigned char data_out, unsigned int address)
{
i2c_start(); // Send start signal
i2c_write(0xA0);       // Send identifier I2C address
i2c_write(high_byte(address)); // Send address to EEPROM
    i2c_write((unsigned char)address);   // Send address to EEPROM
    i2c_write(data_out);             // Send low byte to EEPROM
    delay_ms(100);       // Delay a period of time to write
    i2c_stop();                   // Send I2C Stop Transfer
    delay_ms(100);       // Delay a period of time to write
}

//------------------------------------------------------------------------------
// Procedure: read_byte
// Inputs: address
// Outputs: none
// Description: Reads a byte from the EEPROM given the address
//------------------------------------------------------------------------------
unsigned char read_byte (unsigned int address)
{
unsigned char data_in;

i2c_start(); // Send start signal

i2c_write(0xA0);               // Send identifer I2C address
    i2c_write(high_byte(address));   // Send address to EEPROM
    i2c_write((unsigned char)address);   // Send address to EEPROM
i2c_start();             // Send I2C Start Transer
i2c_write(0xA1);               // Send identifer I2C address
    data_in = i2c_read(NO);       // Read byte
    i2c_stop();                   // Send I2C Stop Transfer

    return data_in;                
}



void WRITE_TO_EEPROM()
{
i2c_start();
i2c_write(0xA0);    
//i2c_write(0x00);
i2c_write(high_byte(0)); // Send address to EEPROM
    i2c_write((unsigned char)0);      
i2c_write((unsigned char)FREQ_COUNTER);
delay_ms(40);
i2c_stop();

delay_ms(100);

i2c_start();
i2c_write(0xA0);
i2c_write(0x10);
//i2c_write(high_byte(0)); // Send address to EEPROM
 //   i2c_write((unsigned char)0);
i2c_write((unsigned char)PC_COUNTER);  
delay_ms(40);
i2c_stop();
}

void READ_FREQ_COUNTER()
{
i2c_start();
i2c_write(0xA0);    
    i2c_write(high_byte(0));   // Send address to EEPROM
    i2c_write((unsigned char)0);
i2c_start();
i2c_write(0xA1);        
FREQ_COUNTER = i2c_read(0);

i2c_stop();

delay_ms(100);

i2c_start();
i2c_write(0xA0);  
i2c_write(0x10);
   // i2c_write(high_byte(0));   // Send address to EEPROM
   // i2c_write((unsigned char)0);  
i2c_start();
i2c_write(0xA1);
PC_COUNTER = i2c_read(0);

//   eeprom_address = i2c_read(0);
//    sprintf(b,"EE - %u , %u",i2c_read(0x00), i2c_read(0x00)) ;
i2c_stop();
}



void WRITE_TO_EEPROM2()
{
i2c_start();
i2c_write(0xB0);    
i2c_write(0x00);    
i2c_write((unsigned char)PC_COUNTER);  
i2c_stop();
}



void READ_PC_COUNTER()
{
i2c_start();
i2c_write(0xB0);    
i2c_write(0x00);
i2c_start();
i2c_write(0xB1);        
//  eeprom_address1 = i2c_read(0);
PC_COUNTER = i2c_read(0);
//    sprintf(b,"EE - %u , %u",i2c_read(0x00), i2c_read(0x00)) ;
i2c_stop();
}

Tuesday, July 16, 2013

Cirrus CS 5490 IC with VB.NET

Code used in VB.NET to communicate with Cirrus CS 5490 IC

These code has to be sent to serial port (RS232)
Only code related to read something (say RMS of Channel 1 and 2) will return 3 bytes.

(HEXADECIMAL CODES)

'Wake up                      "C3"
'Single reading               "D4"
'RMS page selection      "90"

        'HOW TO ENABLE FFT AND IIF  (CODES)
         "40"    '  write register and three bytes
         "0A"    ' enable HPF AND IIF ON
         "02"
         "10"

 'ABOVE 4 BYTES WILL SET REGISTER WHICH WILL ENABLE FFT AND IIF


' NOW IN TIMER OR INFINITE LOOP

 "D4"   'UPDATE READING BY IC

 "06"   'READ RMS OF CH1, ON RECEIVING THIS BYTE IC WILL SEND 3 BYTES

 "07"   'READ RMS OF CH2, ON RECEIVING THIS BYTE IC WILL SEND 3 BYTES


AFTER 06 AND 07 IC WILL SEND 3 BYTES OF RMS VOLTAGE OF CH1 AND CH2.

--



Monday, July 15, 2013

RS232 settings in Atmega16/32

Steps for RS232 communication using Atmega16 and VB.net application

1. Set Baud Rate
#define F_CPU 8000000L
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

2. Register Setting
   UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception circuitry
   UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes

   UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
   UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register

   UCSRB |= (1 << RXCIE); // Enable the USART Recieve Complete interrupt (USART_RXC)

3. Interrupt Routine
// this will echo back the same char
ISR(USART_RXC_vect) {
  char R;
   R = UDR;
  UDR =  R;
}


4. sei();

5.  main()
and infinite loop

Conversions Binary, Octal, Decimals and HexaDecimals in VB.NET

            'let str is a byte in 0 - 255
            Dim str As Integer = tb_BYTE.Text

            Me.TB_BIN.Text = "Bin:" & Convert.ToString(str, 2)
            Me.TB_OCT.Text = "Oct:" & Convert.ToString(str, 8)
            Me.TB_DEC.Text = "Dec:" & Convert.ToString(str, 10)
            Me.TB_HEXA.Text = "Hex:" & Convert.ToString(str, 16).ToUpper

Monday, July 8, 2013

Thursday, December 27, 2012

Create CON folder

Simply folder named as CON can not be created.

To Create CON folder.

Press ALT + 255 (255 from numeric pad)

Now create folder with name CON



Tuesday, February 21, 2012

Create a DLL in VB.NET and USE it in LABVIEW

How to use a DLL in labview, created in VB.net?

Create a Com DLL in VB.NET.

In Labview open empty VI file

Add  :   Connectivity ->  NET  ->   Constructor Node
             Double Click on Constructor Node and select DLL file
Add  :   Connectivity ->  NET  ->   Invoke Node or Property Node
             Take Ref out from Constructor Node as the input for Invoke Node or Property Node.
              This will show functions/properties available.
             Select function/property, use its input/output parameters.


Invoke Node is to call a method/function
Property Node is to use a property

Thursday, August 11, 2011

Serial Communication using Atmega16 : USART


USART in ATMEGA16, with VB.NET code. (Serial Port Communication)
This code is reading Voltage from ADC1 and send it on Serial port and reading the incoming serial data.
On the other hand VB.NET code will receive Serial data (Voltage) and sends a string serially 

/*****************************************************
Chip type               : ATmega16
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include
 #include
// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include
// Standard Input/Output functions
#include

#include
#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7

#define FRAMING_ERROR (1<
#define PARITY_ERROR (1<
#define DATA_OVERRUN (1<
#define DATA_REGISTER_EMPTY (1<
#define RX_COMPLETE (1<

// USART Receiver buffer
#define RX_BUFFER_SIZE 8
char rx_buffer[RX_BUFFER_SIZE];

#if RX_BUFFER_SIZE<256
unsigned char rx_wr_index,rx_rd_index,rx_counter;
#else
unsigned int rx_wr_index,rx_rd_index,rx_counter;
#endif

// This flag is set on USART Receiver buffer overflow
bit rx_buffer_overflow;

 unsigned char REC_DATA[20];  
 int J=0;


// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;

if (data == '?')
{
J=0;
//sprintf(REC_DATA," ") ;  
}
else
{
REC_DATA[J]=data;
 J++;
}

if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
   {
   rx_buffer[rx_wr_index]=data;
   if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
   if (++rx_counter == RX_BUFFER_SIZE)
      {
      rx_counter=0;
      rx_buffer_overflow=1;
      };
   };
}

#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
//while (rx_counter==0);
data=rx_buffer[rx_rd_index];
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
#asm("cli")
--rx_counter;
#asm("sei")
return data;
}
#pragma used-
#endif

// USART Transmitter buffer
#define TX_BUFFER_SIZE 8
char tx_buffer[TX_BUFFER_SIZE];

#if TX_BUFFER_SIZE<256
unsigned char tx_wr_index,tx_rd_index,tx_counter;
#else
unsigned int tx_wr_index,tx_rd_index,tx_counter;
#endif

// USART Transmitter interrupt service routine
interrupt [USART_TXC] void usart_tx_isr(void)
{
if (tx_counter)
   {
   --tx_counter;
   UDR=tx_buffer[tx_rd_index];
   if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0;
   };
}

#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the USART Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter == TX_BUFFER_SIZE);
#asm("cli")
if (tx_counter || ((UCSRA & DATA_REGISTER_EMPTY)==0))
   {
   tx_buffer[tx_wr_index]=c;
   if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0;
   ++tx_counter;
   }
else
   UDR=c;
#asm("sei")
}
#pragma used-
#endif



#define ADC_VREF_TYPE 0x00

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}

// Declare your global variables here

void main(void)
{
  unsigned int volt;
 unsigned char b[20];  
 int i=0;
  float f=0;
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0xD8;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;

// LCD module initialization
lcd_init(20);

// Global enable interrupts
#asm("sei")

while (1)
      {
             ADMUX=0x21 & 0xff ;
              lcd_clear();
             lcd_gotoxy(0,0);
             delay_ms(10);    
             lcd_putsf("Volt= ");
             volt=(unsigned int) read_adc(1);
             f=volt;
             f= 5 * (f/1023);
             ftoa(f,2,b);                                 // till 4 decimal places
             sprintf(b,"%s",b) ;
             lcd_puts(b);
                 
             lcd_gotoxy(13,0);
             delay_ms(10);    
             lcd_putsf("V");
             lcd_gotoxy(0,1);
              sprintf(b," ") ;
              sprintf(b,"%u?",volt) ;
               lcd_puts(b);
                 
               for (i=0;i<20;i++)
               {
                 putchar(b[i]);
                if (b[i] =='?')
                 break;
               }
                  sprintf(b," ") ;  
                  /*
                 for (i=0;i<20;i++)
               {  
                 b[i]=getchar();
             
                 if (b[i] =='?' || b[i] =='' || b[i] ==' ')
                 break;              
               
                  delay_ms(50);    
                }
             
                  lcd_gotoxy(0,2);
                  lcd_puts(b);
                  sprintf(b," ") ;
                   */    
                 
                     lcd_gotoxy(0,2);
                     lcd_puts(REC_DATA);
                     sprintf(REC_DATA," ") ;
                   lcd_gotoxy(5,3);
                  lcd_putsf("SER COMM");
               
             
               
             delay_ms(1000);    
           

      };
}


VB.NET code

1)  Open serial Port

 If Not SerialPort1.IsOpen Then
            SerialPort1.PortName = "Com3"     'port
         
           ' Set other port parameters.
            SerialPort1.BaudRate = 9600
            SerialPort1.Parity = Parity.None
            SerialPort1.DataBits = 8
            SerialPort1.StopBits = StopBits.One
            SerialPort1.Handshake = Handshake.None
            SerialPort1.WriteBufferSize = 100000
            SerialPort1.DtrEnable = False
            SerialPort1.RtsEnable = False
            SerialPort1.Open()
       
        End If


2)  On Data_received event
 Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

System.Threading.Thread.Sleep(100)
        'DATA_RECEIVED = DATA_RECEIVED & SerialPort1.ReadExisting()
        'DATA_RECEIVED_FLAG = 1


        Dim bRead, nRead As Integer
        Dim returnStr As String = ""
        Dim ascStr As String = ""

        bRead = SerialPort1.BytesToRead 'Number of Bytes to read
        Dim cData(bRead - 1) As Byte
        nRead = SerialPort1.Read(cData, 0, bRead)  'Reading the Data
        For Each b As Byte In cData
            DATA_RECEIVED_1 = DATA_RECEIVED_1 & " " & Chr(b)
        Next
        DATA_RECEIVED_FLAG_1 = 1
    End Sub

''There are many ways, one can choose any method.


3) Display data received and send data (On serial) (Using timer)

 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If DATA_RECEIVED_FLAG_1 = 1 Then
            TextBox3.Text = DATA_RECEIVED_1 & Environment.NewLine
            DATA_RECEIVED_1 = ""
            DATA_RECEIVED_FLAG_1 = 0
        End If
        If Me.CheckBox1.Checked Then
            SerialPort1.Write("VIKAS")  'String will be displayed on LCD
            System.Threading.Thread.Sleep(20)
        End If
    End Sub

       ''If CheckBox1 is checked then send data otherwise not.






Wednesday, August 10, 2011

Settings of Fuse bits and Lock bits of Atmega8535

Atmega8535 Fuse bits and Lock bits

  1)  Fuse bits
High byte :      S853SC,    WDTON,      SPIEN,         CKOPT
                      EESAVE,   BOOTSZ1,    BOOTSZ0,  BOOTRST

Low Byte:       BODLEVEL,          BODEN,         SUT1,       SUT0
                       CKSEL3,               CKSEL2,        CKSEL1,  CKSEL0

How to set Atmega8535 at 1Mhz (Internal)?  (Also Default settings of Atmega8535 )  
    High byte :    1 1 0 1 1 0 0 1             0xD9
    Low Byte:    1 1 1 0 0 0 0 1             0xE1

   In HandyProg





How to set Atmega8535 at 8Mhz (Internal)?
    High byte :    1 1 0 1 1 0 0 1             0xD9
    Low Byte:    1 1 1 0 0 1 0 0             0xE4




How to set Atmega8535 at 8Mhz (External Crystal )?
    High byte :    1 1 0 1 1 0 0 1             0xD9
    Low Byte:    1 1 1 0 1 1 11             0xEF


How to set Atmega8535 at 12-16Mhz (External Crystal )?
    High byte :    1 1 0 0 1 0 0 1             0xC9
    Low Byte:    1 1 1 0 1 1 1 1             0xEF


Lock Bits of Atmega8535 .
For HadyProg Select all six Lock Bits
For Robotics code to be written is : 0x00



Convert date and time in the desired format in vb,net


These codes help in formatting date and time in the desired format.

1.dd/MM/yyyy

String.Format("{0:dd/MM/yyyy}", DateTime.Now)

O/P = 19/12/2008

2.MM/dd/yyyy

String.Format("{0:MM/dd/yyyy}", DateTime.Now)

O/P = 12/19/2008


3.dd/MM/yy

String.Format("{0:dd/MM/yy}", DateTime.Now)

O/P = 19/12/08


4.t

String.Format("{0:t}", DateTime.Now)

O/P = 10:30 AM


5.F

String.Format("{0:F}", DateTime.Now)


o/p=Friday, December 19, 2008 10:48:46 AM

Thursday, June 23, 2011

Handle Cross(X) button on control box in form in vb.net.

 Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        MessageBox.Show("closed")
    End Sub
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        MessageBox.Show("closing")
    End Sub

Wednesday, May 11, 2011

Create a DLL in LABVIEW and Using it in VB.NET

Creating DLL in LABVIEW

Step 1: Create a New Empty Project

Step 2: Right click on My Computer icon -> New -> Vi
            New VI file will be opened.

Step 3: Add some Controls as per requirement.
            i.e   2 num controls and 1 num indicator with some mathematic control
            i.e   Addition of 2 numbers

Step 4: In the Front Panel Window, right click on the ICON below the Close button.
            Click on Show Connector.
            Again right click on that and choose the appropriate pattern.
            Now click in the box of pattern and then click on ist control,
            then click on second pattern box then click on 2nd control. Similarly connect all controls with the        pattern box.

Step 5: Save VI file and project.

Step 6: Now right click on the Build Specification in the Project explorer.
            Choose New -> Shared Library (DLL)
Step 7: Click on Information Source , Choose your VI file as Source File.
Step 8: Click on build to Create DLL

Check out other properties like naming the DLL file, how to edit source file again etc.

 Repeating these steps one can add number of VI files. VI file name will be the name of the function or sub.
------------------------------------------------------------------------

VB.NET to use DLL (built in labview)

  'protoptype   MUL_2_NOS is VI files name

    _
    Public Shared Function MUL_2_NOS(ByVal x As Double, ByVal y As Double) As Double

    End Function
or

  Declare Function MUL_2_NOS Lib "DLL PATH HERE" (ByVal x As Double, ByVal y As Double)  As    Double 

   Dim D As Double = MUL_2_NOS(2, 7)

   messagebox.show(d.tostring)

  ------------------------------------------------------------

Thursday, July 22, 2010

Atmega16 : Square wave Frequency Counter: CodeVision Code

/*****************************************************
Chip type               : ATmega16
Program type            : Application
AVR Core Clock frequency: 8.002000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
Written By                :(Vikas Sharma)
*****************************************************/

#include
#include
#include
// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include
//Declare your global variables here
  unsigned char str_buffer[20];
unsigned int CNT=0;
int FLAG=0;
//Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
       // PORTD.7=~PORTD.7;                       //High-Low pulse
       lcd_clear();
       sprintf(str_buffer,"FREQ = %u",CNT);
       lcd_puts(str_buffer);
       CNT=0;
        //TCNT1=55535;
        TCNT1=57723;
}




void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0xFF;
DDRB=0x00;          //input   push buttons

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0xff;           //output         lcd

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0xff;     

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

//TCNT1=55535;
 TCNT1=57723;
TCCR1A=0b00000000;
TCCR1B=0b00000101;   //SELECT CLOCK HRER CS


// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
OCR2=0x00;
TCCR2=0b00000101;
TCNT2=0xFF;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0b00100100;                  //6 bit timer2  0 bit tiemr0   2 bit timer1 

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
#asm("sei")

lcd_init(20);
lcd_putsf("FREQ-");
while (1)
      {
      // Place your code here
           if (PINB.4 == 0 && FLAG==0)
            {
                CNT=CNT+1;
                FLAG=1; 
            }
             if (PINB.4 == 1)
             {
                FLAG=0;
             }
      //PORTD.0=PINB.4;
     // delay_ms(1000);

      };
}