Page 1 of 1

Demo-board PWM APIs

Posted: Tue Oct 14, 2008 11:55 am
by della
Hello everybody,
I don\'t understand how to use the PWM with the demoboard. I\'ve seen that there are 3 functions: EE_pwm_init, EE_pwm_set_duty and EE_pwm_close. When these functions must be called? And the Period is in millisecond or microsecond?

Re:Demo-board PWM APIs

Posted: Tue Oct 14, 2008 1:47 pm
by chris
Hi!

First of all you have to know that the PWM used in the demo-board works via the output compare interface. This is good if you want to drive a servomotor, otherwise you should use the PWM interface of the dsPIC on your own.

The code with the API for the PWM with the demo-board should be in ERIKA_INSTALLATION_DIR/ee/pkg/board/ee_flex/inc/ee_board.h file, but unfortunately it seems that something is missing.
Anyhow the period should refer to the period of the timer2 bound to the OC interface, but the is commented.

If you want to drive a servomotor you can try to adapt the code I am attaching, I already used and tested, to the demo-board (just choose the right Output Compare - OC - interfaces).

The code as two file to manage the PWM on the OC interface, in order to obtain an abstraction of it, and two file to implement the abstraction of the servomotor (the latter is just a wrapper for the first one, allowing to drive the servomotor in degree).

The init functions should be called before using the start and set functions.

I hope this will help.
Fill free to do any further question.

Regards.

Re:Demo-board PWM APIs

Posted: Wed Oct 15, 2008 2:17 pm
by della
Thanks for help.
I have to drive DC motor, not servomotor, but your code is very useful for me for the pwm stuff.

In pwmOC.h file is included a microTime.h, may you post also this file?

Regards

Re:Demo-board PWM APIs

Posted: Wed Oct 15, 2008 2:59 pm
by chris
Sorry, that was because I extracted that code from an old project of mine.
The lines that are required for the pwmOC.h are just the following:

Code: Select all


typedef enum {
	FCY_2_MHz=2,
	FCY_40_MHz=40
} fcy_MHz;
Anyhow I suggest you to have a look at the pwm interfaces that are well-suited for DC motors driving.
Here\'s the link to the microchip specific refman

http://ww1.microchip.com/downloads/en/D ... 70187C.pdf

Bye!