Arizona
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« on: October 19, 2011, 10:53:37 pm » |
I am making a pulse generator for a camera speed control. The signal is in frames per second and is from 20 frames per second to 200 Frames per second.
The pulse is a 1 degree (1/360th) of the Frequency period.
I am using an Arduino Nano 3.0 from Gravitech.
I have no bypass capacitors on my 9V battery or on the board.
here is a picture of two channels (A and B from two separate digital IO pins). They are 3 degrees offset from each other. My Rigol DS1052E shows lots of noise and not quite a square wave here. I'm wondering if the input leads or some other factor is causing the signal noise.
Here is a picture of my output on the scope for a 30 HZ signal ...
Any help in getting these to be very square would be great.
|
|
|
|
|
Logged
|
Brent Finley
|
|
|
|
Topsham, Vermont USA
Offline
Edison Member
Karma: 16
Posts: 1470
... in The Woods In Vermont
|
 |
« Reply #1 on: October 20, 2011, 01:34:13 am » |
Hmmm. looks unusual, brent...
what is the load on this?? Those periods of slope are funny..
what's your code?? Are you doing anything else with the pins like Pinmode inside your loop??
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
|
 |
« Reply #2 on: October 20, 2011, 02:16:20 am » |
What does the trace from the calibration output on the scope look like?
Can we see the code?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
|
 |
« Reply #3 on: October 20, 2011, 03:09:20 am » |
One possible explanation for the shapes is that you are changing the pin mode from input to output. Are you using direct port manipulation and have got the code wrong or have you not set those pins to be an output in the setup function?
|
|
|
|
|
Logged
|
|
|
|
|
Arizona
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #4 on: October 20, 2011, 08:41:45 pm » |
Here is the relevant code:
pinModeFast(sync1, OUTPUT); pinModeFast(sync2, OUTPUT); pinModeFast(onled, OUTPUT); pinModeFast(outled, OUTPUT);
while (digitalReadFast(buttonmode) == 0){ // as long as the mode button is off. // put out our pulse digitalWriteFast(outled, HIGH); digitalWriteFast(onled, LOW); // invert the ON LED digitalWriteFast(sync1, HIGH); if (offset == 0) digitalWrite(sync2, HIGH); delayMicroseconds(p1); // now turn off and wait. digitalWrite(outled, LOW); digitalWrite(onled, HIGH); // invert the ON LED digitalWrite(sync1, LOW); if (offset == 0) digitalWriteFast(sync2, LOW); delayMicroseconds(d1); // do the remainder for ( int x = 0; x < nd1; x++){ // loop over 16000 n times. delayMicroseconds(16000 - loopcomp); // subtract a fixed compensation from the delay for loop overhead } if (offset != 0){ // put out our 2nd pulse digitalWriteFast(sync2, HIGH); delayMicroseconds(p1); // now turn off and wait digitalWriteFast(sync2, LOW); delayMicroseconds(d2); // do the remainder for ( int x = 0; x < nd2; x++){ // loop over 16000 n times. delayMicroseconds(16000 - loopcomp); // subtract a fixed compensation from the delay for loop overhead } } } // end while button not on.
The connection from my project box to the scope is a simple shielded coax cable (about 8 feet long). There are two outputs... one on Sync1 and one on Sync2.
|
|
|
|
|
Logged
|
Brent Finley
|
|
|
|
Arizona
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #5 on: October 20, 2011, 09:22:12 pm » |
I changed to use the regular digitalWrite and here is channel B alone (the same picture as before is what I get).
It just seems like the coax is acting like a big capacitor.
I guess I'll have to test the signal with a probe lead directly.
|
|
|
|
|
Logged
|
Brent Finley
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
|
 |
« Reply #6 on: October 21, 2011, 02:59:43 am » |
Please post code using the # icon. Also posting part of the code is not much, experience shows that it is the bit you know is right where the fault lies. If the code is too long try and simplify it so that it just shows the fault, often that helps you spot what is wrong. Again to me that trace looks like a high output being switched to an input. If it were capacitance it would show on the rise time as well.
|
|
|
|
|
Logged
|
|
|
|
|
Arizona
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #7 on: October 22, 2011, 01:48:56 pm » |
#include <string.h> #include <SoftwareSerial.h> #include <avr/pgmspace.h> #include <EEPROM.h>
const int buttonmode = 6; // the mode button is attached to const int buttonbacklight = 3; // backlight button const int buttondown = 5; // the up button const int buttonup = 4; // the down button const int buttonenter = 2; // the enter button const int outled = 10; const int sync1 = 8; const int sync2 = 9; const int onled = 7;
const int LCDtxpin = 12; const int LCDrxpin = 11;
const int pulsedegree = 1;
int debounce = 10; // debounce millisec delay
int repeatmillis = 80;
SoftwareSerial LCDSerial = SoftwareSerial(LCDrxpin, LCDtxpin);
unsigned int num16; // make this working var visible to other routines. // byte framerate = 30; byte loopcomp = 0; // loop compensation microseconds byte staticcomp = 0; // static overhead compensation byte backlight = 0; // state of the backlight button. unsigned int offset = 0; // degrees offset
unsigned long p1; // pulse width unsigned long d1; // delay width unsigned int nd1; // number of 16000 unsigned long d2; // remainder of delay2 unsigned int nd2; // number or 16000 unsigned long totalmicros; // total microseconds for this freq.
void setup() { pinMode(buttonmode, INPUT); pinMode(buttonbacklight, INPUT); pinMode(buttonup, INPUT); pinMode(buttondown, INPUT); pinMode(buttonenter, INPUT); pinMode(sync1, OUTPUT); pinMode(sync2, OUTPUT); pinMode(onled, OUTPUT); pinMode(outled, OUTPUT); pinMode(LCDrxpin, INPUT); pinMode(LCDtxpin, OUTPUT);
getvalues(); LCDSetup(); calcvalues(); }
void loop(){ if (digitalRead(buttonmode) == 1){ setparams(); } else { calcvalues(); runit(); } }
void runit() { // delayMicroseconds can only handle just over 16,000 counts, so // break this up into n x 16000 + a remainder. and delay with those parameters. //Serial.println("in");
clearLCD(); selectLineOne(); LCDSerial.print("FPS: "); LCDSerial.print(framerate,DEC); selectLineTwo(); LCDSerial.print("PHASE DEG: "); LCDSerial.print(offset,DEC);
while (digitalRead(buttonmode) == 0){ // as long as the mode button is off. // put out our pulse digitalWrite(outled, HIGH); digitalWrite(onled, LOW); // invert the ON LED digitalWrite(sync1, HIGH); if (offset == 0) digitalWrite(sync2, HIGH); else digitalWrite(sync2, LOW); delayMicroseconds(p1); // now turn off and wait. digitalWrite(outled, LOW); digitalWrite(onled, HIGH); // invert the ON LED digitalWrite(sync1, LOW); if (offset == 0) digitalWrite(sync2, LOW); delayMicroseconds(d1); // do the remainder for ( int x = 0; x < nd1; x++){ // loop over 16000 n times. delayMicroseconds(16000 - loopcomp); // subtract a fixed compensation from the delay for loop overhead } if (offset != 0){ // put out our 2nd pulse digitalWrite(sync2, HIGH); delayMicroseconds(p1); // now turn off and wait digitalWrite(sync2, LOW); delayMicroseconds(d2); // do the remainder for ( int x = 0; x < nd2; x++){ // loop over 16000 n times. delayMicroseconds(16000 - loopcomp); // subtract a fixed compensation from the delay for loop overhead } } } // end while button not on. }
// ------------ button functions
boolean buttonIn(int button){ int isdown = digitalRead(button); if (isdown == 0){ repeatmillis = 100; return false; } delay(debounce); isdown = digitalRead(button); if (isdown == 0){ repeatmillis = 100; return false; } long starttime = millis(); // 100 milliseconds max, and repeat while (millis() - starttime < repeatmillis && digitalRead(button) == 1){ // hangout } repeatmillis = 5; // repeat-amatic rate return true;
}
// ----------- below here is all lcd stuff
|
|
|
|
|
Logged
|
Brent Finley
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
|
 |
« Reply #8 on: October 22, 2011, 02:02:06 pm » |
There is nothing in that code that would cause that waveform to be produced. Have you tried just measuring the pulse with nothing else connected to it?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Arizona
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #10 on: October 22, 2011, 04:52:32 pm » |
you know... when I put the probe onto the outLED across the 330 ohm resistor, it's nice and square.... when I put it on the pin for the sync, it shows that decay curve.
I do have protection diodes to prevent signals from either sync output (they are on different cameras) to cause any havoc..
I wonder if my board (and the diodes on those outputs) are causing any issue.)
I'll have to tear it all down and look closely....
Weird.
|
|
|
|
|
Logged
|
Brent Finley
|
|
|
|
Arizona
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #11 on: October 22, 2011, 10:33:31 pm » |
The Radio Shack 1N4003 diode seems to be my problem. http://www.radioshack.com/product/index.jsp?productId=2036269I am isolating my A and B channels with diodes. So the signal is going through Ground -> diode -> (negative signal to output and scope) Arduino Output pin (Positive signal). When I take signal from the Ground... the square wave is true. I did not know that a Diode would act as a capacitor? Can I find an extremely low capacitance diode? Brent
|
|
|
|
|
Logged
|
Brent Finley
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #12 on: October 23, 2011, 02:59:51 am » |
|
|
|
|
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 146
Posts: 4906
|
 |
« Reply #13 on: October 23, 2011, 03:12:41 am » |
Try putting a load resistor (say 1k or 10k) between the positive and negative "output" points. Currently, the only load is your scope probe, which will be 1M or 10M.
Also consider using a signal diode such as the 1n4148 instead of a power diode like the 1n4003, unless you have a particular reason for using a power diode.
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
Topsham, Vermont USA
Offline
Edison Member
Karma: 16
Posts: 1470
... in The Woods In Vermont
|
 |
« Reply #14 on: October 23, 2011, 06:36:41 am » |
Sure, the diode is the problem...
The current goes ONE way and charges the cable up fast, but when the arduino output goes Low, it's not connected in the reverse connection and you get a capacitive discharge..
NOW we understand !
|
|
|
|
|
Logged
|
|
|
|
|
|