Recent Posts

Pages: [1] 2 3 ... 10
1
Code: [Select]
#include <digitalWriteFast.h>

//Arduino will be interface with a DAC to generate pulse sequenses with charactaristics determined by the user through serial monitor.
//The DAC is a 2 channel (L.OUT, R.OUT) 16 bit serial input DAC. the Pins Clk, LRCk and SI are assigned by the arduino.
//Clk:Clock
//SI:Serial input
//LRCK: when it goes from low to high (high to low), the SI from the previous 16 clocks determines R.OUT (L.OUT).
//both DAC outputs are first shifted to 0-2 volt. L.Ch is inverted and then added to the R.ch

//Input: voltage(v), pulse width(ms), inter phase (ms), frequency(Hz), number of pulses, delay(ms)

int d1=1;//0.25 of the clock period.
int d2=d1*2;// 0.5 of the clock period. (Clock pulse width)

int Clk = 2 ; // Pin 2 for Clk
int LRCk = 6 ; //Pin 4 for LRCk
int SI = 3 ;  //Pin 3 for SI for channel 1
int SI_2 = 5; //Pin 3 for SI for channel 2

void setup() {
  Serial.begin(9600);
  pinMode (Clk,OUTPUT);
  pinMode (LRCk,OUTPUT);
  pinMode (SI,OUTPUT);
  pinMode (SI_2,OUTPUT);
}

void loop() {

     digitalWriteFast(LRCk,0);
     digitalWriteFast(Clk,0);
    
     WriteRL(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,//before input, everything is zero.
            1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
        
  while (Serial.available() > 0) {

    float voltage_1 = Serial.parseFloat();     //Voltage amplitude
    float widthF_1  = Serial.parseFloat();     //Pulse width
    float interF_1  = Serial.parseFloat();
    int frequency_1 = Serial.parseInt  ();     //frequency of pulses
    int number_1    = Serial.parseInt  ();     //number of pulses
    int delayy_1    = Serial.parseInt  ();     //The delay before applying the pulse

    float voltage_2 = Serial.parseFloat();
    float widthF_2  = Serial.parseFloat();
    float interF_2  = Serial.parseFloat();
    int frequency_2 = Serial.parseInt  ();
    int number_2    = Serial.parseInt  ();  
    int delayy_2    = Serial.parseInt  ();    

    voltage_1 =  voltage_1*14563-32768;          //Mapping the desired voltage to the corresponding input of the DAC.
    voltage_2 =  voltage_2*14563-32768;  
    int voltageh_1  = (int) voltage_1;
    int voltageh_2  = (int) voltage_2;
    unsigned long widthN_1  = (unsigned long) (widthF_1*1000)/400+0.49; // 400 us is the time it takes widthN=1, based on experimenting
    unsigned long widthN_2  = (unsigned long) (widthF_2*1000)/400+0.49;
    unsigned long interN_1  = (unsigned long) (interF_1*1000)/400+0.49;
    unsigned long interN_2  = (unsigned long) (interF_2*1000)/400+0.49;
    unsigned long PeriodN_1 = (unsigned long) (1000000/frequency_1)/400+0.49;
    unsigned long PeriodN_2 = (unsigned long) (1000000/frequency_2)/400+0.49;
    unsigned long zerotimeN_1 =  PeriodN_1-2*widthN_1-interN_1;
    unsigned long zerotimeN_2 =  PeriodN_2-2*widthN_2-interN_2;
    unsigned long delayyN_1   =((1000.0*delayy_1)/400+0.49);
    unsigned long delayyN_2   =((1000.0*delayy_2)/400+0.49);
    unsigned long N = max( delayyN_1 + ((unsigned long)number_1)*PeriodN_1 , delayyN_2 + number_1*PeriodN_1);// N is the number of times the loop needs to run.

    unsigned long RHigh1_1 = delayyN_1; // R.out for channel 1 is high for RHigh1_1 < n < RHigh2_1 ( n : nth loop)
    unsigned long RHigh2_1 = RHigh1_1 + widthN_1;
    unsigned long LHigh1_1 = delayyN_1 + interN_1 + widthN_1;
    unsigned long LHigh2_1 = LHigh1_1 + widthN_1;
    
    unsigned long RHigh1_2 = delayyN_2;
    unsigned long RHigh2_2 = RHigh1_2 + widthN_2;
    unsigned long LHigh1_2 = delayyN_2 + interN_2 + widthN_2;
    unsigned long LHigh2_2 = LHigh1_2 + widthN_2;
    int state = 00 ; // R= high -> 1 / L= high -> 2 / R,L=0 -> 0 / 10s:ch1 1s:ch2
    
    int counter;
    int modulu;
    
    int o15_1 = bitRead(voltageh_1, 15); int o15_2 = bitRead(voltageh_2, 15); //MSB
    int o14_1 = bitRead(voltageh_1, 14); int o14_2 = bitRead(voltageh_2, 14);
    int o13_1 = bitRead(voltageh_1, 13); int o13_2 = bitRead(voltageh_2, 13);
    int o12_1 = bitRead(voltageh_1, 12); int o12_2 = bitRead(voltageh_2, 12);
    int o11_1 = bitRead(voltageh_1, 11); int o11_2 = bitRead(voltageh_2, 11);
    int o10_1 = bitRead(voltageh_1, 10); int o10_2 = bitRead(voltageh_2, 10);
    int o9_1  = bitRead(voltageh_1, 9 ); int o9_2  = bitRead(voltageh_2, 9 );
    int o8_1  = bitRead(voltageh_1, 8 ); int o8_2  = bitRead(voltageh_2, 8 );
    int o7_1  = bitRead(voltageh_1, 7 ); int o7_2  = bitRead(voltageh_2, 7 );
    int o6_1  = bitRead(voltageh_1, 6 ); int o6_2  = bitRead(voltageh_2, 6 );
    int o5_1  = bitRead(voltageh_1, 5 ); int o5_2  = bitRead(voltageh_2, 5 );
    int o4_1  = bitRead(voltageh_1, 4 ); int o4_2  = bitRead(voltageh_2, 4 );
    int o3_1  = bitRead(voltageh_1, 3 ); int o3_2  = bitRead(voltageh_2, 3 );
    int o2_1  = bitRead(voltageh_1, 2 ); int o2_2  = bitRead(voltageh_2, 2 );
    int o1_1  = bitRead(voltageh_1, 1 ); int o1_2  = bitRead(voltageh_2, 1 );
    int o0_1  = bitRead(voltageh_1, 0 ); int o0_2  = bitRead(voltageh_2, 0 );//LSB
    
    if (Serial.read() == '\n') {        //Now that the user has entered an input,
      
      counter=0;  
      while (counter<N){ // Based on the counter, it is determined what state each channel is in.
        modulu=counter%PeriodN_1;
        if(modulu>=RHigh1_1 && modulu<=RHigh2_1){
          state=10;
        } else if(modulu>=LHigh1_1 && modulu<=LHigh2_1){
          state=20;
        } else {
          state=0;
        }

        modulu=counter%PeriodN_2;
        if(modulu>=RHigh1_2 && modulu<=RHigh2_2){
          state=state+1;
        } else if(modulu>=LHigh1_2 && modulu<=LHigh2_2){
          state=state+2;
        }
      
        switch (state){
          case 00:
            WriteRL(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
            break;
          case 10:
            WriteRL(o15_1,o14_1,o13_1,o12_1,o11_1,o10_1,o9_1,o8_1,o7_1,o6_1,o5_1,o4_1,o3_1,o2_1,o1_1,o0_1,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);          
            break;
          case 20:
            WriteRL(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    o15_1,o14_1,o13_1,o12_1,o11_1,o10_1,o9_1,o8_1,o7_1,o6_1,o5_1,o4_1,o3_1,o2_1,o1_1,o0_1,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);          
            break;
          case 01:
            WriteRL(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    o15_2,o14_2,o13_2,o12_2,o11_2,o10_2,o9_2,o8_2,o7_2,o6_2,o5_2,o4_2,o3_2,o2_2,o1_2,o0_2,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);          
            break;
          case 11:
            WriteRL(o15_1,o14_1,o13_1,o12_1,o11_1,o10_1,o9_1,o8_1,o7_1,o6_1,o5_1,o4_1,o3_1,o2_1,o1_1,o0_1,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    o15_2,o14_2,o13_2,o12_2,o11_2,o10_2,o9_2,o8_2,o7_2,o6_2,o5_2,o4_2,o3_2,o2_2,o1_2,o0_2,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);          
            break;
          case 21:
            WriteRL(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    o15_1,o14_1,o13_1,o12_1,o11_1,o10_1,o9_1,o8_1,o7_1,o6_1,o5_1,o4_1,o3_1,o2_1,o1_1,o0_1,
                    o15_2,o14_2,o13_2,o12_2,o11_2,o10_2,o9_2,o8_2,o7_2,o6_2,o5_2,o4_2,o3_2,o2_2,o1_2,o0_2,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);          
            break;
          case 02:
            WriteRL(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    o15_2,o14_2,o13_2,o12_2,o11_2,o10_2,o9_2,o8_2,o7_2,o6_2,o5_2,o4_2,o3_2,o2_2,o1_2,o0_2);          
            break;
          case 12:
            WriteRL(o15_1,o14_1,o13_1,o12_1,o11_1,o10_1,o9_1,o8_1,o7_1,o6_1,o5_1,o4_1,o3_1,o2_1,o1_1,o0_1,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    o15_2,o14_2,o13_2,o12_2,o11_2,o10_2,o9_2,o8_2,o7_2,o6_2,o5_2,o4_2,o3_2,o2_2,o1_2,o0_2);        
            break;
          case 22:
            WriteRL(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    o15_1,o14_1,o13_1,o12_1,o11_1,o10_1,o9_1,o8_1,o7_1,o6_1,o5_1,o4_1,o3_1,o2_1,o1_1,o0_1,
                    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    o15_2,o14_2,o13_2,o12_2,o11_2,o10_2,o9_2,o8_2,o7_2,o6_2,o5_2,o4_2,o3_2,o2_2,o1_2,o0_2);          
            break;  
        }
        counter++;
      }
    }
  }
}
2
Le bar / Re: [INFO] 26e réunion de la C...
Last post by 68tjs - Today at 05:11 pm
Quote
çà ne va pas changer la vie du Forum
Oh que si ! :smiley-mr-green: :smiley-mr-green:
La définition de l'unité de masse utilise depuis vendredi la constante de Planck.

Les articles dans les différents journaux français et étrangers ont permis de vérifier que les journalistes sont toujours aussi nuls en physique : comme d'hab confusion totale entre la masse m (invariable) et le poids p= mg (variable puisque g varie avec l'altitude).
3
Project Guidance / Re: rev counter with DAC
Last post by Robin2 - Today at 05:09 pm
Yes it is on an Arduino mega.
Please post the program.

...R
4
Bar Sport / Re: is Shannon GOD ?
Last post by larryd - Today at 05:07 pm
"Far from heaven, she is."   

Yoga?   :)




5
Project Guidance / Re: RF relay (receiver) and Ar...
Last post by exrlkr - Today at 05:04 pm
Thanks, I'll give it a try with Mega and transmitter and switches.

Meanwhile I recorded two videos. First video displays everything correct right after relays learned codes from fabric remote control.

Then I clicked a few minutes manually by remote control.

Second video at 0:16 displays strange behavior (turning on and off uncontrollably) when I hold button B which should just turn relay off (and worked on first video). Also notice at 0:21 that one of the relays didn't turned on when I pressed button A (which worked on first video).

Just a note I have already working controlling of my home lights from parking lot by the very same fabric remote control and mega+receiver and controlling of led stripe behind tv by mega+transmitter and nano+receiver+mosfet transistor. I;m trying to say something is already working correctly but relays don't.
6
Post some picture with your setup. Something must be wrong. If you have 10uF cap between RESET and GND on Arduino (source/programmer) then -carduino is OK.
 
Mega uses different pins but if you are using ISP connector it is the same. ISP connector is identical.
No. The log doesn't point to. Are you able load sketch?...
No, it doesn't help. Uploading via serial is able only with the bootloader.
You can try to use command from log directly from CMD or edit programmers.txt: "arduinoasisp.protocol=stk500v1"

It looks like I was using the pin out for the nano. I fixed that and tried again and the same thing. I also tried to edit the programmers.txt and the same result. I added attachments of my setup.
7
I have connected all grounds to each other and my psu can deliver 5A max.
8
General Electronics / Help identify a laser diode
Last post by cloxart - Today at 05:00 pm
Hello everyone,
I need to change a laser diode but all that is written on it is Q 8C on the bottom (nothing on the side) (picture attached)
anyone have any idea on how to find a suitable replacement?

Thank you!
9
Project Guidance / Re: Approach to control 9 mode...
Last post by DanLRC - Today at 04:58 pm
Hi Dave,
Thanks for all the time and feedback. I'll try to digest it all.
I'll post a detailed schematic for eval soon.

I understand the distinction between max and expected.  But since I don't expect to ever use all the components at once (maximum), is not the expected value good to use for board selection?  Just as I would not expect to plug in five 1200W hair dryers on one 15A house circuit.  Am I still missing something here?  All external components except 9 LEDs will be separately powered.

The pin plan I posted was only to show pin assignment, not meant to be a complete schematic.
Question - for "start" input from the RC receiver, I indicated using the RX0 input pin on the Mega.  Haven't researched that yet, but is that the best to use?

Also, for about US$10 I can get Mega boards from our friends in China...I'll probably buy three and expect to possibly lose one in the learning curve.

The reason for the 6V supply is that a 12V SLA battery and a dedicated V regulator will be the power source for the board.  I may kick that up to a 7 or 8V regulator, per the spec below.
The spec for the board power is:
"The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may become unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts."

I have three relay boards...3x8=24 total relays.

Only the LEDs will be directly powered by the Mega.
Air relays and heat relays will be separately powered...both coil side and switched power.  So I was wrong in saying the board would supply the coil load.  I was thinking a bare relay, not the relay board spec. for the logic input.

Still learning....like boot camp....thank you, drill sargeants....

wildbill...I am shocked, too, that I am even thinking about all this.... :o
10
Tutoriels et cours / Re: printf
Last post by kamill - Today at 04:57 pm
Bonjour,

Vraiment très intéressant.
Par contre le lien dans ton premier post ne fonctionne pas.
Pages: [1] 2 3 ... 10