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

I2C troubles.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



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

View user's profile Send private message

PostPosted: Wed Aug 08, 2018 5:55 am     Reply with quote

Yes, GREAT, it's 'up and running'. I had a quick read of the datasheet while watching the rain finally come down here.
This is really what I call a 'smart' module, as it consists of a sensor AND a computer, so there's no low level driver instead talk to the onboard computer.
It makes sense that there is a WDT, clever to keep the module in a known state. There is a command to disable the WDT as well.

I also saw a command to Verify the module. Very handy as it flashes
an LED for you to confirm 'here I am, and I'm alive '!

The 'reset' command will reset ALL modules on the bus, so if you have say 6 of them, ALL will be reset, so it make take longer for the PIC to communicate to the sensors.

Now IF I only had a real use for the neat device.......
Too many PICs...too many Projects...too little time.

Jay
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

PostPosted: Wed Aug 08, 2018 7:25 am     Reply with quote

I put the delay_us(2) in a precaution and will watch how transmissions go during testing. Seems to be ok for now.
I am now looking into getting more data out of the sensor. I am not getting the transmission speeds they claim, seems to be running about 15 HZ.

Right now my code is stripped to only do the loop I posted and send serial data at 19200. The send takes 6ms.
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

PostPosted: Fri Aug 10, 2018 1:05 pm     Reply with quote

Well I have a response from the vendor, they claim very high conversion rates for the sensor, I can only get about 25 HZ out of the sensor with a 16F876 @ 20MHz.

My basic loop is:
Code:
 
 delay_ms(30); //necessary delay
   i2c_start();
   i2c_write(LIDAR | WR); //we are writing
   i2c_write('D');  // issue single 'distance read' command
   i2c_stop();
   delay_us(30);
   i2c_start();      //restart
   i2c_write(LIDAR | RD); //select the read address
   msb = i2c_read(); //now read
   lsb = i2c_read(0);
   i2c_stop();


The Delay_ms(30) is necessary otherwise the loop will lock and not run. The delay_us(30) does not seem to necessary. The only other delay I have is sending data out the COMM and it takes about 6ms to do that. Are there buss problems with I2C and the 16F876? Perhaps I need to start a new thread to discuss this topic. Any tricks to making the I2C run faster. I do have a RTCC running with 15 interrupts per second.
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

PostPosted: Fri Aug 10, 2018 1:20 pm     Reply with quote

The above loop takes 31.2ms to execute. Obviously 30ms of that is the delay. If I lower the delay, the code locks up.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Aug 10, 2018 1:46 pm     Reply with quote

The speed you can get depends on the ranging mode selected. You can only get the 75Hz in the 'tinyLIDAR' mode with a 2m max range.
So how far do you need to sense?.
You will then need to set the range mode to suit, and adjust the time to suit this. 30mSec is required for the default mode (long range).

They don't say, but it is possible the device won't ACK if it is busy.
So try reading the ACK bit back from the address write, and wait till this is ready.
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

PostPosted: Fri Aug 10, 2018 2:26 pm     Reply with quote

Good suggestions, I did change the device mode to the tinylidar mode for the fastest response, but it did not change anything, perhaps the mode change did not take.
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

PostPosted: Fri Aug 10, 2018 2:27 pm     Reply with quote

The vendor claims the high data rates with an Arduino platform.
temtronic



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

View user's profile Send private message

PostPosted: Fri Aug 10, 2018 4:40 pm     Reply with quote

You should be able to 'read back' the device's current configuration ( I read that as a command....).
I learned a long, long time ago to not just 'assume' that the command you send IS done, you MUST request and SEE the configuration.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Aug 11, 2018 12:45 am     Reply with quote

The low latency reading requires you to switch to continuous mode (MC). Look at Appendix A in the data sheet.
The default mode takes 30mSec. The Tiny LIDAR mode reduces this to 18mSec. The continuous mode offers times down to just over 1mSec.

You have to understand what it does. In 'single shot', the D measurement, triggers it to make a new reading, and returns the value from the last one done. In continuous mode it carries on making readings all the time, and the data is available from it's buffer when you read.
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
Page 2 of 2

 
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