TinyCircuits Forum

General Category => General Discussion => Topic started by: IBORE2 on December 19, 2015, 10:27:00 PM

Title: attiny841 in tinyshield dual motor
Post by: IBORE2 on December 19, 2015, 10:27:00 PM
Anyone know how those command are being interpreted. Those command address are not register address in attiny841 datasheet. Are those commands pre-programmed in attiny841?  where can I find the "code" being used to interpret those command?  Current problem I have is 0-MaxPwm is not linearly proportional to 0-Vmax range output. I wonder if there is some issue in the "code" which interpret the command.


  writeByte(COMMAND_SET_MODE, MODE_COMMAND);//send interpreted commands- see header file
  writeCommand(COMMAND_TIMER_1, PWMperiod);
  writeCommand(COMMAND_TIMER_2, PWMperiod);
Title: Re: attiny841 in tinyshield dual motor
Post by: Ben Rose on December 21, 2015, 07:13:12 PM
Hi- the firmware zip is included with the library, available at https://github.com/TinyCircuits/TinyCircuits-TinyShield_Motor_Library

You should be able to see how there's a register access mode plus a PWM command mode, which allows faster/simple transfer of PWM settings.

How are you measuring the output voltage of the PWM? Based on how the PWM hardware is used, the PWM duty cycle percentage should be linear to the set PWM value over the set PWM period. Depending on how you're measuring it, you'll probably need a small load resistor/low pass filter.
Title: Re: attiny841 in tinyshield dual motor
Post by: IBORE2 on December 29, 2015, 01:04:25 AM
Hi Ben,

Thanks for helping!!  I found the firmware zip in the library.  Very nice work of firmware coding!!!

- I always use arduino sdk to load the program into arduino board.  Just want to learn, how can you load the firmware into attiny841.  what kind of the software and what kind of cable need to be used to load the firmware into attiny841? any good link for learning that?

- For pwm, for example, I set the MaxPwm to 255 and use 3.7V for VM.  when I use  motor.setMotor(1, 125), I assume that the driver output should be around 1.85V. But when use mulimeter to measure it, it is actually 3.0V.  is it possible that the motor driver drv8837 itself does not provide  linear output.

- Also, when I set motor.setMotor(1, 255), max driver output only 3.2V out of 3.7V.  I wonder if drv8837 has high resistant of mosfet which eat up some voltage. Here are two observation. 
      1) Connect driver 2 output pins to motor, max is 3.2V 
      2) Since my motor only drive in one direction,  I connect Vbatt (3.7) directly to motor(+)pin while connect only one driver output pin(low) to motor(-), now max can archive ~3.5V.  It concludes that drive8837 internal each mosfet might eat up around 0.25-0.3V. 

Title: Re: attiny841 in tinyshield dual motor
Post by: Ben Rose on December 30, 2015, 10:10:12 PM
Thank you, glad you're taking a look at it.

1. You'll need to build an adapter with a TinyCircuits proto board so that you can connect a programmer- or connect to the TinyDuino and use ArduinoISP software. Then you need a software build environment- there are a lot of tutorials for setting up tools like AVR-GCC, avrdude, make, etc (WinAVR if you're on Windows), especially for 'raw' coding of a standard Arduino, and they should have about the same effect. However, the avrdude config file does need an addition for the ATtiny841- let me know if you get this far, or need help getting there.

2. For a multimeter you'll probably need a resistor/capacitor filter to get a nice voltage output. I've also remembered that the default behavior of the library is to let the motor 'coast'- ie, if one pin is being driven low, the other pin alternates between driven high and undriven- not driven high or driven low, like you would want for a voltage output. Since you're looking into the library, you should be able to write your own setMotor function to use 'maxPWM' instead of zero for the non-pwm pin. ie, a line like 'writeCommand(COMMAND_MOTOR_1,0,abs(val));' becomes 'writeCommand(COMMAND_MOTOR_1,maxPWM,abs(val));'

3. DRV8837 datasheet claims 280 milliohm total(high side plus low side) on resistance at 800mA, which would be 0.224V, so that may be what's going on if your motor is drawing over 1 amp. Is that the case?

Title: Re: attiny841 in tinyshield dual motor
Post by: IBORE2 on January 22, 2016, 03:52:22 AM
Hi Ben,

I am using following programmer, cable and attiny841 shield to program attiny841.


I install winavr and import main.c and makefile. But compilation failed and it complaint about unknown MCU 'attiny841' specified.  As you said, look like avrdude need an addition for attiny841. Can you help on how to add the addition to let winavr or avrdude to recognize and support attiny841 
Title: Re: attiny841 in tinyshield dual motor
Post by: Ben Rose on February 08, 2016, 02:47:09 PM
Hope you are still working on this- sorry about the delay. Compilation failing means avr-gcc doesn't know about attiny841- that checks out, since winavr hasn't been updated in years. You'll need to grab the AVR 8 bit toolchain from Atmel at http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORWINDOWS.aspx and extract the files using 7zip or similar, then copy the folders into your winavr install, overwriting what's currently there. Make a backup :)

You'll need an updated avrdude and config as well- grab avrdude-6.1-mingw32.zip from http://download.savannah.gnu.org/releases/avrdude/ and put it in winAVR-20100110/bin. Then you need an avrdude.conf with the ATtiny841 in the same folder. I've attached mine.

After all this, you should be able to just run 'make install' from the ATtiny841FW folder.
Title: Re: attiny841 in tinyshield dual motor
Post by: Ben Rose on February 08, 2016, 03:10:50 PM
I was able to reproduce a working toolchain using the above post- although I forgot to attach the avrdude.conf, here it is.

Let me know where more detail is needed :)
Title: Re: attiny841 in tinyshield dual motor
Post by: IBORE2 on January 01, 2017, 06:06:32 AM
Hi Ben, just pick up the attiny841 recently again. I was able to load the firmware. what is the fuse and lock bits setting used in tinyshield dual motor?   High bits, low bits, Extended bits and LB bits 
Title: Re: attiny841 in tinyshield dual motor
Post by: Ben Rose on January 23, 2017, 03:12:12 PM
Hi- fuse settings are in the makefile, which should be used if you do a 'make install'. It looks like we are just setting the extended bits to 0xED and leaving the rest default.