Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Writing a Labview Vi for light dimmer.

Status
Not open for further replies.

felicia_1

Junior Member level 1
Joined
Jun 4, 2014
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
186
I would like to construct a labview vi in order to send command to microcontroller (arduino) to trigger the circuits in order to modulate the intensity of halogen lamp.(using VISA serial) Could someone please advice on how to construct a labview vi. (using slider to control the intensity in labview).please refer to the below attachment.

pls: LIFA is not an ideal solution since it can't use with interrupt in Arduino.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
Light dimmer and Breathing light ¨C using Arduino and Labview for AC phase control
(External system version; used Code 2)
 
digital pin 02 (interupt 0)is used to detect AC phase interupt
digital pin 04 and 05 is used to trigger triac
        Pin 04 is for breath light via Labview
        Pin 05 is for test(fixed phase)
       
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
 
#include <TimerOne.h>                                  // TimeOne Library; [url]https://arduino.cc/playground/Code/Timer1[/url]
#include <Messenger.h>                                 // Messenger Library(version: 1.3); [url]https://www.arduino.cc/playground/Code/Messenger[/url]
 
// For Messenger Define function
Messenger message = Messenger();
 
// For AC phase
unsigned long int ZeroXTime[4] = {0,0,0,0};            // Timestamp in micros() of the zero crossing interrupts
unsigned long int Steptime;                            // How many microseconds in each step
unsigned long int AvgPeriod;                           // The average half phase period in microseconds
// unsigned long int PeriodResync = 3000;                 // Number of milliseconds between line freq measurements
// unsigned long int ResetPeriod = PeriodResync;          // The timestamp in millis() when we will measure the period again
unsigned long int AC_step = 100;                       // How many steps in an half AC phase
volatile unsigned long int SteptimeCounter;            // For counting Timer1 interrupts
volatile unsigned long int FireTriac[2] = {0,0};       // Set for multiple firetriac outputs
volatile boolean zero_cross = 0;                       // Tels us we've crossed the zero line
byte TriacPin[2] = {4,5};                              // Digital pins are used for firetriac
byte PowerMap[100] = {
                       99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,
                       63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,
                       27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
                     };                                //Powermap for speeding up the phase control
 
// Inital value for computer control
unsigned long val = 90;                                // Set a variable for Computer Control
                                         
void setup() {                                         // Initial setup
  Timer1.initialize(Steptime);                         // Start up Timer1 timer
  attachInterrupt(0, zero_cross_detect, FALLING);      // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
  pinMode(TriacPin[0], OUTPUT);                        // Set the Triac pin as output (Digital Pin 4 is used.)
  pinMode(TriacPin[1], OUTPUT);                        // Set the Triac pin as output (Digital Pin 5 is used.)
  measure_half_period();                               // Initially measure the average half phase period
  Serial.begin(9600);                                  // open the serial port at 9600 bps for computer control
}                                                      // End setup
 
void measure_half_period() {
  zero_cross = 0;                                      // Set zero_cross
  byte F = 0;                                          // Set a variable for the loop count
  while ( F < 4 ) {                                    // This loop takes 4 zero cross samples (F from 0 to 3)
    if ( zero_cross ) {                                // When a zero cross is detected
      ZeroXTime[F] = micros();                         // Record the current zeor cross time in microsecond
      zero_cross = 0;                                  // Reset zero_cross
      F++;                                             //
    }
  }                                                    // Calculate the time of each Steptime
  Steptime = (((ZeroXTime[1]-ZeroXTime[0]) + (ZeroXTime[2]-ZeroXTime[1]) + (ZeroXTime[3]-ZeroXTime[2])) / 3) / AC_step;
  Timer1.attachInterrupt(fire_triacs, Steptime);       // Associate fire_triacs() with the Timerone interrupt and the Steptime period
  //ResetPeriod = ResetPeriod + PeriodResync;          // Set the next time when we'll measure the half period again
}
 
void zero_cross_detect() {                             // function for detectind zero cross
  zero_cross = 1;                                      // set a variable that's picked up later
  SteptimeCounter = 0;                                 // Reset the step counter for the next round of triac firings
}
 
void fire_triacs() {
  if ( FireTriac[0] == SteptimeCounter ) {             // Is it time to fire triac?
      digitalWrite(TriacPin[0], HIGH);                 // Fire the Triac
      delayMicroseconds(2);
      digitalWrite(TriacPin[0], LOW);                  // Turn off the Triac gate (Triac will not turn off until next zero cross)
  }
 
  if ( FireTriac[1] == SteptimeCounter ) {             // Is it time to fire triac?
      digitalWrite(TriacPin[1], HIGH);                 // Fire the Triac
      delayMicroseconds(2);
      digitalWrite(TriacPin[1], LOW);                  // Turn off the Triac gate (Triac will not turn off until next zero cross)
  }
  SteptimeCounter++;                                   // This counter increments every time fire_triacs runs
}
 
void loop() {
  // Read data                                         // Read triac timing form a computer
     while ( Serial.available() ) {                    // Check if there is Serial data
     if ( message.process(Serial.read() ) ){           // Process the Serial data and continue if there is a message
         val = message.readInt();                      // Set the phase value
     }}
 
  // Fire Triac
     FireTriac[0] = PowerMap[val];                     // Fire Triac via computer control
     FireTriac[1] = PowerMap[5];                       // Fixed phase value for test
}

 

Attachments

  • Coding for Arduino.txt
    6.5 KB · Views: 4
  • Zero Cross Circuit.zip
    183.8 KB · Views: 4
  • Triggering Circuit.zip
    42.7 KB · Views: 3
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top