Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Using a TB6612FNG #21

Open
Ilosariph opened this issue Jan 16, 2024 · 4 comments
Open

Using a TB6612FNG #21

Ilosariph opened this issue Jan 16, 2024 · 4 comments

Comments

@Ilosariph
Copy link

Hello Pieter,
I have tried implementing very basic controls for a motorized fader myself. I can't get it to stop on point like your video shows. I then saw your website, and wanted to try your library, as it looks really thought out. I already have a Sparkfun TB6612FNG (https://www.sparkfun.com/products/14451) and you mentioned the TB6612FNG (I know you meant the chip, and I can't read datasheets, but I guess it would still have more connections than a L293D) in your hardware documentation. I have one small problem though:
According to the schematic PJordan2820 made in #6, the L293D only has two serial connections to the Arduino. The TB6612FNG I am working with has 4 (AIN1, AIN2, PWMA and Standby). How would I connect that to the Arduino to make it work with your library?
Thanks for taking the time to answer (or at least reading the question)

@tttapa
Copy link
Owner

tttapa commented Jan 16, 2024

Because of the asymmetry of this driver (see the H-SW Control Function table on page 4 of the datasheet, HHHH→LL and LLHH→Off), you should use the modifications explained in #18 (comment)

Using those changes, then connect the driver as follows.

Arduino pin Driver pin
2 (PD2) AIN1
3 (PD3/OC2B) PWMA
4 (PD4) AIN2
5V (Vcc) STBY

To wire the motor and the power supply, see the Typical Application Diagram on page 7 of the datasheet.

If you want to use more than one fader, you'll need to change the code for the other motors as well.

@Ilosariph
Copy link
Author

Thanks for that quick answer. The code change seems simple enough and makes sense (though I don't understand most of the code, I understand what you are changing). I'll try it tomorrow and let you know the results of my attempt.

@Ilosariph
Copy link
Author

So I've tried it (with the test reference), but it's not working. I have a theory:
I am using an Arduino Mega rev3. The pinout of it shows the PD2 as D19, the OC2B (which is the important part about this connection if I understood your comment on the other issue correctly) is D9 and PD4 is the RX LED, which makes it inaccessible for me.
I did try it with AIN1 to D19, PWMA to D9 and AIN2 to D3 (for a lack of better option). I tried using D2, D3 and D4 as well.
Reading the fader position with the print_controller_signals flag works as expected. Driving the motor and touch detection work with a simple Arduino script, so the fader or driver aren't broken and the power supply should be sufficient.
Is there an easy way to make this work with the Arduino mega or should I just buy a nano?

Hardware:
The fader is the 5K version of the one you used.
The connections on the diagram are made with the letters / numbers from it's datasheet.
Fader_Connections_Improved_Steckplatine

@tttapa
Copy link
Owner

tttapa commented Jan 18, 2024

It should be possible to make it work on the ATmega2560, but you'll have to change the pins used.

Specifically:

  • pick a different port for the touch pins (e.g. PA instead of PB)
  • pick different motor AIN1/2 pins
  • change the overrun indicator pin from PB5 to PB7

In the code, change the following lines:

// Bit masks of the touch pins (must be on port B):
static constexpr uint8_t touch_masks[] = {1 << PB0, 1 << PB1, 1 << PB2,
1 << PB4};

cbi(PORTB, 5); // Clear overrun indicator

if (Config::enable_overrun_indicator) sbi(DDRB, 5); // Pin 13 output

PORTB &= ~gpio_mask; // low
DDRB |= gpio_mask; // output mode

if (counter == 0) {
DDRB &= ~gpio_mask; // input mode, start charging
} else if (counter == touch_sense_thres) {
uint8_t touched_bits = PINB;
DDRB |= gpio_mask; // output mode, start discharging

sbi(DDRD, 2);
sbi(DDRD, 3);

(Or your modified version)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants