Playing PWM on Arduino MEGA2560 in mikroPascal.

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
mikroSeven
Posts: 161
Joined: 14 Mar 2016 10:24
Contact:

Playing PWM on Arduino MEGA2560 in mikroPascal.

#1 Post by mikroSeven » 17 Apr 2017 20:42

Hi, started learning to use the PWM's on the Arduino MEGA2560.

using PWM Library(routines): ( PWM1 Library = PWM2 Library )

12 PWM-outputs at: E.4, E.5, G5, E.3, H.3, H.4, H.5, H.6, B.4, B.5, B.6, B.7
All above DDR-bits as output. DDRE.4:= 1 etc...
If not: no output PWM1 and PWM2.


PWM1 visible at G.5 and B.7 fast flashing LED
PWM2 visible at H.6 and B.4 fast flashing LED

Played around with increasing/decreasing DutyCycle: visible by the brightnes of the led's.


USING OSCILLOSCOPE:
pwm scope.jpg
pwm scope.jpg (100.68 KiB) Viewed 15304 times
As written in the Library: not all prescale is avaiable.
To DIY or not to DIY

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Playing PWM on Arduino MEGA2560 in mikroPascal.

#2 Post by filip » 18 Apr 2017 16:40

Hi,

I presume this is a small tutorial for our users ?

Regards,
Filip.

mikroSeven
Posts: 161
Joined: 14 Mar 2016 10:24
Contact:

Re: Playing PWM on Arduino MEGA2560 in mikroPascal.

#3 Post by mikroSeven » 18 Apr 2017 17:36

Hi, in the first place I placed it because of my enthusiastic... :D

And if it helps other people, would be fine.
To DIY or not to DIY

mikroSeven
Posts: 161
Joined: 14 Mar 2016 10:24
Contact:

Re: Playing PWM on Arduino MEGA2560 in mikroPascal.

#4 Post by mikroSeven » 18 Apr 2017 21:14

Sorry when I'm wrong but I couldn't find the following combination in the libstock:
( there are lot's of others! )

mikroPascal - AVR - pwm

Thanks in advance.
To DIY or not to DIY

mikroSeven
Posts: 161
Joined: 14 Mar 2016 10:24
Contact:

Re: Playing PWM on Arduino MEGA2560 in mikroPascal.

#5 Post by mikroSeven » 21 Apr 2017 19:01

Learing my way trough Timer/Counter/PWM in all of the mikroPascal-IDE/compiler/Library and the 2560-datasheet.

Started with the standard procedures of the Library but also using direct methodes. ( directly reading/writing registers/bits ).

e.g.: I'm setting the sprecale bits: prescaling is done by 3 bits but they are spread over 2-registers.
( standard procedure PWMx_Init does it for you )

Have a nice weekend!
To DIY or not to DIY

mikroSeven
Posts: 161
Joined: 14 Mar 2016 10:24
Contact:

Re: Playing PWM on Arduino MEGA2560 in mikroPascal.

#6 Post by mikroSeven » 01 May 2017 12:30

Nice!

Controlling the 2560's TimerCounter/PWM by pc RS232, Lazarus!

Video on:
https://www.youtube.com/watch?v=Ho0_UuN-0nk

PWM duty cycle limited between 10% and 90%.
pwm by RS232.jpg
pwm by RS232.jpg (93.16 KiB) Viewed 11237 times
To DIY or not to DIY

mikroSeven
Posts: 161
Joined: 14 Mar 2016 10:24
Contact:

Re: Playing PWM on Arduino MEGA2560 in mikroPascal.

#7 Post by mikroSeven » 20 May 2017 11:12

Gonna use CounterTimer/pwm for controlling steppermotors.

Got the steppermotors allready running.
For exact running I'm gonna use TC/pwm.

Here a first shot:

https://www.youtube.com/watch?v=uT4BkUJiymc

Values are off by tenths of procent.
Need to sophisticate the code to get it more accurate.

To be continued...
To DIY or not to DIY

mikroSeven
Posts: 161
Joined: 14 Mar 2016 10:24
Contact:

Re: Playing PWM on Arduino MEGA2560 in mikroPascal.

#8 Post by mikroSeven » 24 May 2017 20:26

Things are improving:

https://www.youtube.com/watch?v=uT4BkUJiymc


Best regards!
To DIY or not to DIY

Post Reply

Return to “User Projects”