CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PWM control from USART

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PWM control from USART
PostPosted: Fri Aug 13, 2010 12:55 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 2:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 5:46 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 5:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 5:57 pm     Reply with quote

fine... now I understand, thanks PCM programmer
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Aug 18, 2010 6:55 pm     Reply with quote

hi

Now I try use ADC values [0-255] to move a SERVO between [0º-180º]. Is possible make this?

Is possible to adapt this way to make this?
http://www.ccsinfo.com/forum/viewtopic.php?t=34560&start=22


best regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 18, 2010 8:17 pm     Reply with quote

You should try to do it.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Sun Aug 22, 2010 7:02 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group