Arduino Forum

Using Arduino => Project Guidance => Topic started by: marathonMAN1 on Aug 24, 2019, 12:42 am

Title: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Aug 24, 2019, 12:42 am
I need and will build a circuit to control an Inductive device at 60 cycles per second which will have 46 taps that will mimic a brush rotating at 3600 RPM.  1 second= 1000 ms divided by 60 RPS = 16.66 ms per revolution which divided by 46 taps = .352 ms = 352 microseconds of on time per tap. what i can not come up with is how to code an Arduino to switch a CD40110BE to pulse up then down at the right time. i channel to pulse up and one channel to pulse down plus ground.

i attached the circuit but didn't figure out how to post it in the post.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: Paul__B on Aug 24, 2019, 12:48 am
i attached the circuit but didn't figure out how to post it in the post.
That's OK.  Easy enough.  :smiley-lol:
(https://forum.arduino.cc/index.php?action=dlattach;topic=632901.0;attach=321654)
Click to expand. (https://forum.arduino.cc/index.php?action=dlattach;topic=632901.0;attach=321654)
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Aug 25, 2019, 02:48 am
Thank you much.
what i was thinking is the Arduino even fast enough to trigger the duel inputs  at microseconds of time... i think not, what else can i do?
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: TomGeorge on Aug 25, 2019, 07:03 am
Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html  (http://forum.arduino.cc/index.php/topic,148850.0.html). 


Can you post the code that you have now please?


Thanks.. Tom.. :)
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: Paul__B on Aug 25, 2019, 09:47 am
The clock interval of the Arduino is 62.5 nanoseconds.

What do you mean by "fast enough to trigger the duel inputs".
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: lastchancename on Aug 25, 2019, 11:40 am
Are you just trying to walk one bit across all the outputs ?
If that's the case, you may find it easier to use shift-registers (like the venerable 74xx595 family.

You create your bit pattern in an array, then pump it out each time you want change the register output bits.
For 'up' counts, that's as easy as ticking one bit at a time, for 'down' counts, either a bidirectional SR, or simply shift the long contents, and push that out to the 595s.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Aug 26, 2019, 02:22 am
Mr Tom i did and i am still short on what you mean.

as for the code i haven't attempted because of the confusion on my part. the circuit will drive an IGBT/Transistor driver that is 3.3 and 5 volt tolerant so that is one less problem.

"Are you just trying to walk one bit across all the outputs ?"
yes i am but the channels have to be a make before break scenario. meaning one is fully on before the other shuts off. reason is no current interruption so no back emf.
i never thought about that shift register implementation.  another thing is the ends of the controller has to be on for three times as long then the ones in the middle to get an Inductive roll off in my controller.
sounds confusing but it is not just need the proper switching and coding and  am good to go.
Thank you all for the time and effort.
I think i brain farted on the frequency timing.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: lastchancename on Aug 26, 2019, 02:46 am
With the make-before-break timing, you're good with simple shift registers.

Form your bit pattern:  all_off-1-12-2-23-3-34-4 etc in the shift register, pump it out, then at the moment, pulse  the SR output latch.  Rinse and repeat while the SR outputs are latched in the current state.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: TomGeorge on Aug 26, 2019, 04:00 am
Hi,

Can you clarify exactly what we are working on here?

Title;   Using Arduino to Control CD40110BE up down clock.

First line; "I need and will build a circuit to control an Inductive device at 60 cycles per second which will have 46 taps that will mimic a brush rotating at 3600 RPM."

How are they connected?
What is the application?

Tom..... :o
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 02, 2019, 08:32 pm
i will have taps coming off the inductor 46 of them that are connected to an IGBT and drivers that is connected to the above circuit or a shift register. it must be make before break scenario meaning the next in line is fully up before the last one cuts off. this is to ensure a steady current flow through the Inductor.

on each end of the Inductor i have electromagnets that are varied from high to low 180 degrees out from each other, one rising, one falling at the same time. the electronics is to mimic a brush rotating in a circle that make contact with two contacts at a time which are actual loops of wire around the Inductor that changes the magnetic flux to current ratio on a steady basis.

for the 40110be it will have two inputs to the arduino but for the shift register i need to calculate how many inputs i will have.

lastchancename; got any ideas on a cheap shift register.
i am at a loss when coming up with a program to control the two inputs to the up and down pins on the 49110be.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: johnwasser on Sep 02, 2019, 08:51 pm
The CD40110B is NOT a shift register.  It's a decade counter (0-9) with 7-segment display outputs.

http://www.ti.com/lit/ds/symlink/cd40110b.pdf (http://www.ti.com/lit/ds/symlink/cd40110b.pdf)

Unless your "Inductive device" is a 7-segment display you are NOT going to have much luck driving it with a 7-segment driver.  What made you think this counter/driver was suitable for your device?!?


Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 02, 2019, 09:11 pm
I suspect the OP meant to use CD4017 decade counter but got seriously confused at some point.

Quote
it must be make before break scenario
Does CD4017/40110 guarantee that? I don't know...

I too would suggest 6 x 74hc595. Connect these to the SPI pins of the Arduino so they can be updated at high speed (8MHz clock). Then you can guarantee make-before-break by sending the required patterns of bits in your sketch. But will even that be fast enough?

Another option could be a Mega. 46 pins could be updated at high speed using direct port manipulation.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: lastchancename on Sep 02, 2019, 09:19 pm
Quote
i am at a loss when coming up with a program to control the two inputs to the up and down pins on the 49110be.
While not complicated (yet), it sounds like you may be better off moving this thread to Gigs & Collaborations, where someone can work with you to develop a solution.

Depending on your expectations, and the helper, it could require payment.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: johnwasser on Sep 02, 2019, 11:07 pm
The problem with using CD4017 counters is trying to cascade them.  Like the CD40110, each chip represents one digit.  You get one output per chip.  To count off 46  outputs you have to AND the 10 "ones digit" outputs with each of the first five of the "tens digit" outputs.  That's 47 2-input AND gates you need...  and a LOT of wiring.  You could then count from 00 to 46 and reset at 47.

If you want a moving bit, the shift registers (6*8 or 3*16) will eliminate the need for 47 AND gates.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: TomGeorge on Sep 03, 2019, 04:02 am
i will have taps coming off the inductor 46 of them that are connected to an IGBT and drivers that is connected to the above circuit or a shift register. it must be make before break scenario meaning the next in line is fully up before the last one cuts off. this is to ensure a steady current flow through the Inductor.

on each end of the Inductor i have electromagnets that are varied from high to low 180 degrees out from each other, one rising, one falling at the same time. the electronics is to mimic a brush rotating in a circle that make contact with two contacts at a time which are actual loops of wire around the Inductor that changes the magnetic flux to current ratio on a steady basis.
So 46 taps on EACH inductor.
Each tap has an IGBT on it?
So you will have your inductor connected to a powersupply at the start of its winding and with IGBTs connect each tap in turn with the other end of the powersupply?
What voltage/current and how is your inductor constructed?
How many inductors?
Can you post a basic diagram of how your project will be constructed?
Thanks.. Tom.. :)
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 11, 2019, 01:26 am
I thought the CD40110B will work because it has an count up/down, cascade  features that allows it to count up which changes the tap position on the inductor which changes the inductance of both side of the inductor. then count down using the very same tapes to change the inductance the other way. all the taps are on the same inductor and since it is the positive side and two are on at a time there will be two north face magnetic fields at the two taps that are constantly moving. what this does is separate the one big inductor in two halves with one side increasing in current and the other side reducing in current in complete unison which is simple physics.

the pic below is the taps on the inductor which does not show all 46 taps for space reasons. the taps are positive side taps and at the bottom after the electromagnets is the negative side connection.

all this circuit does is vary the current through the two end feed connection of the inductor that mimic a brush rotating in a circle but change the inductor tap locations instead which causes Inductive reactance ie a current change of both feeds on either end of the inductor.
all i need to do is figure out how the timing of the two signal wires to the Arduino one being up and the other down plus ground, will be. for one revolution of a rotating brush will be 16.66 ms so that time has to be divided by 48  because one of the end channels are switched twice because of the up then down switching. this is good because that is what i need it to be.
each tap is on for .347 ms each which is divided by 48 channels of which will equal 16.666 ms of one revolution. does that mean a CD40110 b will not work and i am forced to use a cascade shift register. here i thought it will count up then down like it says in the Instructions.

i hope you can understand this with the help of the pic.

(https://i.postimg.cc/Yqzh4cTm/Iron-core-inductor-taps.jpg)
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 11, 2019, 08:15 am
CD4017 does not do what you think it does, not what you want. You must have misinterpreted the "instructions" (data sheet?)

Shift registers (74hc595) will do what you want. 4 Arduino pins will be needed for clock, data, latch and output enable (to ensure break-before-make).

How much current will be flowing? If less than 150mA, maybe tpic6b595 could be used instead, removing the need for igbts.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 11, 2019, 06:18 pm
johnwasser and PaulRB you are completely correct, i totally misunderstood the function of the CD40110. so i did some further research and both of you are correct in your assumptions that i need to use the 74HC595 in cascade fashion. fantastic chip and a perfect fit for this project, THANK YOU BOTH.

i can then cascade (6)  74HC595's to get my needed 46 channels timing them up then down.

PaulRB; that is make before break which is the leading channel on before the lagging one shuts off. also i will be using 1.4 amps peak of current @ 100 plus volts DC through the transistor.  i might want to switch to a logic level NPN to switch a  high power PNP to make it easy on me instead of having to use high side drivers.

i am working on the timing circuit right now using the 74HC595 in a sop 16 package that i will have connected to a Tensy 3.6.  it is on a Tall Dog break out board but i can take that off and mount it to my timing board.

then comes the fun part of coding.

Arduino community is awesome, thanks guy for all the help.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 11, 2019, 08:43 pm
Quote
that is make before break which is the leading channel on before the lagging one shuts off.
Ah, sorry. In that case, don't bother with an Arduino pin for Output Enable, just tie it to ground. You will need to send data to the shift registers at twice the anticipated rate, so be sure to use hardware SPI pins for speed.

Quote
i might want to switch to a logic level NPN to switch a  high power PNP to make it easy on me instead of having to use high side drivers.
Sounds like you are confused about types of transistors. NPN & PNP are BJT transistors, switched by current not voltage, so there is no such thing as a "logic-level NPN", they are all logic level. I suspect you meant to say logic level n-channel mosfet. But if you are switching high-side, is a p-channel MOSFET you want. You could control the p-channel MOSFET's gate with an npn bjt. If you do that, consider the tpic chip again. That would save you 46 npn-transistors, because the tpic chips could drive the p-channel MOSFET gates directly.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 11, 2019, 08:49 pm
Checking your diagram again, I don't think you do want high-side switching or p-channel MOSFETs or PNP BJTs. You want logic-level n-channel MOSFETs, which you can directly control with 74hc595 outputs.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 12, 2019, 01:15 am
That is what i was talking about was Enhanced MOSFET i just forgot to add that as i was out the door.
the switching has to be done on the high side only.  so i can use cheap  logic level capable  NPN MOSFET triggering PNP MOSFET.
this way as you say can be directly controlled by the logic level N channel Mosfet.
I can not use the N channel MOSFET on the high side without a driver and that is a lot more parts i do not want to spend on.
the BJt is current controlled and the shift register does not put out that kind of current so it has to be a logic level N channel MOSFET.

in your opinion what would be the cheapest way out using a high side switching scenario.
Thanks again.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 12, 2019, 07:30 am
Can you draw a schematic showing a few of the coils and high-side switches please? Based on your previous diagram, which I still find confusing, I'm not getting what you are saying about the need for high side switching.

I think I may have misunderstood your diagram. I interpreted the grey rectangles on the right and left, with the orange stripes on each side, as batteries, with their positive terminals connected to the ends of the coil and the two negative terminals connected together. But now I think they are something else. This is why a proper schematic would be helpful. They are, if done correctly, much less ambiguous.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 12, 2019, 08:04 am
The closed core  in the middle is an active Inductor with 46 positive taps. the ends of the inductor are connected to electromagnets on either side which then are connected to the negative of the power supply.
when i sweep the taps back and forth i am changing the magnetic flux to current ration which in turn creates Cemf that opposes the current flow of both feeds through the electromagnets

with this active inductor i can vary the current flow of two feed on either side of the inductor 180 degrees out from each other but in complete unison.

what i need to do know is or figure out how to switch on PNP MOSFETS with such low voltage coming from the 74HC595's or at least come up with a solution.

with PNP's will i still need a driver to turn them on.

(https://i.postimg.cc/RZyyws27/Iron-core-inductor-taps.jpg)
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 12, 2019, 07:14 pm
The 74hc595 outputs would need to drive npn bjt transistors or small n-channel FETs with logic level gates. Each bjt/fet, when switched on, would pull the gate of a large p-channel MOSFET down to ground to switch the MOSFET on. When the bjt/fet is off, the p-channel MOSFET's gate would be pulled up to high voltage, with a resistor, to switch it off.

Earlier, I suggested that this could be simplified by using tpic6b595 instead of the 74hc595. The idea was that the tpic chip's outputs could drive the p-channel MOSFET gates directly. The pull-up resistors would still be needed, but the bjt/n-channel fet would not be needed. In logic terms, the tpic chips are identical to 74hc595, but their outputs won't be damaged by high(er) voltages. The 74hc595 can't be connected to high voltages, which is why the bjt/n-channel FETs are needed with that chip. HOWEVER, the tpic chips are only rated up to 50V, and you are talking about 100V+, so the tpic chips won't be suitable. You will need to find npn bjt or n-channel FETs rated for over 100V to drive the gates of your p-channel MOSFETs (which must also be rated over 100V).
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 13, 2019, 12:34 am
Awesome ! Thank you PaulRB  very much for everything.
i was wondering if i shouldn't throw in a opto isolator in the mix to protect the IC's. i even found 300 volt opto's.

here is the code for the sketch i found that i can add to to switch multiple 74HC595B's shift registers. right now it is at 16 LED's.

 
Code: [Select]

/* Test circuit of the 74HC595B shift register serial to parallel Converter
   16 Leds in sequence up then back by Derek Mallow.
*/

const int clockPin = 9;  // Clock Sequence
const int hdataPin = 8;  // MS byte Serial data line
const int ldataPin = 11; // LS byte Serial data line
const int latchPin = 10; // Latch Pin

void setup() { // happens once on startup
  pinMode(clockPin, OUTPUT);
  pinMode(hdataPin, OUTPUT);
  pinMode(ldataPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
}

  void loop() {
    for (int i=0; i<16; i++)
    {
      if(i<8)shiftOut(ldataPin, clockPin, MSBFIRST, B00000001 << i);
      else shiftOut(hdataPin, clockPin, MSBFIRST, B00000001 << i-8);
      digitalWrite(latchPin, HIGH);
      delay(62);
      digitalWrite(latchPin, LOW);
    }
      for (int i=0; i<16; i++)
  {
      if(i<8)shiftOut(hdataPin, clockPin, MSBFIRST, B10000000 >> i);
      else {
      shiftOut(hdataPin, clockPin, MSBFIRST, B00000000);
      shiftOut(ldataPin, clockPin, MSBFIRST, B10000000 >>i-8);
      }
      digitalWrite(latchPin, HIGH);
      delay(62);
      digitalWrite(latchPin, LOW);
      }
  }


i copied it off of a video on youtube and compiled it and it worked so all i have to do is follow the format he used and add more shift register data lines. i have the circuit already done in DipTrace with 46 channels shifted right then left,  now all i need to do is the recoding.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 13, 2019, 08:25 am
Thet sketch may be ok for initial testing, but as I said earlier, given the timings you mentioned in your first post, you need to be using the Arduino's hardware SPI, because shiftOut() is very slow by comparison.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 13, 2019, 05:20 pm
Yes the whole sequence has to happen at 60 times a second and i am unaware of the speed of the shiftOut. do you happen to know the limitation of shiftOut.???? can shiftOut do micoseconds.??? can Tensy's shiftOut faster.???
the chip i will be using can hit 100 Mhz so then the limitation then falls on the Arduino.
EDIT;
each shift left then right has to happen in 16.66 ms so i thought shiftOut was fast enough.

i know nothing about hardware SPi so is there any information you can provide to help me in my quest. darn this really bites the bullet, i thought i had a winner.

Thanks so much.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 13, 2019, 05:38 pm
shiftOut() is implemented in software and you have no control over its speed. It will probably be somewhat faster on teensy 3.x compared to AVR based arduino, but I guess still not fast enough. I would expect the clock speed to be a few tens or low hundreds of KHz.

SPI hardware can perform the same function as shiftOut() but it is much faster. Its clock speed can go up to 8MHz even on a 16MHz Arduino. On teensy 3.x it will be faster again, especially if Direct Memory Access is used in conjunction with the SPI hardware. DMA is a feature of more advanced MCUs which can send out data through the SPI hardware while the CPU performs some other task, such as preparing the next batch of data.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: CrossRoads on Sep 13, 2019, 06:51 pm
Code: [Select]


/* Test circuit of the 74HC595B shift register serial to parallel Converter
   16 Leds in sequence up then back by Derek Mallow.
*/
// Edits by CrossRoads to use SPI
#include <SPI.h>


//const int clockPin = 9;  // Clock Sequence
//const int hdataPin = 8;  // MS byte Serial data line
//const int ldataPin = 11; // LS byte Serial data line
//const byte latchPin = 10; // Latch Pin
const byte latchPin = 8; // SS from Arduino


void setup() { // happens once on startup
  SPI.begin(); // default 4 MHz clock
  //13,SCK, to clock
  //11, MOSI
  //  pinMode(clockPin, OUTPUT);
  //  pinMode(hdataPin, OUTPUT);
  //  pinMode(ldataPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
}


void loop() {
  for (int i = 0; i < 16; i++)
  {
    if (i < 8) {
      digitalWrite (latchPin, LOW);
      SPI.transfer(B00000001 << i);
      digitalWrite (latchPin, HIGH);
    }
    else {
      digitalWrite (latchPin, LOW);
      SPI.transfer(B00000001 << i - 8);
      digitalWrite (latchPin, HIGH);


    }
    //      digitalWrite(latchPin, HIGH);
    delay(62);
    //      digitalWrite(latchPin, LOW);
  }
  for (int i = 0; i < 16; i++)
  {
    if (i < 8) {
      digitalWrite (latchPin, LOW);
      SPI.transfer(B10000000 >> i);
      digitalWrite (latchPin, HIGH);
    }
    else {
      digitalWrite (latchPin, LOW);
      SPI.transfer(B0000000);
      digitalWrite (latchPin, HIGH);
      digitalWrite (latchPin, LOW);
      SPI.transfer(B10000000 >> i - 8);
      digitalWrite (latchPin, HIGH);
    }
    //      digitalWrite(latchPin, HIGH);
    delay(62);
    //      digitalWrite(latchPin, LOW);
  }
}


I don't know if the delay(62) is needed  for display purposes.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 14, 2019, 12:30 am
The Nexperia 74HC595 has a shift out frequency of 100 mhz so that is comforting to know.
also a feature in the data sheet states the shift clock and the store clock can be tied together which then lags the store function (Latch) by one clock cycle so i am wondering if this can speed things up.

if not i might have to go to direct port manipulation which even a regular 16 Mhz Arduino can fit the bill.

CrossRoads;

this program i copied off of a video which it works well but i have not changed anything just yet, i wanted to get some advice on the program before doing anything else. i was just curious if the shiftOut and digitalWrite commands were fast enough to round trip 46 channels in 16.66 ms. well actually divided by 50 as the ends are on for three times longer. this works out to be 0.333 ms each channel with the ends 0.333 x 3  x 2 + 46 channels = 16.66 ms.

again Thank you very much.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: CrossRoads on Sep 14, 2019, 02:12 am
I had a sketch that used SCK at 8 MHz (used SPI clock divisor of 2, vs default of 4), and uploaded data to 45 shift registers at a 20 KHz rate (an update every 50uS).

16.66mS = 16,660uS.  Easily achievable I would think.
I used direct port manipulation for the SSpin low & highs; digitalWrite is way slower.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 14, 2019, 03:33 am
CrossRoads;

That sounds great, one thing i am forgetting though is i miss calculated badly. i was suppose to have a round trip if the channels and i only accounted for a one way trip. i know, i know how ignorant of me making that bad of a mistake.

the channels are 46 in total total so up and back will be 92 plus two added for the ends on longer so i have to divide 16.666 ms per revolution by 94 up and back total.

so now i have 16.666 ms per rotation of the channels up and back to mimic a rotating brush at 3600 rpm. so that leaves me with each channel on for .177 mS  or 177 uS each.

i would love to see the sketch CrossRoads or at least part if their is any way possible. i need to study port manipulation badly, been reading all day long on the subject. i didn't realize that replacing a rotating brush would involve so much work but the end result will be fantastic.

Thank you so very much.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: dougp on Sep 14, 2019, 03:44 am
I ask out of ignorance - what is the pattern of output bits going to look like?  It's repeating I assume, but it'll go through some sequence?
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 14, 2019, 08:16 am
Channels are overlapped with two always on at a time in Make Before Break.

Are you Doug Pine by the way.

pic is just for reference concerning the overlap only not the channels available.

(https://i.postimg.cc/GpVYWGXw/Signal-Overlap.png)
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 14, 2019, 08:28 am
In that case, in each 177us period, you would need to update 6x 74hc595 only once, to achieve make-before-break. So that's 48 bits in 177us. That's around 1 bit every 3us, a clock rate of ~333KHz.

With 8MHz clock you can send out data to the 6x '595 in as little as 6us. Of course, there will be overheads: preparing the data, latching the outputs.

Code-wise, I would suggest to use an unsigned long long, for simplicity and performance. These are 64 bits, so enough to hold your 46 bit pattern, which you can initialise to 0b11. You can easily shift the bits in either direction with << and >>. You also have to handle the "wrap-around" between bit 0 and bit 45. When sending out the data with SPI.trsnsfer(), you can cast the unsigned long long into a byte reference, to avoid the need for more shifting and masking to extract individual bytes. You can use micros() to perform the timing.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: TomGeorge on Sep 14, 2019, 10:50 am
Hi,
Are the taps part of the two inductors, or a separate tapped inductor?

I'm not sure what will happen with DC, but I was involved long ago with a project involving switching auto-transformer (AC) tap with similar make-before-break.
The problem was circulating currents between the two connected taps, current being induced into them by the current in the rest of the winding.
The transformer was 10A, but the circulating currents we up to 10 times that amount.

With DC you will have switching transients, so I'm not sure what sort of circulating current you will get.
This current will flow through your tap switching components.


Quote
Channels are overlapped with two always on at a time in Make Before Break
No, you should have two ON at switch over, not ALL the time.

Like this.

Tap 1 ON.
then
Tap 2 ON
then
Tap 1 OFF
then
Tap 3 ON
then
Tap 2 OFF
then
Tap 4 ON
then
Tap 3 OFF.

I hope that makes sense.

Tom.... :)
PS. It will be interesting to see how the inductors interact with changing current and the CORE coupling them together to give a MUTUAL INDUCTANCE.
You are effectively making a transformer with pri winding magnetically and electrically connected to sec winding. :o
How are your inductors connected, START to START or START to FINISH terminals?
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: dougp on Sep 14, 2019, 02:44 pm
Are you Doug Pine by the way.
Nope.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 14, 2019, 05:56 pm
PaulRB;
 
 Simply outstanding advice  :) and exactly what i need and i really do appreciate the explanation. the coding will be much more involved then shiftOut which is to bad as that is simple and i am not that experienced in coding. i also PaulRB was wondering will a Tensy 3.6 fit the bill for the timing as i have one on a Tall Dog break out board.????

TomGeorge;

no the Inductor is not two separate Inductors, it is one closed core inductor with the ends on either side connected to electromagnets. the moving taps are the action of a rotating positive brush converted to electronic switching. with the taps being positive it will cause two north face opposing fields at the brush or taps overlap that essentially separate the single Inductor to two separate inductors with current increase of one side and decrease current on the other in complete unison. it is essentially using inductive reactance to control current flow in two different feeds to the electromagnets 180 degrees out from each other which shift the opposing fields to one side then the other while maintaining field line pressure.

there is NO mutual inductance between them because of the opposing fields at the on taps that separate one inductor in to two halves.  their is also no secondary as i am controlling the current flow to two sets of electromagnets in repulsion. 
the pic below is the single layer Inductor that will control current flow of two feeds. it has less winding's then the real version as this is just for visuals to get the point across. the timing graph i posted is how the timing is going to be irregardless of word meaning and interpretations. two channels overlapping throughout the entire sweep except on the ends where they are on for three times longer then the ones in the middle. i posted a pic of the set up but i guess you pass that by.

again Thank you PaulRB, CrossRoads for your help many times over.


(https://i.postimg.cc/pLGDCKHt/Inductor-Functions.png)
 
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: TomGeorge on Sep 14, 2019, 06:46 pm
Hi,
I did see the other diagram.
Is the mechanical version of  this in existence and does it work?

So your taps will be where the circumference of the circle is, or along a line through the axis of the inductor?

I sense an "overunity" machine design.

Tom... :)

Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 14, 2019, 11:12 pm
Yes it is an extension of the mechanical, yes, through the axis and yes, it works most beautifully. it is the most efficient way to control current on the planet. as for the rest, well, it is just an active inductor that controls two current feeds 180 degrees out.

all i am here is to get advice on the controller and software to control it converting it from mechanical to electronic control nothing more for which PaulRB and CrossRoads have helped immensely.
MM
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 14, 2019, 11:38 pm
PaulRB;
  Is this what you are talking about unsigned long long and unsigned long long int and are they the same thing.?
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: TomGeorge on Sep 15, 2019, 03:27 am
all i am here is to get advice on the controller and software to control it converting it from mechanical to electronic control nothing more for which PaulRB and CrossRoads have helped immensely.
MM
Okay, but the mechanical brushes may be under going quite high currents and this will reflect in your solid state version.
I would suggest you use a high side driver for your IGBT or MOSFET switch.

Tom... :)
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 15, 2019, 05:29 am
It actually is only an amp or two at most not what you are thinking and as for the IGBT or MosFet i have changed to a Logic NPN switching a higher power PNP.  because of the fact that with a driver for the IGBT or ModFet  the boot strap capacitor can not keep the transistor on for the amount of time i need for the overlap especially for the ends which are on three times longer. there is no way for it to recharge and will shut off.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 15, 2019, 11:30 am
PaulRB;
  Is this what you are talking about unsigned long long and unsigned long long int and are they the same thing
Yes and no.

Yes, unsigned long long is shorthand for unsigned long long int.

But the code you posted is not Arduino C, it's some C for desktop PC. There is no std::cout in Arduino C. In that code "<<" is a string concatenation operator and is also not part of Arduino C. The "<<" and ">>" operators I'm talking about are bit-wise shift left and shift right operators which act on integers and are available in Arduino C.

Before you post any more code, please read the forum guide in the sticky post so you know how to do it correctly.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 15, 2019, 07:18 pm
Thanks i'll do that.

is there any code using long long, shift operators and other coding i can study as i have no experience in that depth of coding.
another thing is how will i get the channel overlap i need as per the pic i posed  where one channel is on while the previous channel goes low and the next channel goes high at the same time. this allows me to basically have two on at switching at all times.  if i can't do this i will have to pay someone to do it unfortunately even though i like to do things myself.

Thanks again.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 16, 2019, 01:23 am
PaulRb, Crossroads i have search the net for two days and i have found nothing worth a darn about << >> unsigned long long  or SCK . everything i found just wanted to describe it or it's function with no coding or sketch as an example. i am completely lost in that field.
i can design the circuit, design the board on DipTrace with the transistor board to boot but beyond simple coding i am stuck like chuck.

any advice will be well taken.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: CrossRoads on Sep 16, 2019, 05:03 am
Put your data into an array, and then shift the data into 75HC595, or TPIC6C595 or TPIC6B595 if you need more current drive.

This code shows just doing one pass of data, you can change it to output bytes 0 to 5, then 1 to 6, 2 to 7, etc.

(https://forum.arduino.cc/index.php?action=dlattach;topic=632901.0;attach=324616)
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 16, 2019, 07:31 am
CrossRoads;

 Thank you so much, i will download and study till my eyes fall out.
one thing though, i thought it was an 8 bit per port or is that depend on pin ability as some can not be used.  can you explain the bit group count, do you mean to overlap.???

another thing is i see you daisy chained them. in the original circuit i had it used pin 14 of each 595 to Arduino separately and worked fine. will this be able to shift 0 to 46 and back to zero with additional line of code. ?

with this programming will i be able to overlap like the timing drawing i posted??? overlap believe it or not in this situation is a must in the controller.
sorry for the question.
so with a quick glance it looks like a standard Arduino should run a sketch with 595's interfacing with a logic NPN MosFet switching PNP MosFet on the high side.

another thing is why is pin 13 in your schematic from all 595's going to the Arduino??  A HIGH on OE causes the outputs to assume a high-impedance OFF-state which will kill the output.
your the best and thanks again.

EDIT; found a lot of info on Gammon.com.au forum concerning SPI.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 17, 2019, 09:17 pm
I've had a go at some example code for you. Not properly tested!
Code: [Select]
#include <SPI.h>

unsigned long long int registerBuffer = 0b11;
const unsigned long long int bit45 = 1ULL<<45;
unsigned long int lastUpdate;
const unsigned long updatePeriod = 177UL;
const byte latchPin = 10;

void setup() {
  Serial.begin(115200);
  SPI.begin();
  SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
  pinMode(latchPin, OUTPUT);
}

void loop() {
  if (millis() - lastUpdate > updatePeriod) { //Is it time to update the registers?
    lastUpdate = millis();
    byte wrap = (registerBuffer & bit45) != 0; //Copy bit 45 from the buffer
    registerBuffer <<= 1; //Shift all bits in the buffer 1 place to the right
    if (wrap) registerBuffer |= 1; //Paste the copied value from bit 45 into bit 0
    unsigned long long int temp = registerBuffer; //Take a copy of the buffer
    SPI.transfer(&temp, 6); //Send the buffer to the registers
    digitalWrite(latchPin, HIGH); //Latch the updated values into the register's output pins
    digitalWrite(latchPin, LOW);
  }
}


@CrossRoads, @dougp, @TomGeorge, @Paul__B, @lastchancename, @johnwasser please check this code for me!
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 18, 2019, 02:10 am
thank you so much PaulRb. between you and CrossRoads you both have a different approach to the same outcome which is very good. i also thought digitalWrite was to slow for something like this. is there a serialWrite () or is that a wrong usage of serialWrite.

i am curious as to direct port manipulation. see the example shown and tell me what you think about the feasibility of such an approach. is millis(); used instead of delay microseconds, i looks like i would need a lot of channels to satisfy this beast. even though this looks easier i think the code from both of you will be better in the long run, i hope.

Code: [Select]

PORTD =0b00000001; // Bit 0
delayMicroseconds(T1);
PORTD =0b00000011; // Bit 0,1
delayMicroseconds(T2);
PORTD =0b00000110; // Bit 1,2
delayMicroseconds(T2); 
PORTD =0b00001100; // Bit 2,3
delayMicroseconds(T2);
PORTD =0b00011000; // Bit 3,4
delayMicroseconds(T2);
PORTD =0b00110000; // Bit 4,5
delayMicroseconds(T2);
PORTD =0b01100000; // Bit 5,6
delayMicroseconds(T2);
PORTD =0b11000000; // Bit 6,7
delayMicroseconds(T2);
PORTD =0b10000000; // Bit 7
PORTB =0b00000001; // Bit 0  bit 8 = PORTB bit 0)
delayMicroseconds(T2);
PORTB =0b00000011; // Bit 0,1
delayMicroseconds(T2);
PORTD =0b00000110; // Bit 1,2
delayMicroseconds(T2);
PORTD =0b00001100; // Bit 2,3
Ect...Ect.....Ect....


Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 18, 2019, 07:42 am
Yes, I think this is also an approach to consider. Obviously you would need a Mega for this. One downside to the approach is that, if you find you need to move to a faster processor, your code would need to be rewritten, because the direct port manipulation code above is specific to AVR processors. There will probably be equivalent commands for other MCU, but for example their ports may be 16 bits wide, not 8.

Never heard of serialWrite. Did you mean Serial.write() ? If so, that's not for setting output pins, it's similar to Serial.print().
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 18, 2019, 08:37 am
I Figured as much for the top part. i was researching it last night and came to the same conclusion that it would have to be modded per chip ports.
you are correct about SerialWrite, i went back to take another peak.

i do have a Tensy 3.6 with a Tall Dog break out but i need 5 volts output for the logic level NPN's so the Tensy would "just" turn it on and that is no good. is there any way to use Serial, SPI or I2C  two Arduino's together to get my 46 channels and 5 volts in a master slave situation. i am just asking as a last resort as i will try both your and CrossRoad's way to time the board.

it is to bad the STP16C596 doesn't have shift capabilities at 16 channels it sure would of made thing easier to design. all the output are on one end with the rest on the other.

Thanks again PaulRB and you to CrossRoads for the wonderful help you both have given me.
DL
MM
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 18, 2019, 05:50 pm
Tall Dog break out
No idea what that is, please post a link.

but i need 5 volts output for the logic level NPN's
I thought we had covered this earlier in the thread, but maybe I'm getting confused with another thread. NPN transistors are not switched by voltage, they are switched by current. 3.3V vs 5V is not a problem, you simply compensate with a lower value resistor in series with the base.

is there any way to use Serial, SPI or I2C  two Arduino's together
Yes, but almost always a bad idea. Certainly a bad idea in this case. I2C is slow. SPI would be fast enough, but why use another Arduino, which needs coding, debugging etc. when you can just use simple shift registers?

it is to bad the STP16C596 doesn't have shift capabilities at 16 channels it sure would of made thing easier to design. all the output are on one end with the rest on the other.
Lost me there. No-one has suggested STP16C596. It does have 16 channels. But the max voltage is 16V, so cannot be exposed to your 100V+. Cannot drive NPN because the outputs can only sink current, not source it. No idea what you mean by "all the output are on one end with the rest on the other".
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 19, 2019, 04:29 am
Here is the link to the Tensy 3.6 Tall Dog breakout board.
https://www.tindie.com/products/loglow/teensy-3536-breakout-revision-a-due/# (https://www.tindie.com/products/loglow/teensy-3536-breakout-revision-a-due/#)

it is really nice having all pin outs easily available and not have to fiddle with the underside. easily fits in the palm of your hand.

i was referring to Logic level enhanced Mosfet NPN not a current controlled bjt for which the Mosfet i have connected to an enhanced Mosfet PNP for the grunt work.
thanks for the info about the different interfaces, good to know about i2c being slow.

as for the STP16C596, all the outputs are on the lower half of the ic on both sides and the control pins are on the top half making it really nice to trace out on a board. i was just stating that it would be nice if the ic had latch capabilities and not sink only.

i have a question about the code, do the interrupts needs to be turned off as to not interfere with the SPI function and correct timing or is that not a problem. interrupts can add time to the sketch  throwing the time off right.?

Thank you much.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 19, 2019, 08:13 am
Thanks for the link to the link to the tall boy thing. Not something I would choose, but each to their own.

Can you post a link to these "NPN MOSFETs" please. I've only heard of "n-channel MOSFETs", so would be interested to understand the difference.

You don't need to turn interrupts off for SPI. Exact timing is not as critical with SPI as with some other types of serial communications, because there are separate clock and data lines and the correct timing is whatever the master device says it is. So if software SPI were used and interrupts caused slightly inconsistent timing, that would not matter. But for your application you need to use hardware SPI, and that wouldn't be affected by interrupts during the transmission of each byte of data, although it could cause minor delays between bytes, but again thats not a problem. Are you planning to use interrupts? I am not aware of any need to do that for your project.

STP16C596 does have latch capability. Its outputs can sink but cannot source current.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 19, 2019, 06:36 pm
Unfortunately i have a bad habit of using NPN, yes we are talking about the same thing, N channel MosFets.
i was just curious as i have been studying up on SPI and came across the data that suggested possible interference issues so i thought i would bring it up to you as you have MUCH more experience then i do at this sort of thing, which by the way thank you for the info. no i do not plan on using interrupts as they are not needed in my situation.
as for the STI it can shift but as you said it has no latch and can only sink. i have the data sheet on my computer with a some guy's program that uses it for a LED bar graph that is why i brought it up. no i do not plan to use it, only the 595.

any luck on getting the sketch a second eye.?

again thank you and everyone else for the help. when i am finally finished with my active inductor i will post link to it in action and i will also post you guy's as the leading contributors in making this a reality.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 19, 2019, 07:31 pm
Quote
as you said it has no latch
No, I said the opposite of that.

I can't imagine the SPI circuit causing interference, but it (and the rest of the circuit) might be affected by interference. You will be switching high voltages and currents and creating fast moving magnetic fields. That's a recipy for interference problems! I'm not an expert in how to minimise that risk.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 19, 2019, 09:03 pm
Bad eyes all i can say,  LE Latch pin 4 sorry.

concerning an Byte Array how do you shift the bytes from 0 byte to 45 and back to 0 and would it matter if it was MSB or LSB.?

also in the set up you used const int LatchPin, clockPin, and dataPin, when i declare them as outputs do i still use pinMode in the setup.?

Remember i am a newbie at coding so don't byte.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 19, 2019, 10:53 pm
There's no byte array in the code I suggested. Are you asking @CrossRoads?

Regarding L/MSBFIRST, yes, as I said, not properly tested, some corrections will almost certainly be needed!
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 20, 2019, 12:03 am
My apologies PaulRB, i did get the two mixed up, i have labeled them accordingly.
it seams the two of you are taking such different routs and it is a little confusing.
i actually am trying to pursue both so now i have separated them into different folders with the research also.
as i stated earlier does it matter if LSB or MSB i would like to know if it changes anything. i am sure the program can start with either way Right.?
can you explain the usage of const int and how do i declare the pins.?
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 20, 2019, 07:43 am
If I were you, I would test the code by wiring up the 6x '595 with 46 LEDs (+46 series resistors). You may have noticed the code I posted uses millis() rather than micros() which means it will run 1000 times slower, enabling you to observe the LEDs and check the sequence. Then you can play around with the wiring, direction of shifting and use of L/MSBFIRST in the code. Once that's working correctly, you can change millis() to micros() before you wire up your transistors.

"const" is short for constant. It indicates a value that does not change in the code. You can treat const variables just like any other, except that if your code accidentally attempts to change the value, you'll get an error message.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 20, 2019, 05:39 pm
PaulRB;
That's what i figured from the moment i saw the code you presented. seeing the Millis() i could test it first before implementation which is the standard way of doing things and yet i am still grateful you brought it up.

i do have a puzzling question though to you Paul and CrossRoads alike, does it matter if two channels are high on the same port and will this have an adverse effect on the chip.?? ie... port D 0, 1 high at the same time or does it have to be another port.??? or does it even matter.
thank you for the const information.

CrossRoads;
Slave Select is only available on certain Arduino boards. using a board that does not have a Slave Select pin for witch i am aware of,  how do i go about using a general pin for Slave Select and or can any pin be used for this.
also error message; "serial" was not declared in this scope. i did not know i had to declare serial.

thank you both for your time and patients to a newbie.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 20, 2019, 08:42 pm
You can have as many pins high as you like, it does not matter. What does matter is the current they source (or sink, when low). Each pin has a 40mA absolute limit on AVR chips (less on teensy, I suspect), but you should keep that to 30mA or less for long life. An unconnected pin sources/sinks no current. A pin driving the gate of a FET will source or sink almost zero current. Or rather, the pin must source current for an instant to turn the FET on, and sink current for an instant to turn the FET off again. The gate of a FET acts like a small capacitor. At low switching frequencies, the current is almost zero, but at higher frequencies it can become significant.

There are also current limits for various groups of pins, and for the chip overall. I don't see this as a problem in your circuit. Pins driving the inputs of other chips also draw almost no current.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: CrossRoads on Sep 20, 2019, 09:03 pm
If a chip supports SPI, then it will have a Slave Select pin. Some of the Lilypad boards do not make all the pins available and make SPI usage not possible.

A '328P in a DIP package has a 200mA limit on its VCC and Gnd pin. A '328P in a surface mount package has two Vcc pins, thus the board can deal with more current.  The electrical interface section of the data sheet bears this out, as the total current available for each port (there is a current limit per port) totals up to 300mA.

http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf (http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf)

Table 30-1, page 323
3. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: 
ATmega48A/PA/88A/PA/168A/PA/328/P: 
1] The sum of all IOH, for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150mA. 
2] The sum of all IOH, for ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150mA. 
If IIOH exceeds the test condition, VOH may exceed the related specification. Pins are not ensured to source current greater than the listed test condition. 
4. Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: 
ATmega48A/PA/88A/PA/168A/PA/328/P: 
1] The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed 100mA. 
2] The sum of all IOL, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100mA. 
3] The sum of all IOL, for ports D0 - D4, RESET should not exceed 100mA. 
If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not ensured to sink current greater than the listed test condition.

Are you using Serial.begin(), Serial.Available(), Serial.read(), Serial.write(), Serial.print()?
Notice all use a capital S, not a small s. C++ is case sensitive, cap/no-cap is an easy mistake to make.

Sorry about being in & out on this thread, I've been kind of busy with other stuff.  What board are you using?
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 21, 2019, 12:40 am
PaulRB;

"There are also current limits for various groups of pins, and for the chip overall. I don't see this as a problem in your circuit. Pins driving the inputs of other chips also draw almost no current."

That's what i figured also. there is only a few pins active at a time so i forsee no such problems. my only real concern is the load on the 74HC595's which will basically have 50 to 60 ma ruffly total anyways.

CrossRoads;

The guinea pig in this case is an Arduino Leonardo i had for my Aquaponic control system that got destroyed by my ex room mates. Arduino works though.

do not fret the small stuff, i an just very grateful for the help from you two and i realize people have lives also. whether you take a week to respond it is ok with me.
PS. i am still getting an error code SPI_MODEO not declared in setup.

Thank you both very much.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 21, 2019, 09:30 pm
Quote
PS. i am still getting an error code SPI_MODEO not declared in setup.
Well, that's not right. Post your code.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 22, 2019, 07:45 pm
This error is with CrossRoads code. i am working on it so i will post when i get done troubleshooting it.
PaulRB i am wondering about the non pin assignment in your code. i have added the pins in the declaration and in after void set up. is this correct as it still compiles correctly.?
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 22, 2019, 08:51 pm
Quote
the non pin assignment
???

You can declare pin constants anywhere you want, as long as they are outside of any function (otherwise they would be local to that function and not visible outside it) and before they are used.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: lastchancename on Sep 22, 2019, 11:47 pm
Honestly, no disrespect to OP, but please remember you're planning to switch mains voltages & currents into an inductive load.
This may not be a suitable beginners project
See if you can find a buddy that lives nearby, or buy someone in the Gigs & Collaboration section.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 23, 2019, 03:13 am
Here is my problem blatant with no disrespect intended.
1. i did not ask you for your opinion but thanks anyways, i might take it under consideration some day just not today.
2. i have been working on this project for 6 years and i really know this device top to bottom especially my Inductor controller and what it is capable of.
3.  if you would of read from the start this device does NOT use main AC it uses DC 100 volts @ 1 amp peaking to 1.4 amps. well i might not have stated that but i did now and if that is the case i do apologize for my lack of awareness to the fact .
if you feel like helping on the coding i would very much appreciate it but i have the device very much covered thank you.

it uses Inductive Reactance to control current flow which is probably not within your realm of understanding of what an Inductor can actually do. the mechanical controller is almost done and i am here to seek advice from experienced coders to convert the controller to electronic to make it totally non moving.
it is one Inductor split into two with two opposing magnetic fields at the rotating brush which allows two separate feeds on either end of the Inductor to control current 180 degrees out from each other. one increasing one  decreasing, vice versa, in complete unison as the brush rotates.

if you care to lean what an active Inductor can really do and how it operates just let me know as i have a ton of research on the matter that i have posted on MY forum.

Regards,
DL
MM
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 23, 2019, 03:33 am
PaqulRB;

  I was wondering if i use const for the pin assignment of the remaining pins or do i use just regular pinMode and it if is the previous case how to i go about it.?

i tried to use digitalWriteFast and pinModeFast but it would not compile at all for the Arduino Leonardo.

Coding, ARGE !
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: lastchancename on Sep 23, 2019, 04:59 am
REPLIES #5 and 7 pointed you in the right direction, but you don't like the thoughts proposed.
OK by me.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 23, 2019, 09:07 am
lastchancename;

  I am already pursuing two different forms of SPI coding and i can not handle a third just yet as i am new to coding and very new to SPI.

PaulRB;

  I figured out why it was not compiling. i downloaded the new digitalWrieFast-Master, followed instruction and presto it compiled. it was having a tissy with the installed Arduino file.

Here is the file, please tell me if i made mistakes.

Code: [Select]

  #include <digitalWriteFast.h>
  #include <SPI.h>

  unsigned long long int registerBuffer = 0b11;
  const unsigned long long int bit45 = 1ULL<<45;
  unsigned long int lastUpdate;
  const unsigned long updatePeriod = 180UL;
  const byte latchPin = (9);   // SS or CS output to STCK latch pin 12 on 74HC595
  const int clockPin = (11);  // SCk to Seial Clock SHCP Shift Clock pin 11 on 74HC595
  const int dataPin =  (12);  // Mosi to DS in pin 14 on 74HC595

  void setup() {
  Serial.begin(115200);
  SPI.begin();
  SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
  pinModeFast(latchPin, OUTPUT);
  pinModeFast(clockPin, OUTPUT);
  pinModeFast(dataPin,  OUTPUT);
  }

  void loop() {
  if (millis() - lastUpdate > updatePeriod) { //Is it time to update the registers?
  lastUpdate = millis();
  byte wrap = (registerBuffer & bit45) != 0; //Copy bit 45 from the buffer
  registerBuffer <<= 1; //Shift all bits in the buffer 1 place to the right
  if (wrap) registerBuffer |= 1; //Paste the copied value from bit 45 into bit 0
  unsigned long long int temp = registerBuffer; //Take a copy of the buffer
  SPI.transfer(&temp, 6); //Send the buffer to the registers
  digitalWriteFast(latchPin, HIGH); //Latch the updated values into the register's output pins
  digitalWriteFast(latchPin, LOW);
  }
}



 
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 23, 2019, 05:42 pm
These lines are not needed. The SPI clock (SCK) and data (MOSI) pins are fixed and not configurable. They are on the SPI header and not duplicated on any of the Lenonardo's edge pins. They don't seem to have Arduino pin numbers on Leonardo. You don't need to specify them, and if you try to specify them and choose different pins, it won't work on those other pins, it will continue to work on the SPI header pins. You don't need to set them to be outputs, SPI.begin() will do that.
Code: [Select]

  const int clockPin = (11);  // SCk to Seial Clock SHCP Shift Clock pin 11 on 74HC595
  const int dataPin =  (12);  // Mosi to DS in pin 14 on 74HC595

  pinModeFast(clockPin, OUTPUT);
  pinModeFast(dataPin,  OUTPUT);


(http://www.hobbycomponents.com/images/forum/leonardo_pinout.png)
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: marathonMAN1 on Sep 24, 2019, 01:12 am
Awe !, that is something i very much overlooked, they are constant and dedicated . that just goes to show you do not try to code at 3 am in the morning. isn't the SS or CS pin also not configurable. ?? but i guess since it isn't in the group it isn't static.?

I guess the title of this thread needs to be changes to Arduino SPI to control 74HC595 shift register.

Thank you PaulRB much appreciated.
Title: Re: Using Arduino to Control CD40110BE up down clock
Post by: PaulRB on Sep 24, 2019, 08:21 am
Yes, you can choose what pin to use as SS. Atmega32U4 does have an "official" SS pin, but it seems to be connected to an led on Leonardo. Should not be a problem, because as long as it is set as an output, which the Leonardo core must be setting to make the led work, the Leonardo will be the SPI master, not slave.

You can change the thread title by modifying the original post.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 24, 2019, 03:57 pm
 I was planing to use the Tinsy 2.0 which is a 32U4 for which has SS or CS pins plus Mosi0 and SCK0. i have already accounted for it on my shift register controller board @ 12 pins a side the board is cheap and will do the job intended.
The Leonardo is just for testing as it is still reserved for my Aquaponic system and code.

i was wondering in the code sample you presented to me, how is the program cycling back and forth from end to end just looking at the code. i have not tested it just yet. i also see you used a wrapper to wrap the code in the registry buffer then pulling samples and updating time every loop. very nice implementation that and the fact the code compiles in 7 seconds with only 15% of storage space used.

Thanks PaulRB, you have been a tremendous help.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Sep 24, 2019, 08:37 pm
I'm still not 100% sure what you wanted to do with the moving bit pattern. Currently my code will cause the pair of 1s to shift always in the same direction and when they reach the end of the shift registers, they re-appear at the opposite end. Other things you said imply movement in both directions, but I can't figure out when the direction reverses.

Teensy 2.0: SPI pins are quite different to Leonardo, 0=SS, 1=SCK, 2=MOSI
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 24, 2019, 11:32 pm
Zero to 45 back to zero continuously. 0>45>0
my only concern for this program is the lack of overlap between the channels for make before break scenario. meaning one channel becomes high before the later goes low in sequence.

Yes, i am aware the Tensy has different pins. it doesn't take 5 minutes to change traces in DipTrace for the controller board if i am to use either. my only concern is if Tensy 2.0 supports digitalWriteFast.

How i want the bits to shift, of course though i want them to shift back from 45 to zero same sequence.



Code: [Select]

  byte dataArray[] = (
  0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 
  0b01100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 
  0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 
  0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 
  0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 
  0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, 
  0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000001, 0b00000000, 
  0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000, 
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011,
  0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001,

 






Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Sep 25, 2019, 12:15 am
Ok, the code I wrote does what you just described. Assuming you described it unambiguously.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 25, 2019, 03:11 am
Just like the old show on TV "The Night Rider" where Kit, the car has a light in the front that goes from left to right to left again in a sweeping fashion.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Sep 25, 2019, 08:05 am
Ah, the code I gave you does not do that, but it does do what you described in post #78, if interpreted in that way (my code does go from 45 to 0, just not via 44, 43...). When reading your earlier posts, I wondered if you meant "night rider" style movement. This is s good illustration of why a diagram is better than an English description for technical stuff: English can be so ambiguous!

A few more lines will be needed to adapt the code to do "night rider". Get the shift registers+LEDs working with the current code first, then change it to "night rider".
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 25, 2019, 04:44 pm
#7 me #8 not me. well at least me are on the same page now. i just need to test what i have now and go from there. you have been a tremendous help and i surely appreciate it so much.

i still need to order a few parts to get this test circuit going so i will get on that. in the mean time do you recommend any bread board over others as i do not have one presently. i recently moved  away from sorry ex room mates that literally threw 2k worth of my test equipment in the trash when i was not there so i have to start over.

thanks again.

Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: johnwasser on Sep 25, 2019, 04:56 pm
do you recommend any bread board over others as i do not have one presently. 
One thing to watch out for: Some of the large breadboards have power rails that are split in the middle.  You can generally tell because the colored lines (typically red and blue) along the power rails have a gap in the middle.  People have had problems because they expected power applied to one end of the power rail would get all the way to the other end.  Jumpers across the gap will eliminate that stumbling block.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 25, 2019, 05:16 pm
Thanks for the info. so basically the boards is split into two electrically, got it.

PaulRB;

even though the program needs to run like the night rider except with 46 channels, it still needs to have overlap like the Array i posted which will be tricky.

Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Sep 25, 2019, 07:46 pm
Quote
#7 me #8 not me.
I said post #78, not posts #7 and #8...

Breadboards: I like K&H AD-100,101,102. Unusually, they have connector strips 6 pins long where every other breadboard has 5. They can be clipped together in many flexible configurations to suit each project. They are also reliable, in my experience, with few or none of the problems people always complain about on this forum. That may partly be because of how I use them. I like to avoid Dupont cables and instead use solid core connection wire laid flat to the board, like this:
(https://forum.arduino.cc/index.php?action=dlattach;topic=188135.0;attach=54203)

Quote
still needs to have overlap like the Array i posted which will be tricky.
No, it won't be a problem.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 26, 2019, 12:54 am
Sorry, i did not realize we were up to that many posts.

nice breadboard and can clip together, i need to get some.
i to like neatness, every time i do audio/video surround sound redo's i always encounter a rats nest from their own installation. yet when i am done everything is labeled and neat as can be with awesome sound to boot. same with electronics, i literally hate wire clutter and is one of my pet peeves.

again thanks for the advice and for the coding support. i will be searching for the breadboards when i click post.

EDIT;
i checked out the K&H products, a little expensive but very nice quality. i do like the ones with the power and ground screw connectors. I'm sold.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Sep 26, 2019, 07:45 am
Quote
the ones with the power and ground screw connectors.
I don't like those. Not expandable/flexible/configurable.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 26, 2019, 08:56 pm
I do like the ones you are talking about i just want them longer. great quality though.

PaulRB instead of using DigitalWriteFast could i use the direct port manipulation like the code attached. observe the direct port on and off sequences. i think this would be better than DWF or PMF....Yes ?
and of course no delay function as we are dealing with Milis() or Micros().
It will also work with decimal numbers.





* setup() function
 *
 * Set B5 (Digital pin 13) to output by changing the DDRB
 * register instead of using pinMode().
 *******************************************************/
void setup()
{
  DDRB = B00100000;
}

/****************************************************************
 * loop() function
 *
 * Turn the LED attached to B5 (Digital pin 13) on and off
 * by changing the PORTB register instead of using digitalWrite().
 ****************************************************************/
void loop()
{
  PORTB = B00100000; //Turn LED on.
  delay(1000);
  PORTB = B00000000; //Turn LED off.
  delay(1000);



It will even work if the values are in variables, binary or decimal:

int on = B00100000;
int off = B00000000;

void setup()
{
  DDRB = on;
}

void loop()
{
  PORTB = on; //Turn LED on.
  delay(1000);
  PORTB = off; //Turn LED off.
  delay(1000);
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Sep 26, 2019, 10:28 pm
You could. But as you move from digitalWrite() to digitalWriteFast() to direct port manipulation, you get deeper and deeper into code that will limit your choices in terms of the range of Arduino your code will run on in the future. Right now, as far as I can see, your code needs to do 2 digitalWrite() for each update of the registers, every 177us? Well, digitalWrite() takes around 2~3us on a 16MHz Arduino.

Quote
i just want them longer
They clip together length ways too.

P.S. I see you still have not read the forum guide yet, even though you have made almost 60 posts. Please do that!
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 27, 2019, 02:53 am
Well understood Mr Paul. it was just a thought and was curious, i am learning what i can.

I didn't know they clipped together length wise. it is kinda to late i purchased another k&H board of of ebay for cheaper price, still a K&H though. it is equal to about 6 of the one you showed me and has the power attachments. link to pic of breadboard. it is huge.

https://i.postimg.cc/xjx75pXf/K-H-Bread-Board.png (https://i.postimg.cc/xjx75pXf/K-H-Bread-Board.png)

as for the forum post, i entered it correctly it just came out that way because i copied it from a post. in order to have it correctly post in the window i will have to enter it in the IDE then copy for forum. that is a real pain in the back side and should of been taken care of within the forum software.
if you have another way please let me know and i will be glad to oblige because at this point in time i surely do not want to piss anyone off.

Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Sep 27, 2019, 07:48 am
Quote
it is equal to about 6 of the one you showed me
I wouldn't want to swap my breadboards for that, as I said before, I like the 6-long pin strips. Very useful for wider Dev boards and modules like esp8266/32. Here's a larger circuit I built using them:
(https://forum.arduino.cc/index.php?action=dlattach;topic=409966.0;attach=203608)

Quote
in order to have it correctly post in the window i will have to enter it in the IDE then copy for forum.
Not at all. Just hit the code tags button and paste it in. All described in the forum guide.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 27, 2019, 06:20 pm
  I have everything i need to test coming by next week. i will use my existing Leonardo then later purchase a Tensy 2.0 to mount on the manufactured board. the board it's self is finished in design yet will wait to have made in case of changes that may occur. also the transistor board is finished in design and luckily only two layers and still i was able to separate the power/ground and digital ground return from the digital channel inputs.
each board will have ribbon cable for digital connections between boards and the transistor boards will have much thicker wire connections to the Inductor taps. the length between the Inductor taps and the transistor boards will be kept as short as possible being above the Inductor few inches then the controlling board above that. since the opposing fields in the conductor will have a bulging effect i have taken this into account having the transistor board four or five inches from the Inductor as to not interfere with the digital channels.

I use DipTrace which i find much easier to use then most design software. i can easily design a board in just a day or so and instantly 3D so see any such mistakes in silk screen or other problems.

like i said the code is very fast and compiles is 7 seconds flat which literally blew my mind. the thing that puzzles me is why do such a narrow amount of boards support digitalWriteFast. it literally refuses to compile for any other boards.???

again thanks for everything PaulRB and for the K&H boards, they surely seem like good quality made breadboards with little to no complaints.

if by chance i need to move up to a slightly higher power shift register the pin assignment will be different but i can change the design in DipTrace in one afternoon with no problem.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Sep 27, 2019, 07:16 pm
The reason that digitalWriteFast is not implemented on many other platforms is, I think, because it's advantages aren't so dramatic on those platforms. On AVR chips like atmega328/2560, direct port manipulation can be 10~15 times faster than digitalWrite(). But on esp8266, for example, it's only about twice as fast, so why bother? I think this is because of the large number of Arduino pins that ATmega chips have compared to their port size, which is 8 bits, and the number of ports which don't have all 8 bits available because they are used for other things like crystal oscillator inputs. So translating an Arduino pin number to a port and pin number is complex. On other chips, it's much simpler, because their ports are 16 bits wide, for example.

I don't think you have any need or reason to move to higher power shift registers. None of them are rated for the voltages your circuit uses, so you still need 2 transistors per channel.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 28, 2019, 03:26 am
  Very interesting PaulRB i did not know that info, thanks.

on the other matter i was referring to driving the logic level n-channel.  even though it is voltage controlled i still need enough driving current to turn it on to turn on the p-channel. it turns on at 2.6 volts 25 ma so the voltage is ok but current is close.

i will calculate it  again to make sure i am right. plus i will test first to see outcome is acceptable then test with 100 volts DC again making sure everything is operating ok.

the main thing is the program which i will start testing next week.

Thanks PaulRB.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Sep 30, 2019, 05:24 pm
Like i said most of the things i ordered will be in this week. the resistors, LED's and breadboard are in today while the rest between today and Friday. i will be setting up and testing Saturday for sure.

any chance on the rest of the code to make appear as night rifer style when and if you get the chance this weekend? i have been studying your code and some i get but others do not make sense do i am looking up each and every line and associating it with an action. i downloaded the language reference so that helps then looking up that on the net.

Thanks again for all the help PaulRB, i could not have done this coding by myself or at least efficiently that is.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Sep 30, 2019, 11:03 pm
Night Rider pattern:
Code: [Select]
#include <SPI.h>

unsigned long long int registerBuffer = 0b11;
byte shiftPos = 0;
bool shiftingLeft = true;
unsigned long int lastUpdate;
const unsigned long updatePeriod = 177UL;
const byte latchPin = 10;

void setup() {
  Serial.begin(115200);
  SPI.begin();
  SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
  pinMode(latchPin, OUTPUT);
}

void loop() {
  if (millis() - lastUpdate > updatePeriod) { //Is it time to update the registers?
    lastUpdate = millis();
    //Shift the register left or right
    if (shiftingLeft) {
      registerBuffer <<= 1; //Shift 1 place to left
      if (++shiftPos == 44) shiftingLeft = false; //Time to switch direction?
    }
    else {
      registerBuffer >>= 1; //Shift 1 place to right
      if (--shiftPos == 0) shiftingLeft = true; //Time to switch direction?
    }
    unsigned long long int temp = registerBuffer; //Take a copy of the buffer
    SPI.transfer(&temp, 6); //Send the buffer to the registers
    digitalWrite(latchPin, HIGH); //Latch the updated values into the register's output pins
    digitalWrite(latchPin, LOW);
  }
}
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 01, 2019, 03:01 am
Awe man thank you very much. i was really hoping to test this weekend and you bless me with this and my goodies came in today two days early so it is flat out project time.
your the best !

i was wondering about the code. is the code wrap in a buffer then updates off of the buffer every loop to keep the time constant.
i really want to understand the code in case i need other thing to perform or differently not just run it not knowing what the heck is going on.
if i need to change the time do i change the update period of 177UL to a longer time. also what if i need the end channels to stay on longer what would i do then.??
sorry for the questions but i do really want to learn this SPI port manipulation.
is there any such tutorial that will help me understand more.

Thanks very much.
DL
MM
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Oct 01, 2019, 06:57 am
Not sure about your first question. "wrap" was a variable in the earlier version on my code but has gone in this version. A copy of the buffer is made using the variable "temp". This is because of the way I used SPI.transfer(). Used that way, it overwrites the data given to it with garbage, because the MISO pin isn't connected (SPI is normally a 2-way comms protocol).

Yes, you can adjust the timing by changing the value of updatePeriod. For different delays at the limits, you could remove the "const" from its declaration and change is value depending if "shiftingLeft" is being changed or not.

SPI isn't "port manipulation" in the sense you mean, I think. Its a specialised piece of hardware inside the ATmega chip which can shift out data one bit at a time with an accompanying clock signal. The SPI circuit can do this much quicker than a piece of code could, and does it independently of the CPU, which can running other code while the data is being sent.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 01, 2019, 03:50 pm
  Ah, that is very interesting and good to know. so in other words i can add sensors for voltage, current and frequency monitoring on a display or sent remotely while the SPi is doing it's thing.
using direct port manipulation on those will it allow a low frequency Arduino like the Leonardo and or the Tensy 2.0 to do constant updates in real time or would i just use the standard approach.?

This is freaking awesome PaulRB, i so much thank you for your participation in this adventure of mine. you may not know it but you may have just helped change humanity as we know it in a very positive manor.
see this project of mine is not just some forgetful blinky thing to make someone go wow, that's cool or attract 1 million low intelligent youtube views from people that can barely tie their shoes let along help Humanity in a positive manor. this project can literally help millions of starving human beings around the world that are needlessly in a position of hardship.

that is how important this project is and to me that is awesome.

Thank you so much.

DL
MM
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 02, 2019, 12:59 am

[Yes, you can adjust the timing by changing the value of updatePeriod. For different delays at the limits, you could remove the "const" from its declaration and change is value depending if "shiftingLeft" is being changed or not.]


So i can have a longer delay at the beginning of shift right and shift left that way the ends stay on longer..?
it seems difficult sense i need two channels on at changeover from one channel to the other except on the ends where they are on three times longer.
now i am confused as to how this is going to work.i might have to have timing overlap caps at the transistors after all.?
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Oct 02, 2019, 08:01 am
Some code changes will be required for that. I will help you understand the code so you can modify it. Ask about any parts you do not fully understand.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 02, 2019, 04:07 pm
Thank you first off.

unsigned long long int registerBuffer = 0b11;  not sure i understand the position of the register buffer.

byte shiftPos = 0; does this mean it starts at byte zero of MSB or LSB or is it just the position of the first IC.

 = 177UL;  i have not seen this before unless i overlooked it somewhere. i know it is the time delay but why UL.

the rest i have the Arduino reference library to associate each function which makes sense taking it line by line. the program looks fairly simple yet i am new to programming.

so lets get this straight. it sets the bytes in a register mem buffer then references to that buffer each loop then shifting either left or right depending on the position of the bytes. bool meaning either t or F shifts to the left  until end then false else shift right.

so then comes the point of how to overlap, as in shifting two bytes at a time ? and how to leave the ends on for three times longer?

Edit. what size solid wire would you recommend for the K&H breadboard.

Thanks for you patience and time PaulRB i surely appreciate this.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Oct 02, 2019, 06:25 pm
unsigned long long int registerBuffer = 0b11;  not sure i understand the position of the register buffer.
I'm not sure what you mean by "position". It's position is in RAM memory, all variables are in RAM memory.

byte shiftPos = 0; does this mean it starts at byte zero of MSB or LSB or is it just the position of the first IC.
As we shift the bits around, this keeps track of how many shifts we have done. When that gets to 45, we reverse the direction until we get back to zero and so on.

= 177UL;  i have not seen this before unless i overlooked it somewhere. i know it is the time delay but why UL.
"UL" means "unsigned long" and it tells the C compiler that the constant should be stored as an unsigned long. Without the "UL" it will be stored as an ordinary int. In this case, it does not matter, the UL is not needed. But sometimes it can be important. I am trying to maintain a good habit of using UL for constants that are assigned to unsigned long variables.

so lets get this straight. it sets the bytes in a register mem buffer then references to that buffer each loop then shifting either left or right depending on the position of the bytes. bool meaning either t or F shifts to the left  until end then false else shift right.
Sorry, I can't get straight what you are describing. Yes, "bool" indicates a Boolean variable which can take only two values, true or false.

so then comes the point of how to overlap, as in shifting two bytes at a time ?
We are shifting 6 bytes at a time, not two. You will have 6 shift registers. But I think we may be confusing each other with the word "shifting". There are two types of shifting going on here. One is "shifting" meaning "transferring" the 6 bytes from the Arduino's memory to the 6 shift registers using SPI. The second type of "shifting" means updating the 46-bit pattern in the Arduino's memory by moving them one bit to the right or left before it gets sent to the shift registers.

and how to leave the ends on for three times longer?
Like I said before, change updatePeriod so that it is no longer a const and can be updated. When the pattern is at the ends, set it to 3 * 177, otherwise 1 * 177.

Edit. what size solid wire would you recommend for the K&H breadboard.
Around 22AWG wire is good, which is about 0.5~0.6mm diameter.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 03, 2019, 03:58 am
Thank you very much, that really helped ease some confusion.

so the update can take place at the last bit 3*177 then the next bit opposite shift there will be another update 1* 177 to account for the shorter time in the middle. thanks

you have been a tremendous help.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 07, 2019, 06:56 pm
I was unable to conduct test as i can not find my wire anywhere in the house. so i am having to order it. circuit is half done, ran out of wire on hand. i have everything else i need except the connection wire.


Byte 0 update 3x 177us  update shift right 1 x 177 us 1 through 44 then update 3 x 177 us 45 then shift left then update again 1 x 177 us 44 through 0 which is then looped.
is this correct.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Oct 07, 2019, 10:15 pm
is this correct.
I don't know, its too confusing.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 08, 2019, 10:35 pm
Byte 0 and 45 has to be on for 3 x 177us then update time
byte 1-44 has to be on for 1 x 177us then update time
each time it transitions from the ends to bytes in the middle there has to be an update in time as it is ether on for longer or a shorter time.

trust me i am having just as much trouble trying to code this then i am trying to describe it to you.
sorry for the confusion.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: dougp on Oct 09, 2019, 12:22 am
trust me i am having just as much trouble trying to code this then i am trying to describe it to you.
A possible graphic representation of what I think you're describing.  Close?

(https://forum.arduino.cc/index.php?action=dlattach;topic=632901.0;attach=327533)
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Oct 09, 2019, 07:47 am
@dougp We have established that is wrong. I thought that too at first. But the 1 bits don't wrap around from 45 to 0, they "bounce" and move in the opposite direction at 0 and 45, like the famous "cylon" or "night rider" patterns from the 1970s TV shows. Also there is no bit 46.

@marathonMAN, you are getting bits and bytes mixed up. A bit is a binary digit, a single 1 or 0. A byte is 8 bits. What I can't quite get is are there any times, at the extreme ends of the pattern, when only one channel is on rather than two adjacent channels?
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: dougp on Oct 10, 2019, 02:08 am
@dougp We have established that is wrong. I thought that too at first. But the 1 bits don't wrap around from 45 to 0, they "bounce" and move in the opposite direction at 0 and 45, like the famous "cylon" or "night rider" patterns from the 1970s TV shows.
Sorry, that slipped by me.  I've only been following this thread peripherally.

Also there is no bit 46.
I understand.  I was off on a tangent.

well actually divided by 50 as the ends are on for three times longer. this works out to be 0.333 ms each channel with the ends 0.333 x 3  x 2 + 46 channels = 16.66 ms.
So then, something like this?

(https://forum.arduino.cc/index.php?action=dlattach;topic=632901.0;attach=327673)
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 10, 2019, 03:47 pm
PaulRB

  Yes, the ends 0/45 are on 177 us by them selves. then when increasing or decrease in the night rider fashion it will overlap with the next output for 177 us. this mean when it is in constant motion it will have had the ends on for  longer then the output in the middle.
thank you for the correction and yes i did get them mixed up for a moment, apologies !

Dougp:
yes, exactly, your graph is exactly like my description above or vise verse. this will allow the ends to be on for a total of three times. i might even do the ends twice by them selves depending on how tests go. once i see it on an oscilloscope i can then determine if it is correct.


Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Oct 10, 2019, 04:12 pm
The code I posted will need further changes in that case. As is, there will always be two adjacent outputs on together.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 11, 2019, 03:49 pm
I am still going to test it as is, it might work and testing is the only way to find out. the whole intention is to exactly mimic the rotating brush on the single layer inductor that is why it is so crucial for the sketch to mimic these movements.

again thank you for your awesome help.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Oct 11, 2019, 04:14 pm
to exactly mimic the rotating brush on the single layer inductor
This is something I don't get. If it is mimicing a rotating brush, why is the "night rider" pattern appropriate, instead of the rotating pattern my earlier code was written to mimic?
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 12, 2019, 10:13 pm
PaulRB;

  Referring to post #37 i posted a graph of part G from the top view. if you break the brush rotation down to its basic form the two opposing fields at the brush are sweeping back and forth across the Inductor irregardless of the rotation. the action is increasing current flow to one feed and reducing to the other and vise verse.
if i was to do it as you are suggesting i would loose the opposing fields between the two feeds for a moment which will cause massive BEMF in the system which i do not need or want. even though the brush is rotating it is still raising and lowering current flow in a linear fashion as it tracts back across the same contacts it previously tracked across while not loosing the opposing fields used to separate the inductor in two.

so yes i do need the code to mimic this feature otherwise it will not function properly and that way is the night rider style which mimics the rotating brush basic function of increase and decrease of two feeds.
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Oct 13, 2019, 10:26 am
Its not that I don't believe you. I just can't picture it, mentally. Have you seen any animations or slow motion film of this thing in action, on the web?
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 13, 2019, 03:54 pm
PaulRB;

  This is ground breaking stuff here that was buried in 1908, you can't just hop down to Wall Mart and buy a video of this thing in action. granted i should of had my own working video out by now but all i have is a test run of the rotation at low speed and high speed on Youtube.

again the picture below which i have already posted shows a roller brush that is rotated. the description is exactly as i have stated in previous post.

each time the brush make a rotation one side of the inductor connection is increased then decreased in current flow with the opposite side 180 degrees out which is opposite. it will be decreasing then increasing. what this means is the taps connected to the inductor winding loops are switched on in a night rider fashion back and forth on a continuous basis. each wire will have a tap that is connected to a transistor so multiple taps will be made which will be switched on back and forth.

follow the brush as it rotates in a circle on the core. it will be increasing one side while simultaneously reducing the other. then when the brush reaches then end near the tap it will rotate the other direction reducing that tap and increasing the other.

(https://i.postimg.cc/NMYMwMWv/Rectangle-Core.png)
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: PaulRB on Oct 13, 2019, 06:49 pm
Many apologies, you did post that before, I remember now. The night-rider thing makes a little more sense now. So the rotating brush switches current to inductors or electromagnets. The vertical conductor strips each take current to one inductor, yes? What are the two conductor strips at the edges for, the ones with the right-angle bend in them? The brush never contacts those.

So, night-rider pattern. No wonder the concept was shelved in 1908, the TV show wouldn't be broadcast for another 70 years, so no-one had a phrase to describe the pattern produced! But more seriously, the rotating brush would not produce pulses of even length, the pulse lengths would vary sinusoidally. Unless the widths of the tracks varied in such a way as to even them out?
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: TomGeorge on Oct 13, 2019, 11:38 pm
Hi,
This might be clearer;
(https://forum.arduino.cc/index.php?action=dlattach;topic=632901.0;attach=328191)

Tom... :)
Title: Re: Using Arduino to control 74HC595 not CD40110BE in cascade using SPI.
Post by: marathonMAN1 on Oct 14, 2019, 03:32 am
IF my hair was longer i would literally pull all of it out right now.

the strips you see are actual copper wire wound around the core in loops, one length, so the current is split in two feeds at the positive brush. since the brush is moving so does the contact change as does the inductance of the two feeds.  there will be two opposing magnetic fields at the brush that keep the two feeds separate which allows each feed on either side of the brush to change. one raising in current the other lowering in current in one direction then the other direction one lowering and the other raising in current.

no, the right angle strip is the end of the loops of the one layer inductor that never get toughed by the brush. they are there for inductance purposes and the connection to the magnet.

Yes ! you are correct sort of. the device is DC so the rotating brush raises and lowers the current feed of the two that look like always positive Ac yet not since it is DC. the inductor will only lower the reducing feed 1/3 rd of the peak.

so you see i need a program that will act like the night rider to switch the taps from one end to the other and back in a continuous basis. overlapping each tap in the middle with the ends on for three times longer. the inductor i have has 46 taps off of the inductor so i will need a program that can shift 0 to 45 and back to 0 continuously all while overlapping the taps and the ends on for three times longer.

simple yes !

PS.  PualRB here is a link to the rotating inductor i am building.  the inductor core is below the rotating brush holder but it was not wound with wire at the time or had the brushes installed. this is the mechanical version, the software is for the electronically switched version.

low RPM test. https://www.youtube.com/watch?v=2MZaSZLLEWQ (https://www.youtube.com/watch?v=2MZaSZLLEWQ)

High speed test. https://www.youtube.com/watch?v=OT2Tubgv-_A (https://www.youtube.com/watch?v=OT2Tubgv-_A)