To Whom it May Concern,
I need to use the 16 bit timers on the mega with MC33926 Motor Shield to drive one dc motor for my application and am having trouble with the software changes. I saw that there was a Mega library for the DualVNH5019 Motor Shield, so I took that side by side the MC code and added those changes to the MC code - for example adding things like
#elif defined(AVR_ATmega128) || defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
// Mega board specific stuff here - assumes assigning timer3, using pins 3 &5
OCR1B = speed;
… where needed.
I’ve tried this code though and it doesn’t work. I know can’t use the Mega pin 12 which corresponds to Timer 1 on this because it corresponds to the fault pin on the motor drive. I know there are other 16 bit timers to use, but basically I’m pretty uncertain with what I’m doing, and would appreciate the advice.
Can someone review my code and tell me if there’s something obvious I’m missing?
Can someone recommend a strategy to get around the pin 12 issue?
Can someone explain also the hardware pin set up – right now I’m just using jumpers to connect things. So I have pin 9, 10 on the motor drive to pin 10,11 on the Mega. Do I need to plug in the pins I skipped as well? A general example would be useful.
DualMC33926MotorShield.h (1.44 KB)
DualMC33926MotorShield.cpp (4 KB)
It looks like you are implementing Timer1 in your code to generate your PWM signal; however, you have pins 10 and 11 connected to the PWM pins on the MC33926 motor driver shield. Pin 10 does not use Timer1; it uses Timer2. If you want to use Timer1 to generate both PWM signals, you should have pins 11 and 12 connected to the PWM pins on the shield.
You said the code does not work; how did you determine that? Does your program compile? If you have access to an oscilloscope, could you verify you are generating a PWM signal by measuring the Arduino pin?
If you use a different Timer on the Arduino Mega to generate your PWM signal, you can keep pin 12 connected to the status pin. Alternatively, you can remap the status pin to some other unused pin on your Arduino. You can read more about this in the “Remapping the Arduino Connections” section of the Dual MC33926 Motor Driver Shield user’s guide.
You do not need to connect the unused pins of the shield to the Arduino. The “Shield Connections: Signals, Power, and Motors” section of the user’s guide has a diagram that shows which Arduino pins are used by the shield.
Thanks for replying. So my program compiles, and I checked if that the PWM was being generated by making a LED blink on pin 11 of the Mega using PWM, so that’s fine.
I had pin 10 connected that way because I’m just using one motor and wanted to avoid touching pin 12 - so both PWM pins need to be on the same timer even if I’m not using both?
Looking at the cpp file, it seems then to avoid 12 and everything else I’m limited to using timer 3 with pins 5 and 3. If I wanted to do this, can you explain how I would need to change the registers? I know TCCR1A would have to go to -> TCCR3A, and same idea for the B register, but I don’t comprehend what TCCR1A is getting assigned to. Do I need to change this address as well, what would I change it to?
Thank you for your help!
If you are only moving one motor, it will probably be fine to leave pin 12 as is. However, you should make sure you set the TCCR1A register so that it does not affect OC1B (pin 12). You should refer to the ATmega2560 datasheet for setting the register. You can also refer to the datasheet for configuring the registers to use Timer3.