Re: HCMotor Arduino library for driving DC and stepper motors.
Posted: Sun Sep 01, 2019 8:13 am
Hi Andrew,
As a newbie I was digging deep on the “surface” I found Javier Valencia code dealing with timers. I found also some improvements added by Bill Perry for use timer4 on Atmega32u4. I also read data sheet and try to figure out what to add/correct in your program. I might be totally wrong in my thoughts, so can you please revise it and comment if you want or are in the right mood. Here is the code:
// Set timer mode
TCCR4A = (1<<WGM41); // here is the big ... Q should it be PWM4A or WGM41 set to 1.
// Set the prescaler
TCCR4B = prescaler;
// Clear timer 4 counter
TCNT4 = 0;
// Set the compare match register
OCR4A = compare;
// Enable timer 4 interrupt on compare match
TIMSK4 = (1<<OCIE4A);
In the Atmega32u4 data sheet p. 156 - 15.8.4 PWM6 Mode, there is some explanation that states that the PWM6 Mode (PWM4A = 1, WGM41 = 1, and WGM40 = x) provide PWM waveform generation option. Here my knowledge and understanding are too “short” to make it as it should be in the program …
As a newbie I was digging deep on the “surface” I found Javier Valencia code dealing with timers. I found also some improvements added by Bill Perry for use timer4 on Atmega32u4. I also read data sheet and try to figure out what to add/correct in your program. I might be totally wrong in my thoughts, so can you please revise it and comment if you want or are in the right mood. Here is the code:
// Set timer mode
TCCR4A = (1<<WGM41); // here is the big ... Q should it be PWM4A or WGM41 set to 1.
// Set the prescaler
TCCR4B = prescaler;
// Clear timer 4 counter
TCNT4 = 0;
// Set the compare match register
OCR4A = compare;
// Enable timer 4 interrupt on compare match
TIMSK4 = (1<<OCIE4A);
In the Atmega32u4 data sheet p. 156 - 15.8.4 PWM6 Mode, there is some explanation that states that the PWM6 Mode (PWM4A = 1, WGM41 = 1, and WGM40 = x) provide PWM waveform generation option. Here my knowledge and understanding are too “short” to make it as it should be in the program …