03-11-2013 06:27 PM
Hello community,
I like the Arduino PWM signal generation that I found from the example a lot but I am having some trouble trying to write PWM port with a delay on each individual pin and changing frequency on the fly. Currently I am using Arduino Mega: pin 2, 3, & 5. Also, if I use a combination of pins other that the ones sharing the same counter/timer (for instance adding pin 4), it seems to offset the start time for the pin that is not in that group. I wonder if and how can I generate the PWM signal for more that 3 pins and able to control the start time and as well as being able to control the delay for each individual pin properly.
I also wonder if there's a new update for the "LabVIEW interface for Arduino Packet" available besides the one that was posted by Sammy_K on June 27, 2011?
I am not an expert on LabVIEW scripting, but if anyone can respond with an example will be greatly appreciated.
Please help,
Sy D.
03-12-2013 02:51 PM
The latest version of LIFA is 2.2.0.79 and can be isntalled via the VI Package Manager. It was released in August 2012.
As for the PWM question, I'm not sure why a "start time" is relevant because PWM is only used for the pulse width information (for communications). I used 4 PWM pins for motor controllers on our robot last year and never had any issues with it.
What are you using PWM for?
Also, I was unable to open and look at your VI because I don't have LabVIEW 2012 on this particular computer.
03-12-2013 06:15 PM
Hello Nathan,
Thanks for your help..Please see attached files for clarification. Yes, I did use LIFA 2.2.0.79 and currently, I am using a demo version of LabVIEW 2012 to see if I can get somewhere with it.
Based on what I understand, At-Mega 2560 is using Timer/Counter for PWM signal generation. PWM pin5 = OC3A, PWM pin2 = OC3B, & PWM pin3 = OC3C. But PWM pin4 is = OC0B which belongs to a different Timer/Counter set and that's why on my scope capture it shows Ch-3 (the blue trace) is missed aligned with the rest. Please kindly correct me if I am completely out of the alignment here.
Basically, I am trying to generate 4 PWM signals to exercise my DUT as follow:
Ch-1: is for a clocking purpose
CH-2 - Ch-4 are to just control the programming current for a three channels buck regulator with a different pulse width and delay to just see how/if can I break the part.
03-15-2013 03:51 PM
SydorlyLTNI,
You are correct that the channels use different clocks and that is why they are not synchonized.
Do you actually need the channels to by synchronized (this will be difficult) or could you do something like Set all PWM duty cycles to 0 (off)>>Start the clock>>Start the 3 channels that control power? If you explain your setup more we can provide some more recommendations.
-Sam K
-LIFA Developer
03-15-2013 06:28 PM
Hello Sammy_K,
Thanks for stepping in. To be honest, I am not that good in programming, that's why I like LabVIEW. It's takes a huge amount of time out of my headache and allow me to get my job done and achieving my goal in timely manner.
Back to your questions, yes.. I do need to synchronize the channels so that can get my start time to abuse my DUT at a known state, but if there's an alternative option(s) that would allow me to do what I want to do, I am open for that. Please do advise..
On the Arduino IDE side, I have been trying to generate the waveforms that I hope to have and also trying to "SYNCH" the TIMER together from the document and the discussion that I found, I am not able to accomplish the synchronization at all. Maybe I am not doing something correctly and it's entirely possible. Below is what/how my script looklike:
#include <avr/interrupt.h>
#include <util/delay_basic.h>
//GTCCR = (1<<TSM)|(1<<PSRASY)|(1<<PSRSYNC); // halt all timers
unsigned long time;
void setup()
{
Serial.begin(9600);
GTCCR = (1<<TSM)|(1<<PSRASY)|(1<<PSRSYNC); // halt all timers
int outputPsuB = 12; // Timer1-B
int outputPsuC = 13; // Timer1-C
// PSU outputs via timer1
pinMode(outputPsuB, OUTPUT); // select Pin as ch-B
pinMode(outputPsuC, OUTPUT); // select Pin as ch-C
TCNT0 = 0; // set timer0 to 0
TCNT1H = 0; // set timer1 high byte to 0
TCNT1L = 0; // set timer1 low byte to 0
TCNT2 = 0; // set timer2 to 0
// set all timers to the same value
GTCCR = 0; // release all timers
// GTCCR = (1<<TSM)|(1<<PSRASY)|(1<<PSRSYNC); // halt all timers
// GTCCR = B10000000; // Turning "ON" TSM: Timer/Counter Synchronization Mode
TCCR1A = B00101001; // Phase and frequency correct PWM change at OCRA
TCCR1B = B10011; // System clock / 1024 from prescaler
OCR1A = 7000; // 0.78125 Hz
OCR1B = 1000; // 75% PWM
OCR1C = 2000; // 5% PWM
// TCCR0A = TCCR0A & 0x3F; // disable OC0A from timer0
}
void loop()
{
Serial.print("Time: ");
time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send massive amounts of data
delay(0);
}
For a better explanation, I am attaching my waveforms sketch for your reference and thanks again for your response.
Hope to hear from you soon
Sy D.
03-18-2013 12:53 PM
I still have no clue as to what this device is that you are trying to control with PWM. It kind of feels like, to me, that we might be experiencing The XY Problem. Did I miss something?
03-18-2013 05:23 PM
Hello Nathan_B.,
Please accept my sincere apology for not being clear to you. If you are looking for an answer to what exactly the device that I am trying to test, there are some product proprietry on my DUT that I cannot share. The best I can tell you is what I am trying to achieve and it is what I can describe about the waveform that I have drawn and attached above:
a.) I am trying to generate 4 PWM signals to control my DUT.
b.) Signal-1 is a 50% duty cycle CLK from ~ 20Hz to 10KHz
c.) Signal-2, 3, & 4 are PWM signals that have the same frequency as the CLK but with an adjustable duty cycle of ~5% to 95% of the total period with programmable/controllable delay from when signal-1 beginning @ time zero.
The 4 signals that I am trying to generate are all output signals from the Arduino. I do not need to read anything back at all.
I hope this would make enough sense for you to relate to and hope you won't mind respond with some solution to help me out.
Sincerely,
Sy D.
03-19-2013 09:34 AM
Sy D,
I'll take a look at the code above when I get a chance, however I think what Nathan was asking is for a better description of the signals rather than the device. Specifically do the signals absolutly have to have synchronized periods? If you can tell us more about the signals or what they do to the device we might be able to help you figure out a work around that does not require synchronized signals.
On a side note, if your application does require tight synchronization you may want to consider a DAQ card. You can get a USB DAQ device that gives you much more control over many more channels and still control it using LabVIEW and DAQmx.
-Sam K
LIFA Developer
03-19-2013 11:36 AM
Hello Sammy_K and Nathan_B,
Very sorry if my description is not clear to you guys. Maybe it's my english problem, but let me try again.
My ultimate goal was to generate a total of 4 signals to control my DUT. The first signal is acting as a CLK and frequency needs to be as slow as ~20Hz up to as fast as 20KHz the most. Within that clocking period, I need to generate 3 PWM signals to control my DUT to do its job based on the part specification.
The 3 PWM signals are required to start at time "0" with the CLK at first and has to be able to adjust its duty cycle from ~5% to ~95% within that CLK period.
After that I need to delay the 3 PWM signals one at a time, but still remain the same frequency as the CLK and do not have to be operating within the same CLK period.
Now I am encountering problems that Arduino could not provide such as more than 3 signals SYNCHing, I can change the frequencies but the duty cycle is only 50%, I can control the duty cycles but the frequency is fixed, and I cannot generate time delay on any of my 3 PWM signals.
I hope this is clear enough for you to see what I mean.
Regards,
Sy D.
03-20-2013 08:46 AM
Sy D,
As far as I know the arduino doesn't really offer this kind of functionality as a 'feature'. While it is common for microcontrollers to allow you to synchronize clocks / PWM signals they often are not robust enough to provide tight control over the timing delays between channels. You might be able to get this to work (I'm not sure exactly how off the top of my head) but what you really need is a DAQ card.
-Sam K
LIFA Developer