Go to Post The point of FRC (in my opinions) is to teach the kids that might have no skills, new skills. - dirtbikerxz [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 23-02-2009, 10:05
haim haim is offline
Registered User
FRC #1657
 
Join Date: Feb 2009
Location: israel
Posts: 2
haim is an unknown quantity at this point
using ttl on innovation first

hello every one
im using first 18f8520 with edu code for mplab.
im having problams with my code.
i want to control my first (connects with rs323 to pc) with hyper tirminal to be precise i want to control my servo on pwm out pins.
how i write a code for a thing like that?
need yours help please
  #2   Spotlight this post!  
Unread 23-02-2009, 15:36
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: using ttl on innovation first

I've never used the EDU controllers before, but I have a fair amount of experience with PICs in general and the IFI FRC controller. Someone else may be able to give you a better answer, but here's what I can tell you:

Under the default code (I downloaded the one available on ifirobotics.com), you can use printf(...) to send stuff out on the serial port. If you want to read in from the serial port, try making the following changes:

in ifi_utilities.c: Initialize_Serial_Comms
change USART_RX_INT_OFF to USART_RX_INT_ON

in user_routines_fast.c:InterruptHanderLow
add the following code to the bottom of the function:
if (RXINTF)
{
char data = RCREG;
/* data now holds one received character. it should be placed in a buffer somewhere */
}

Like I said, I haven't tried this code, but it should work. Post back here if it doesn't, or if you need help writing a receive buffer or anything. You also said "[your] code isn't working," so if you already have some code in the works that's having issues, you might try posting it so we can give you suggestions.

Good luck,
--Ryan
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
  #3   Spotlight this post!  
Unread 24-02-2009, 07:40
cau.denny cau.denny is offline
Registered User
None #1234
 
Join Date: Feb 2009
Location: israel
Posts: 6
cau.denny is an unknown quantity at this point
Re: using ttl on innovation first

thanks rayn,
i post the message it helped me.
i have a one more quastion.
when i define to control pwm pins what code i need to write to do this things:
i mean for example i want when i press on hyper terminal the letter A it will send to pwm out 1
0 like:
A= 0;
if a press B it will send to pwm out 1 127.
B= 127;
if a press c it will send to pwm out 1 255.
C= 255;
if you can help me its great im new in all that
  #4   Spotlight this post!  
Unread 25-02-2009, 02:55
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: using ttl on innovation first

Quote:
Originally Posted by cau.denny View Post
when i define to control pwm pins what code i need to write to do this things:
i mean for example i want when i press on hyper terminal the letter A it will send to pwm out 1
0 like:
A= 0;
if a press B it will send to pwm out 1 127.
B= 127;
if a press c it will send to pwm out 1 255.
C= 255;
if you can help me its great im new in all that
For that, just start interpreting the information that you get in the data variable. As the datatype suggests, the code allows you to receive one character at a time, so what you're wanting is fairly simple, just select a different behavior based on what letter you receive, like this:

switch(data)
{
case 'A':
pwm01 = 0;
break;
case 'B':
pwm01 = 127;
break;
case 'C':
pwm01 = 255;
break;
}

A couple of WARNINGS to anyone who wants to start using this code for reading from serial ports:
  • Make sure to only read the character from the data variable. Once the RCREG register is read, it is automatically cleared, that's why we store the character in an intermediary variable
  • Once you change the init flag to USART_RX_INT_ON, make sure to add the interrupt code as well so that the processor can service the interrupt
  • When processing an interrupt handler (in our case, anything that's inside InterruptHandlerLow), the processor completely stops doing anything else.
    Firstly, this is BAD for IFI controllers (either the EDU or the FRC controller) because they depend on periodic communication between the controller's two processors. This means that if your code in InterruptHandlerLow takes too long, the controller will auto-reset. If you're getting unexpected "code errors" after you add code to interact with the serial port, make sure this isn't happening to you.
    Secondly, if the interrupt is not serviced quickly enough, the processor may miss the next character sent, and you'll start wondering why you're only getting every second or third character you're sending to the robot.

The usual way to avoid the last problem is to store characters into a global circular buffer in the interrupt handler, then add code outside the interrupt handler (like in Process_Data_From_Local_IO) that checks if there are any new characters in the buffer and processes them accordingly.

The advantages of the buffer are:
  • You can process multi-character commands
  • You have have more complex processing of the received data
  • It keeps the serial port receiving smoothly

However, adding a buffer adds a fair bit of complexity to your code, and circular buffers can be easy to mis-code, especially since there's only a vary limited amount of debugging that can be done with the IFI controllers.

For examples of how to write such a buffer, try Googling for "circular buffer" or "ring buffer." If you don't feel like investing in the experience of writing your own buffer, allow me (as I'm often apt to do) to point you to the venerable Kevin Watson's implementation of serial port code for the IFI controllers. His code was written for the newer IFI FRC controllers (based off the PIC18F8722 instead of the PIC18F8520 like the EDU controllers), and as such may require some massaging in order to get the hardware portion of the code working, but it still has a good example of a circular buffer, regardless.

For the example given of just setting motor values, it should be fine to just put the code given into InterruptHandlerLow because it's not too computationally intensive (just make sure that you control the rate of characters coming to the robot over the serial link. If the rate gets to be several thousand per second or such, you may start encountering problems).

As always, if you have any other questions or problems, feel free to post back.

Happy coding,
--Ryan
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
  #5   Spotlight this post!  
Unread 25-02-2009, 08:52
Phalanx's Avatar
Phalanx Phalanx is offline
Formerly Team 1089 (Mercury)
AKA: Michael Reffler
FRC #5431 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jun 2005
Rookie Year: 1999
Location: Lewisville, TX (previously NJ)
Posts: 384
Phalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond repute
Re: using ttl on innovation first

No need to massage any code. Kevin has done remarking and impressive work the PIC controllers from IFI.

All of his EDU Controller Sample code can be found here:
(Bottom half of the page)
http://kevin.org/frc/2005/

Specifically Serial Driver for the EDU 8520.
http://kevin.org/frc/2005/edu_serial_ports_0.3.zip
__________________
Don't just ask the experts, become one!
Leadership is not about ability. It's about responsibility!
Diagonally Parked in a Parallel Universe. It's okay we do Quantum Physics


  #6   Spotlight this post!  
Unread 26-02-2009, 00:04
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: using ttl on innovation first

Quote:
Originally Posted by Phalanx View Post
No need to massage any code. Kevin has done remarking and impressive work the PIC controllers from IFI.

All of his EDU Controller Sample code can be found here:
(Bottom half of the page)
http://kevin.org/frc/2005/

Specifically Serial Driver for the EDU 8520.
http://kevin.org/frc/2005/edu_serial_ports_0.3.zip
Thanks for filling in the blank. I haven't been around FIRST for long enough to have used the EDU controllers, so I was taking some shots in the dark.

--Ryan
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
  #7   Spotlight this post!  
Unread 27-02-2009, 14:58
cau.denny cau.denny is offline
Registered User
None #1234
 
Join Date: Feb 2009
Location: israel
Posts: 6
cau.denny is an unknown quantity at this point
Re: using ttl on innovation first

thank you very much guy!
you helped me alot especially you rayn.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the TTL port on the RoboVasion (Edubot) Controller Leav Programming 3 06-08-2008 11:00
**FIRST EMAIL**/Championship Hotel and Innovation First Information Katie Reynolds FIRST E-Mail Blast Archive 1 19-01-2005 16:42
Using the TTL port Max Lobovsky Programming 6 25-06-2004 12:44
Innovation First Manual Cheese Head Programming 2 19-11-2002 12:44
Innovation First archiver 2000 0 24-06-2002 00:12


All times are GMT -5. The time now is 01:57.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi