View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
PWM control from USART |
Posted: Fri Aug 13, 2010 12:55 pm |
|
|
hi
I try control PWM of an motor by a program on PC which send to USART values between 0 and 1023.
My question is, what is correct way to read from USART "read_usart" and apply value on PWM function?
Code: |
set_pwm1_duty(read_usart);
|
Someone can give an idea?
Best regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 13, 2010 2:37 pm |
|
|
This post has an example. It calls get_long() to get the duty cycle.
http://www.ccsinfo.com/forum/viewtopic.php?t=31662&start=6
You don't need all the code for Timer0, and you don't need the code
to check kbhit() or the switch-case statement. Hopefully that's enough
to get you going. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri Aug 13, 2010 5:46 pm |
|
|
Hi
I try find in manual of CCS but not find get_long() function...
if for example I write on terminal "1000" and on my code I have "duty=get_long();" I only have "duty=1000" after send "\r"?
PS: I don't understand how get_long() function work to read from terminal diferents values like "10", "250", "1000", etc... it need an stop "bit" like "\r" correct?
best regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 13, 2010 5:50 pm |
|
|
It's in the input.c file, below. You need to #include input.c above main().
Then you can call get_long() in your program.
Quote: |
c:\program files\picc\drivers\input.c
|
Quote: |
if for example I write on terminal "1000" and on my code
I have "duty=get_long();" I only have "duty=1000" after send "\r"? |
That's correct. You need to press the Enter key after you type the
number. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri Aug 13, 2010 5:57 pm |
|
|
fine... now I understand, thanks PCM programmer |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 18, 2010 8:17 pm |
|
|
You should try to do it. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sun Aug 22, 2010 7:02 pm |
|
|
hi
with this function "servo.c" I can decide +- angle of I need my servo? for example 10º, 20º, 30º, etc?
someone know if this is possible?
best regards |
|
|
|