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 support@ccsinfo.com

receiving data on pic16F from an accelerometer MPU6050
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Sun Jan 29, 2023 3:33 pm     Reply with quote

temtronic wrote:
No, that PIC is more than fast enough ! I ran 3DOF helicopters in realtime over the internet a decade ago,using servos and encoders,so it IS capable of your project.

Please post your current program so we can see what you're doing.

The code that we are talking about is in first page of this topic if you want to see.
temtronic



Joined: 01 Jul 2010
Posts: 9142
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 29, 2023 3:49 pm     Reply with quote

some comments....

1st, you need to add SMBUS to the #use I2C(.... options.... ) though you should really have 5V<>3V interface logic translators.

2nd, relocate ALL 'math' operations from inside the I2C operations

3rd, add ERRORS to the #USE RS232(...options....)

4th, add PUT to the #FUSES list
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Sun Jan 29, 2023 4:06 pm     Reply with quote

temtronic wrote:
some comments....

1st, you need to add SMBUS to the #use I2C(.... options.... ) though you should really have 5V<>3V interface logic translators.

2nd, relocate ALL 'math' operations from inside the I2C operations

3rd, add ERRORS to the #USE RS232(...options....)

4th, add PUT to the #FUSES list


Okay for 2nd but why add PUT and ERRORS?
And for SMBUS i will add it but i don't know if it's useful. I tried earlier and it doesn't change anything with or without it
temtronic



Joined: 01 Jul 2010
Posts: 9142
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 29, 2023 9:36 pm     Reply with quote

SMBUS changes the accepted voltages for 'high'(1) and 'low'(0) on the I2C pins. You may have to lower the I2C bus pullup resistor values. Typically 3k3 for 3volt bus.
Also set the I2C speed option to SLOW. Once you get the code running 100%, THEN try the 'FAST' option.

If that doesn't get you 100% proper data, then you need to add 'logic level translator' devices between the PIC I2C bus and the MPU8050 I2C bus. The other alternative would be to use a 16LF877 and use a VDD=3 volts.

PUT is Power Up Timer. It's used to ensure the PIC powers up in a known sequence,so that it reliably works.

ERRORS adds a small amount of code to prevent the PIC HW UART from 'locking up' from data coming in (say from a PC) before the PIC can process it. The HW UART only has a 2 byte buffer, so if your program doesn't read and clear the buffer before a 3rd character comes in, the PIC will 'freeze' (stop working).
Ttelmah



Joined: 11 Mar 2010
Posts: 19277

View user's profile Send private message

PostPosted: Mon Jan 30, 2023 7:47 am     Reply with quote

You need to understand that you are trying to do something that is not
likely to ever work 100% reliably.

You have a 3.3v gyro chip trying to talk to a 5v PIC via I2C. Now the PIC
'properly' implements I2C. I2C has a Vih (input high voltage, when running
off 5v), of 3.5v. Problem is that the 3.3v device only supports having it's pull
up resistors go to 3.3v, so the bus does not go high enough to reliably be
seen as high by the PIC. Now the Arduino does not actually use I2C input
buffers, so can get away with this, but the PIC can't. The SMBUS
option should turn down the required Vih voltage, but it is a feature that
has varying efficacy on different PIC's. Yours is a very old chip, and I know
a lot of these do not properly implement the SMBUS option. Sad

The 'correct' way to do what you want is to either use a 3.3v PIC (and it
is worth saying that most of these will run a lot faster, and have more RAM/
ROM than your current chip), or use a hardware level translator.

You are fighting a war with incorrect hardware, and really need to rethink
how you are trying to work.
temtronic



Joined: 01 Jul 2010
Posts: 9142
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 30, 2023 8:10 am     Reply with quote

here's one example of what you need

https://universal-solder.ca/product/2-channel-level-converter-3-3v-5v-with-on-board-3-3v-ldo/

to PROPERLY interface your 3v module to your 5v PIC.

At that price it's not worth buying the pieces and soldering !
I understand that different parts of the World have 'supply issues' but as Mr. T points out ...you will NEVER get what you have to work 100% reliably.

NO amount of code,however 'clever', can cure the basic hardware problem.
Ttelmah



Joined: 11 Mar 2010
Posts: 19277

View user's profile Send private message

PostPosted: Mon Jan 30, 2023 11:48 am     Reply with quote

As a comment, there is one other way to get round the problem.
Instead of using the hardware I2C, choose two pins on your PIC that
have TTL input buffers, and use software I2C on these pins instead of
using the hardware port.
temtronic



Joined: 01 Jul 2010
Posts: 9142
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 30, 2023 1:22 pm     Reply with quote

DOH !

Perfect SOLUTION, providing he can swap 4 pins !!

Since the project is to 'level a plank using 4 actuators', it's easily done using SW I2C.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Mon Jan 30, 2023 2:59 pm     Reply with quote

Hi all, thank you for your answers. I really keep what you all say in my mind but the thing is that my project work properly like i did. I guess all you said were supposed to help me and it will! but i think the PUT, ERRORS, SLOW, etc... are optional and it will ensure that my PIC won't have any problems one day, but i tried my project today with my current code and one actuator and it worked almost perfectly. I just need to reduce more the delay (I've kept 500ms). So I'm going to add all that you said in purpose to have a better code. However, for hardware part maybe i haven't explained properly my situation with the PIC, but there are actually no problems with the I2C. If i have understood correctly what you said, should i understand that my Bus can work even without all the options and the 3V interface you were talking about but it can cause some issues?
temtronic



Joined: 01 Jul 2010
Posts: 9142
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 30, 2023 5:33 pm     Reply with quote

re:
Quote:
i tried my project today with my current code and one actuator and it worked almost perfectly.

ALMOST perfectly is NOT 'good enough'.

It needs to be 100% perfect, do 1 million operations and EACH one be correct. Do 10 million more, and all of them are correct.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Mon Jan 30, 2023 5:54 pm     Reply with quote

temtronic wrote:
re:
Quote:
i tried my project today with my current code and one actuator and it worked almost perfectly.

ALMOST perfectly is NOT 'good enough'.

It needs to be 100% perfect, do 1 million operations and EACH one be correct. Do 10 million more, and all of them are correct.


Don't worry i know it can be better ^^. But what i mean is, i just wanna be well rated for my degree, and when I'm sure the project works, i will try to improve myself and do better. My real goal is to learn things and get many knowledges not only do this project.
Ttelmah



Joined: 11 Mar 2010
Posts: 19277

View user's profile Send private message

PostPosted: Tue Jan 31, 2023 12:27 am     Reply with quote

'ERRORS', shoukd always be used when using the hardware UART, unless
you add your own error trapping and recovery to the ISR. Not using it
is criminal/stupid. I have a personal 'moan' that a lot of the older CCS
examples don't use it. However if you look, these are very old and date
back to before CCS actually got this working right...
Use it. It really should be the default behaviour by the #USE

'PUT' in this case probably doesn't matter, but would if for example you
tried to send serial data right after the boot without any delay. Get in
the habit of using this for reliability.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Tue Jan 31, 2023 2:38 am     Reply with quote

Ttelmah wrote:
'ERRORS', shoukd always be used when using the hardware UART, unless
you add your own error trapping and recovery to the ISR. Not using it
is criminal/stupid. I have a personal 'moan' that a lot of the older CCS
examples don't use it. However if you look, these are very old and date
back to before CCS actually got this working right...
Use it. It really should be the default behaviour by the #USE

'PUT' in this case probably doesn't matter, but would if for example you
tried to send serial data right after the boot without any delay. Get in
the habit of using this for reliability.


Sorry if i missed something but, why do you talk about hardware UART?
Ttelmah



Joined: 11 Mar 2010
Posts: 19277

View user's profile Send private message

PostPosted: Tue Jan 31, 2023 2:45 am     Reply with quote

Because that is what 'ERRORS' applies to.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Tue Jan 31, 2023 2:59 am     Reply with quote

Ttelmah wrote:
Because that is what 'ERRORS' applies to.


Yes but im only using i2c in my project.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 5 of 6

 
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