View previous topic :: View next topic |
Author |
Message |
Robotan
Joined: 12 Jul 2008 Posts: 18 Location: Canada
|
|
Posted: Tue Feb 24, 2009 5:43 pm |
|
|
I just tried the program without the interrupt and it still doesn't work. Both chips were tested with the same 10MHz crystal. With the picbaud program I noticed the error in the 19200 baud rate is much lower at 40MHz, so I tried running the 18F4620 at that speed. But no luck, the new PIC still refuses to talk to the servo motors. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 24, 2009 7:18 pm |
|
|
I finally figured out what your problem is. It's because starting
with vs. 4.021, CCS decided to do pointer arithmetic correctly.
Here's the note from the old versions page:
Quote: |
4.021 The & unary operator by default no longer returns a generic (int8 *) |
Quote: | int16 angle;
AX_SendByte(*(&angle+1)); //high byte of angle |
This code is actually increasing the address by 2 bytes, because 'angle'
is declared as an 'int16'. This is how it works starting with vs. 4.021.
But you just want to get the MSB of 'angle', so you need to cast it to
an int8 pointer before you add 1 to it. Example:
Quote: | AX_SendByte(*((int8 *)&angle+1)); |
You need to do this everywhere in your code where you're adding 1
to a 16-bit pointer. Be careful, because it's easy to make a mistake
when doing this mod. |
|
|
Robotan
Joined: 12 Jul 2008 Posts: 18 Location: Canada
|
|
Posted: Wed Feb 25, 2009 7:22 am |
|
|
Wow, thanks! I being an amateur programmer would never have caught that. I don't fully understand pointer arithmetic, but that method of accessing the high or low byte of an integer was lifted from a CCS code example. It seemed like a more direct way of doing things rather than copying the high and low bytes to new variables before sending them. I use several serial devices, and in each case I find myself having to split up multi byte variables before sending them, and then re-assembling them on the other side. Are there other ways of doing this that I should be aware of? |
|
|
|