NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Support Forum » Carrera Precision CP5906 digital caliper
September 16, 2010 by kle8309 |
If anyone knows the protocol for the digital read out please let me know. |
---|---|
September 17, 2010 by hevans (NerdKits Staff) |
Hi kle8309, It looks like not too many people have worked with the calipers you have, and we certainly have not either. I think your best bet is to try to scope the output of your calipers see if you can figure out what is coming out. Odds are it will be at least very similar to a documented protocol. If you don't have a scope you can try using the MCU itself to detect the signal and then send the data to your PC to visualize. Good luck with this project, keep us updated! Humberto |
September 27, 2010 by kle8309 |
// calipers.c // for Caliper DRO with ATmega328p // kle8309 // atmega168 define F_CPU 14745600include <stdio.h>include <avr/io.h>include <avr/interrupt.h>include <avr/pgmspace.h>include <inttypes.h>include "../libnerdkits/delay.h"include "../libnerdkits/lcd.h"include "../libnerdkits/uart.h"uint8_t read(void){
} double digital_read_out(void){
} void caliper_power_on() {
// SET PINS AS INPUT
DDRB |= 0x00;
// SET PINS AS OUTPUT
DDRC |= 0xff;
DDRB |=(1<<PB3);
// PULL UP PINS 1 2 3
PORTB|=(1<<PB1)|(1<<PB2)|(1<<PB3); // turning off and on again will eliminate start up error
PORTB&=~(1<<PB3);
PORTB|=(1<<PB3); // Light Indicator PORTC|=(1<<PC0); } //////////////////////////////MAIN////////////////////////////////////// int main() { // start lcd
lcd_init();
FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
lcd_clear_and_home(); // update time uint32_t timeconstant=100; uint32_t n=0; lcd_clear_and_home(); n=4*timeconstant; //turn on caliper caliper_power_on(); // skip first dro while(--n>1){ lcd_line_four(); fprintf_P(&lcd_stream, PSTR("Begin in:%5u"),n); delay_us(500); } //INITIALIZE UNIT BIT uint32_t b_24=0; while(1){
return 0; } |
September 27, 2010 by kle8309 |
This is a modified code for the Carrera Precision CP5906 DRO. I hope this will help others use this particular caliper. Believe it or not, it took my 30 hrs to see this project through. ps. I tried using comparators but they didn't work too well so I sticked to 4 npn bjt for the non-inverted clock and data level shifting. |
September 27, 2010 by kle8309 |
PC0 power indicator PC5 Clock indicator PC3 Data indicator PB3 power to caliper PB1 DATA PB2 CLOCK ps link http://www.youtube.com/watch?v=P-4zTMiHECQ |
September 27, 2010 by Ralphxyz |
That's great I just picked up a set of calipers. I haven't any idea of the brand but between your project and the nerdkit caliper project I "should" be able to get something working. Thank you, Ralph |
September 27, 2010 by kle8309 |
Ralph, This thread may be useful to you also http://www.nerdkits.com/forum/thread/683/ Good luck! |
October 30, 2010 by kle8309 |
code update to calipers project: this one has struct and mem allocation (which requires some mod to the makefile ie. -j .data) // calipers.c // for Caliper DRO with ATmega328p // Kelvin Le // 10-29-2010 define F_CPU 14745600include <stdio.h>include <stdlib.h>include <avr/io.h>include <avr/interrupt.h>include <avr/pgmspace.h>include <inttypes.h>include "../libnerdkits/delay.h"include "../libnerdkits/lcd.h"include "../libnerdkits/uart.h"// PC5 is clock led // PC3 is data led // PC0 is power led // PB1 DATA in // PB2 CLK in // PB3 power switch // these are the data types for data storage // bit 9-16 is 16 bits and 17-24 is 32 bits struct multi_Arr
{ }; // this is the hard part uint8_t read(void){
} void digital_read_out(struct multi_Arr *DRO){
} void caliper_power_on() {
// SET PINS AS INPUT
DDRB |= 0x00;
// SET PINS AS OUTPUT
DDRC |= 0xff;
DDRB |=(1<<PB3);
// PULL UP PINS 1 2 3
PORTB|=(1<<PB1)|(1<<PB2)|(1<<PB3); // turning off and on again will eliminate start up error
PORTB&=~(1<<PB3);
delay_ms(500);
PORTB|=(1<<PB3); // Light Indicator PORTC|=(1<<PC0); } //////////////////////////////MAIN////////////////////////////////////// int main() { // start lcd
lcd_init();
FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
lcd_clear_and_home(); // update time uint16_t n=300; //turn on caliper caliper_power_on(); // init DRO structure pointer struct multi_Arr *DRO; // allocate memory memory using calloc DRO=(struct multi_Arr *)calloc(1,sizeof(struct multi_Arr)); // skip first dro
while(--n>1){
lcd_line_four();
fprintf_P(&lcd_stream, PSTR("Begin in:%5u"),n);
delay_us(500);
}
lcd_clear_and_home(); while(1){
return 0; } |
October 30, 2010 by kle8309 |
Later on, I gonna send the 3 bytes of read out using SPI. That is why I used struct to store many different types of readouts. |
October 30, 2010 by Ralphxyz |
Just out of curiosity what the heck does include [HTML_REMOVED]mean? Ralph |
October 30, 2010 by kle8309 |
I don't know, it was like that whenever I upload my code it won't let me do "<>" here are the includes w/o the "<>" include stdio.hinclude stdlib.hinclude avr/io.hinclude avr/interrupt.hinclude avr/pgmspace.hinclude inttypes.hinclude "../libnerdkits/delay.h"include "../libnerdkits/lcd.h"include "../libnerdkits/uart.h" |
October 31, 2010 by hevans (NerdKits Staff) |
The forum software removes HTML tags in posts to prevent malicious injection of code in forum posts. To prevent that problem make sure you properly indent all code blocks with at least 4 spaces, which will make sure all > and < are properly escaped. To indent a code block you can just highlight it and and press the Indent Selection as Code Block below the Preview button. Humberto |
November 07, 2010 by kle8309 |
My calipers project (SPI and PCINT): http://www.youtube.com/watch?v=HVkW4u-os7c |
November 07, 2010 by kle8309 |
|
November 08, 2010 by mrobbins (NerdKits Staff) |
Hi Kelvin, Cool to see it working! Out of curiosity, what are the three different microcontrollers are all doing and what's going on overall? Mike |
November 08, 2010 by kle8309 |
So there are three mcu:
This mcu is responsible for user interface (I'm currently working on incorporating the ps/2 keyboard program into the current one). When requested, the master will ask slave 1 for calipers DRO. Also, when requested, the master will send an interrupt to slave 2 to update the DRO on slave's memory.
constantly acquiring DRO data
constantly sending out PWM to drive a linear actuator (not seen in the video). When the master interrupts slave 2, it will calculate a new PWM (time on and time off basically)corresponding to the DRO received. |
November 08, 2010 by Ralphxyz |
So will the linear actuator move the measured distance coming from slave 1 DRO data? What linear actuator are you using? Ralph |
November 11, 2010 by kle8309 |
@ Ralph Here is the actuator I'm using: actuator and yes, I got the actuator to move according to the DRO from the calipers. It is not
100% accurate since the mcu pin output is 4.7V and not the 5V needed (but close). To accommodate for this, I used an external hex inverter (requires a 6.5V Vcc)and shifted the 4.7v to 5v. This is one way to calibrate the actuator. However, this will not a perfect fix since the minimum voltage is 0.2V. Ideally we want 0V, so the actuator will only retract to 2mm and not 0mm. Right now, I'm working on another algorithm that may self correct itself to the analog position feedback from the acutator (another cool feature about this actuator). So far, between the calipers and the overall system, I have spent over 70hrs for this project (mostly debugging c codes!). |
November 11, 2010 by Ralphxyz |
So you have invested "over" 70hrs and bought a $90.00 actuator so far. What is your final project? That actuator looks really neat, I want one just to play around with that would be cool. Ralph |
November 11, 2010 by kle8309 |
This is part of my senior design "laser light deliver system" |
November 14, 2010 by kle8309 |
Here is the video with the actuator in it and I also added the ps/2 keyboard: |
March 12, 2011 by Linkster |
Hi Kelvin, |
March 12, 2011 by kle8309 |
Hi Gary, First of all, don't give up. About the calipers project, it would make your life easier if you have access to an oscilloscope and/or multisim. Make sure it's not the chinese protocol (the NK demo) If it's the same protocol as mine then you will have to improvise like I did. You will have to change the NK code to something similar to what I have up above. Note: the Carrera Precision protocol is 24 bits with data set freq of 3.54Hz (much slower than the chinese protocol); clock freq is ~ 1.43Khz How to wire data/clock level shifter (-> means connection)
Note: data and clock are amplified using the steps above. Tips on debugging software
let me know if this helps |
March 12, 2011 by kle8309 |
|
March 13, 2011 by Linkster |
Kelvin, |
March 13, 2011 by kle8309 |
// slave1.c // for Caliper DRO with ATmega168p // Kelvin Le // 11-7-2010 define F_CPU 14745600include <stdio.h>include <stdlib.h>include <avr/io.h>include <avr/interrupt.h>include <avr/pgmspace.h>include <inttypes.h>include "../libnerdkits/delay.h"include "../libnerdkits/lcd.h"include "../libnerdkits/uart.h"include "../libnerdkits/spi.h"/* PIN DEF PC5 POWER OUT PC4 CLK IN PULLED HIGH CALIPERS PC3 DAT IN PULLED HIGH CALIPERS PC2 CLK LED OUT PC1 DAT LED OUT PC0 DEBUG LED PB5 SCK IN PB4 MISO OUT PB3 MOSI IN PB2 SS to GND PB1 INTERRUPT IN ISR(PCINT0_vect) */ // these are the data types for data storage // bit 9-16 is 16 bits and 17-24 is 32 bits struct multi_Arr
{
}; /-------------------DRO functions-----------------------/ // this is the hard part uint8_t read(void){
} void digital_read_out(struct multi_Arr *DRO){
} void caliper_power_on(void) { // SET PINS AS INPUT DDRC |= 0x00; // SET PINS AS OUTPUT DDRC |= (1<<PC5)|(1<<PC2)|(1<<PC1)|(1<<PC0); // PULL UP PINS power, clk, and data PORTC|=(1<<PC5)|(1<<PC4)|(1<<PC3); // turning power off and on again will reduces start up error PORTC&=~(1<<PC5);
delay_us(500);
PORTC|=(1<<PC5); } /-------------------------------PACKAGING-----------------------------/ void pack_3_bytes(struct multi_Arr *DRO){ // counter init uint8_t i=0; // clear old reading first for(i=0;i<3;i++) DRO->byte_array[i]=0; // 3 bytes are packed in byte_array
return; } /--------------------------INTERRUPT HANDLING--------------------------/ /-------------------------------MAIN-----------------------------------/ int main() { // spi debug led PCO is defined in caliper_power_on() // start lcd lcd_init();
FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
lcd_clear_and_home(); // update time uint16_t n=40; uint8_t i=0; uint16_t k=0; // turn on caliper caliper_power_on(); // init DRO structure pointer struct multi_Arr *DRO; // allocate memory memory using calloc DRO=(struct multi_Arr *)calloc(1,sizeof(struct multi_Arr)); // skip first dro while(--n>1){
// clear lcd lcd_clear_and_home(); // throw first blank out //SPI_SlaveReceive_char(); while(DRO==NULL){
while(1){
return 0; } |
March 13, 2011 by kle8309 |
Gary,
I have noticed that my old c code pin definitions are different from what I described (for data and clock they were PBX but my new code is PCX).
So I posted the updated version. Just ignore the SPI and interrupt parts (unless you want to send the DRO to another MCU using SPI). The subroutines that are essential are the read(), digital_read_out(), caliper_power_on(), and main(). Of course, the struct multi_Arr also. |
March 13, 2011 by Linkster |
Kelvin, |
March 13, 2011 by Linkster |
Kelvin, |
March 13, 2011 by kle8309 |
Gary,
About the sleep mode, it happens to my calipers too as it try to save power.
But i'm not sure how to turn it back on without reseting the DRO which involves
reseting the power input. |
March 13, 2011 by Linkster |
Tried various combinations with the data/clk pins with no result. I remember seeing the pads for the on/off button. One side was I beleive + and the other side was the activate lead. I know it dosen't lose position during sleep and reactivation so I'm thinking of running another wire from the activation lead to a bjt voltage divider for +1.5 from a MCU PCx. Then write some code to pulse the PCx off and then on every 3 minutes to reset the calipers sleep timer. Should be able to pulse off and on fast enough to hardly notice it happened. |
March 14, 2011 by Linkster |
Turns out that the common to the caliper push buttons are ground and the on/off lead is at +1.65 volts open. Pulling this lead to ground turns caliper on and off. |
March 27, 2011 by Linkster |
Kelvin,
The dro always displays inches even after pushing the mm button on the caliper. The caliper normally defualts to mm on start up and the readout is not acurate unless you display the inches on the caliper. |
March 27, 2011 by kle8309 |
Gary,
I didn't not encounter the issue you are having.
About the 24th bit. It should be high if you are in inches mode. The inches mode should be the one that needs calibration (notice the *1.27 in the code) In mm mode, all you have to do is divide the value by 100. |
March 27, 2011 by Linkster |
so, if inches is (b_24==1); then is millimeters (b_24!=1); ? |
March 27, 2011 by kle8309 |
The 24th bit is the "unit bit". It tells you whether the data should be interpret as inches or mm. High means inches Low means mm Q:"so, if inches is (b_24==1); then is millimeters (b_24!=1); ?" A:Yes I think there is some discrepancy with the if and else statement. Use an LED to help you see where the code is. |
March 30, 2011 by Linkster |
Kelvin, |
March 30, 2011 by kle8309 |
I bought mine calipers on amazon for $20 amazon link |
Please log in to post a reply.
Did you know that LEDs (light emitting diodes) only conduct current in one direction, like normal diodes? Learn more...
|