Counter for DC Motor x1 encoder

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://pastebin.com/axCepHjp  //Code

 

https://imgur.com/a/z5MOtzb  //Data analyzer + ticks counter by counter4

                                             //Channel 2 shows that timer runs for 100ms

                                             //Channel 1 shows software interrupt 

                                             //Channel 0 shows ticks from encoder

 

https://wiki.dfrobot.com/Micro_DC_Motor_with_Encoder-SJ01_SKU__FIT0450  //Motor

 

I am reading in from a POT, and using that to create a 0-100% DC. I am trying to then determine the RPM associated with that DC. 

I put some tape on this DC motor and counted to 10 and stopped the timer, and I kept getting 118-120 RPM. The time was from .4-.5 each time. This seems correct especially according to the data sheet at 5V.

My issue that I am having is I am not getting enough ticks to support this RPM that I timed. I am only getting around 1850 for a second, or in my code around 190 for 100ms. 

So I have 190 ticks/ .1 seconds ---> 190*60/.1 ---->  114000 ticks/minute ----> 114000 tick/minute * 1 rev / 1920ticks ~= 60RPM. According to the data analyzer this is correct also. 

Since the Freq of the ticks are around 1850Hz then 1850*60/1920 ~= 58RPM. 

So I am not exactly sure what I'm doing wrong. There is no way counter4 can't keep up with the ticks. I am just boggled on how I am not getting enough ticks but the motor is running at 120RPM.

I have the timer running for 100ms, and I have counter4 enabled for rising edges, and I have a software interrupt to trigger the ICR on counter 4 also.

Which channel 1 shows it triggering. So I have my code verified by the data analyzer. But at the same time, I have no idea why I wouldn't be getting the correct ticks.

Any help will be very appreciated! Thank you!

 

 

*EDIT*

Data sheet was wrong, I tested using a really low PWM, and found out it was actually half of what the data sheet. 960 PPR. Which makes sense because my PWM was always half of what I expected.

Last Edited: Thu. Apr 9, 2020 - 03:29 PM