PIC based DRO - Page 2

Page 2 of 6 FirstFirst 12345 ... LastLast
Results 21 to 40 of 113

Thread: PIC based DRO

  1. #21
    Member
    Join Date
    Jun 2007
    Location
    Australia
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default

    Hmm..I think i found another hole im my theory about using pics to link encoders to steppers.It would be feasible to control one stepper that way but I guess would be a problem when integrating X,Y, and Z when interpolated on a g2 for example. If one took a bit longer to correct a couple of missed steps, it would throw the whole move out of wack. I guess you could have some way of all 3 PICs knowing what each of the others is doing.



  2. #22
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default Comparator Overview

    Bill,

    I am having trouble simply reading the 90KHz clock single from the scales using just about every method I can think of, be it through a separate comparator, an opamp configured as a comparator, and even a combination of NPN and PNP transistors.

    Can you give us a little insight into how you are using the comparators on the chip to accomplish this and as well a little description of why there are LEDs connected to the clock and data lines.

    I've also read conflicting info on whether or not the signal from the scales is +1.5v high and 0 low, -1.5v high and 0 low or some combination of those. I have an oscilloscope being delivered today which should help ME see what's going on.

    As of now, all I see is 3 "pulses" per second on the clock. However, using a homebrew soundcard oscilloscope technique I can definitely see that it's outputting the usual 2*24. Unfortunately the card doesn't record fast enough to see the clock, just the basic outline of it which looks like this _/-|-\_ (pardon the wonderful ascii rendition) hehe The -'s there are obviously the clocking which ends up somewhere between high and low because it can't resolve on the soundcard.

    ok so I'm all ears.

    Thanks!



  3. #23
    Registered
    Join Date
    Mar 2007
    Location
    UK
    Posts
    534
    Downloads
    0
    Uploads
    0

    Default

    This was my circuit to convert scale volts to TTL. Screwed it to the back of the scale, putting new mounting holes on the PCB isolated the scale.

    Resistor pair R7 and R8 are there to hold the scale within the range of the comparators. 100k was not enough, needs a cap. Had a nasty surprise when I found the scale frame was connected to + on the battery so I had to isolate the scale steel bar to

    Attached Thumbnails Attached Thumbnails PIC based DRO-scale-jpg  


  4. #24
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    Hi Jon,

    The scale's signal polarity is conventional i.e. positive = hi, complicated by the fact that the battery +ve terminal is connected to the body of the scale making the 'signal ground' actually -1.5v. I've compensated for this by making my PIC's Vss -1.5v and Vdd +3.5. Once this is done the PIC sees a 1.5v pulse into the comparator's inputs

    The resistor and LED circuit is to simply limit the voltage to about 1v2 when the PIC is driving the CLK and DATA lines. The PIC drives the CLK and DATA lines hi to reset the scale and switch modes (e.g. from slow 300mS to fast 20mS update)

    Reading the data from the scale is simply a matter of

    a) setting the comparator to compare the CLK input with the internal Vref (set at about 0.75v)
    b) wait for clock = hi (by testing the comparator's o/p)
    c) wait for clock = lo
    d) switch comparator input to DATA line
    e) test comparator o/p (switch carry bit as necessary)
    f) shift data into store

    g) loop for 24 bits for binary scale incremental and again for absolute

    Below is the assembly code (it's fairly well commented, so it shouldn't be too difficult to read):

    Note: there are two types of scale data.
    1)Binary 1/20480th of an inch (in two 24bit words one incremental from last zero, one absolute from power on [battery insert])
    2)BCD - which has 6 4bit nibbles representing the display data plus 4bits mode info (Sign, 1/2 thou, mm/inch, not-used)

    My code reads either type, by first counting the number of CLK pulses to determine the type of scale connected to the PIC, then jumping to the appropriate routine.


    Code:
    ;(c) W.K.Todd 2005
    ;Read data bits from Vernier scale
    ;V2.00 - uses on-chip comparator for both inputs
    ;GP0 - data
    ;GP1 - clock
    ;------------------------------------------------------------------
    ;vernier data is 24bits (lsb first) absolute position 
    ;followed by 24bits relative pos (as displayed) 
    ;clock remains high for 50uS between data bursts
    ;each bit represents 20480th of an inch  
    ;data is valid on falling edge of clock
    ;Clock is high for 50uS prior to first valid clock edge 
    ;------------------------------------------------------------------
    ;4bit digit output from new verniers
    ;
    ;verniers tx data as 7 nibbles, first 6 nibbles are display digits lsd-msd,
    ;7th nibble is: Sign bit(1=-ve), Half thou bit(1=0.0005"), mm/inch bit(1=mm), always high bit
    ;Data is valid on falling edge of clock
    ;Clock is high for 50uS prior to first valid clock edge 
    ;-------------------------------------------------------------------
    ;Vdata	equ	0x00	;4 bytes shift register
    ;			;Vdata = MSByte
    ;			;Vdata+1 = NSB
    ;			;Vdata+2 = nsb+1
    ;			;Vdata+3 = LSByte
    ;
    ;initialise comparator etc
    ;
    VInit	BSF	status,RP0	;select bank 1		
    	movlw	B'10100011' 	;set Vref ~ 0.75v, Vdd = 5v;(24/5)* 0.75 
    	movwf	VRCON
    	BCF	status,RP0	;select bank 0
    	movlw	B'00010110'	;multiplex in, int ref output inverted, output
    	movwf	CMCON
    	return
    ;
    ;get vernier data into buffer
    ;
    GetVD	bcf	CMCON,CIS	;switch comp to clk input
    	btfsc	Mode,Vtype
    	goto	GetVDD		;get vernier decimal data
    	
    	call	synlp	;gvd	
    	call	GetVDB		;get and discard ABS
    		
    GetVDB	movlw	0x80		;set hi bit of shift register
    	movwf	Vdata
    	clrf	Vdata+1		;set-up for 24bits
    	clrf	Vdata+2
    	clrf	vdata+3
    	
    
    cphlp	btfss	CMCON,COUT	;wait for  clock to go high
    	goto	cphlp
    	bcf	status,c	;clear carry ready
    ;wait clock low - grab bit
    cpllp	btfsc	CMCON,COUT
    	goto	cpllp
    	bsf	CMCON,CIS	;switch comp to data input
    	btfsc	CMCON,COUT	;test data bit
    	bsf	status,c	;set carry if data = 1
    	rrf	Vdata,f		;roll bit into msb buffer...
    	rrf	Vdata+1,f	;then...
    	rrf	Vdata+2,f	;into lsb.
    	bcf	CMCON,CIS	;switch comp to clk input
    	btfss	status,c	;exit when 24 bits shifted
    	goto	cpllp
    	return
    
    ;sync - wait for clock low for >1mS	
    synlp	btfsc	CMCON,COUT
    	clrf	Vdata+3		;use Vdata+3 as temp timer
    	decfsz	Vdata+3,f
    	goto	synlp
    	return
    
    ;
    ;get decimal vernier data
    ;
    GetVDD	movlw	Vdata+3
    	movwf	FSR		;set indirection pointer
    ;set up nibble counter
    	clrf	vdata+3
    	call	synlp
    	movlw	0x08
    	call	VDbyte		;first nibble 1
    	decf	FSR,f		;Vdata+2
    	movlw	0x80
    	call	VDbyte		;2&3
    	decf	FSR,f		;Vdata+1
    	movlw	0x80
    	call	VDbyte		;4&5
    	decf	FSR,f		;Vdata
    	movlw	0x80		;get last byte 6&flags
    
    VDbyte				;get byte or nibble 
    	movwf	INDF
    cphlp1	btfss	CMCON,COUT	;wait for  clock to go high
    	goto	cphlp1
    	bcf	status,c
    cpllp1	btfsc	CMCON,COUT
    	goto	cpllp1	
    	bsf	CMCON,CIS	;switch comp to data input
    	btfsc	CMCON,COUT	;test data bit
    	bsf	status,c	;set carry if data = 1
    	rrf	INDF,f		;roll bit into msb buffer...	
    	bcf	CMCON,CIS	;switch comp to clk input
    	btfss	status,c	;exit when 8 bits shifted
    	goto	cpllp1
    	return
    
    ;measure the vernier reading speed (300mS slow,20mS fast)
    measure		bcf	CMCON,CIS	;switch comp to clk input
    		call	synlp		;wait for clock low >1mS
    		bcf	Mode,Fflg
    ;if clock occurs within ~25mS then Fast flag will be set
    		movlw	25
    		movwf	vdata		;borrow vdata as counter
    m2lp		btfsc	CMCON,COUT
    		bsf	Mode,Fflg	;
    		decfsz	vdata+3,f
    		goto	m2lp	
    		decfsz	vdata,f
    		goto	m2lp
    		return
    
    ;
    ;check vernier type by counting clock pulses
    ;
    GetVT	bcf	CMCON,CIS	;switch comp to clk input
    	call	synlp		;wait for clock low
    	clrf	vdata+1		;used as timer
    	movlw	30
    	movwf	vdata+2		;clock pulse counter
    vthlp	btfss	CMCON,COUT	;wait for  clock to go high 
    	goto	vthlp
    
    cntlp	btfsc	CMCON,COUT	;wait for clock low
    	goto	cntlp
    	decf	vdata+2,f	;count bit
    	clrf	vdata+1		;used as timer	
    cnthp	btfsc	CMCON,COUT	;wait for clock high  or timeout
    	goto	cntlp		;if clock hi then wait for clock low
    	decfsz	Vdata+1,f	;exit loop if low >~1mS
    	goto	cnthp
    	bcf	Mode,Vtype
    	btfss	Vdata+2,7	;test if >30 clock pulses
    	bsf	Mode,Vtype	;if not then flag as new type vernier
    	return


    Attached Thumbnails Attached Thumbnails PIC based DRO-multi-scale-jpg  
    Last edited by BillTodd; 07-08-2009 at 02:56 PM. Reason: adding picture
    Bill


  5. #25
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default Thanks!

    Ok cool! Thank you both of you for the info. That's basically what I needed and I don't know how I overlooked the necessity of the LEDS for the using clock and data to set the mode and zero.

    I do have another question though... Where did you source the -1.5v for ground? The scale's ground?

    Sorry if this is obvious, I'm still learning and I gotta start somewhere



  6. #26
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    If you squint at my picture long enough you should be able to make out a 5v regulator with a resistor + Red LED giving about 1v5 above the regulator's 0v, this is taken to the common ground so giving -1v5 (regulator 0v and PIC Vss) & +3v5 (reg +5v and PIC Vdd) from a floating PSU input.
    Where did you source the -1.5v for ground? The scale's ground?
    No, the scales ground (battery +ve) is the same as the PC's ground i.e. Earth potential, the -1v5 is the scale's power supply input (battery -ve).

    Bill


  7. #27
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by BillTodd View Post
    If you squint at my picture long enough you should be able to make out a 5v regulator with a resistor + Red LED giving about 1v5 above the regulator's 0v, this is taken to the common ground so giving -1v5 (regulator 0v and PIC Vss) & +3v5 (reg +5v and PIC Vdd) from a floating PSU input.


    No, the scales ground (battery +ve) is the same as the PC's ground i.e. Earth potential, the -1v5 is the scale's power supply input (battery -ve).
    Oh my... I appologize. I was too busy looking at the code and I didn't scroll down far enough to see the picture you attached. I was referencing the diagram on your site.

    Almost time to go home so I can work on something fun.



  8. #28
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default ugh

    Well after some extensive messing around it seems that I need to learn assembly... I've been programming these little chips for awhile now using MikroC and it's worked quite well until now. Unfortunately, it looks as though the code just doesn't run fast enough to pick up those 90khz signals unless it's done in assembly. Simply reading the value of COUT is taking serval intructions (when you look at the assembly version), which just isn't necessary.

    No biggy Knowing assembly should make using the datasheets much simpler!

    Be back soon!



  9. #29
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    Well after some extensive messing around it seems that I need to learn assembly
    PIC assembler is easy only 35(?) instructions (it's the carry that always throws me - is it set or reset after subtraction???? - catches me out every time!)

    I don't think HLLs like 'C' are ideal for programming these little controller chips. PICs in particular benefit greatly from careful optimisation even in when writing in assembler.

    Is it possible to embed and call assembler routines in your version of C?

    Bill


  10. #30
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default

    I can place assembly directly into the C code and have done that with some minor things... However, I'm not certain how to use them together in a looping or conditional situation.



  11. #31
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    If you want to just concentrate on the convert and display device, and are happy using async serial instead of I2C, I could let you have a copy of my obect code and a run down of the interface protocol? (may even have the board design somewhere)

    Bill


  12. #32
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by BillTodd View Post
    If you want to just concentrate on the convert and display device, and are happy using async serial instead of I2C, I could let you have a copy of my obect code and a run down of the interface protocol? (may even have the board design somewhere)
    Actually that would be really nice... I've been spending some time the last few days getting a grasp on programming the PIC's in assembly. It's really quite interesting. I probably won't use your code directly and as more of a guideline. Not because I think I could do it better, but because I still want to learn assembly for these chips.

    If you have a larger picture of the scale schematic you posted that would help quite a bit.

    Thanks again for all of your help.



  13. #33
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    I've been spending some time the last few days getting a grasp on programming the PIC's in assembly.
    Like most things, you have to get your knowledge up to a 'critical mass' Once you can get the thing to compile you're pretty much there [these days I find the 'mass' evaporates faster and faster - I have to top-up every time I revisit it!]

    won't use your code directly and as more of a guideline.
    It might just confuse you (I learnt 'assembly' years ago programming Z80s with simple assemblers, so I don't use a fraction of the newer assembler/compiler's capabilities)

    The source should open with MPLab 8 or later.

    Keep us informed of your progress

    Attached Thumbnails Attached Thumbnails PIC based DRO-multichannel-reader-pdf  
    Attached Files Attached Files
    Bill


  14. #34
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default YAY!

    Alright so I've made some pretty decent progress!

    After going through the typical blinking LED, input, etc. stuff I finally decided to take a crack at reading this signal. To my surprise, my first try worked!

    I decided my first step should be simply determining if the PIC was reading the signal correctly. This was done by turning a pin on when it sensed the clock was high and turning it off once the clock went back low. This turned out to be surprisingly simple and FAST... Here is the little bit that does that portion:

    Code:
    RL1		btfss	CMCON,COUT	;wait for clock high
    		GOTO RL1
    		XORWF	GPIO,5		;toggle GP5
    RL2		btfsc	CMCON,COUT	;wait for clock low
    		GOTO RL2		
    		XORWF	GPIO,5		;toggle GP5
    		GOTO RL1
    I then connected one channel of my oscilloscope to GP5 on the PIC and one channel to the scales output (which was also going into the pic).

    Check out the result in the attached image. The red line is the output from the PIC and the blue line is the output from the scale... They were both being read at the same time.

    I would like to add that I could NOT get this to work correctly using MikroC... Nothing against it, but the speed difference is quite obvious.

    Attached Thumbnails Attached Thumbnails PIC based DRO-scale_vs_pic-jpg  


  15. #35
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default Quick update...

    One little change to that code... GPIO,5 should actually be GPIO,1

    Code:
    RL1		btfss	CMCON,COUT	;wait for clock high
    		GOTO RL1
    		XORWF	GPIO,1		;toggle GP5
    RL2		btfsc	CMCON,COUT	;wait for clock low
    		GOTO RL2		
    		XORWF	GPIO,1		;toggle GP5
    		GOTO RL1




  16. #36
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    You're a fast learner

    Be aware there pitfalls if you talk to the GPIO using those infamous read-modify-write instructions sometimes you get away with it sometimes you don't (there's full explanation on the microchip site).

    Bill


  17. #37
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default

    You know, I've been looking through your code and I've reached a bit of a dilema...

    You've really done a fantastic job and from what I can tell, if I were to do it on my own... I'd just be reinventing the wheel and in the end, come up with basically the same thing. (there's only so many ways to do it...)

    So, I think I am going to concentrate on part 2 of this which is the display/control end of things. The plan is to connect all of these to a single 16F883 which will manage the scales and display the info on a small LCD.

    The 16F883 has hardware USART so, that part's done for me

    Gonna do this in assembly so wish me luck. The LCD should prove interesting... It has a standard HD44780 controller.



  18. #38
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    The plan is to connect all of these to a single 16F883 which will manage the scales and display the info on a small LCD.
    I was thinking of doing the same in order to replace the PC. Care to share?

    The 16F883 has hardware USART so, that part's done for me
    The DRO displays need to be updated as fast as possible (to make it feel right on the lathe/mill). This means using the scale's fast 20mS mode. With three (or four) axes to display this gives you 5-6mS to collect, parse, convert and display the binary/bcd to inches and/or millimetres.

    Incidentally, I find the simultaneous display of Inch & mm very useful on the mill.

    Gonna do this in assembly so wish me luck.
    The binary/bcd inch/metric conversion maths may be easier in C.


    The LCD should prove interesting... It has a standard HD44780 controller.
    No that's easy (initialising the 44780 can be a pain). I have some four bit driver code if need it. However, I suggest you make your interface 8 bit, since it'll give you the option of using a VFD module (when you find the LCD unreadable )


    Attached is a zip with a compiled version of the PIC code and the VB5 DRO application installer.

    The app' has a sort of 'demo' mode, so you can look at it and play with out an interface. Either of my interfaces - single com-port powered or multi channel will work with it. One of these days, I'll finish of the MDI version.

    I'll try to put together a typical interface protocol conversation for you later.

    Attached Files Attached Files
    Bill


  19. #39
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default

    Awesome, thanks for the code. I'll have to play around with it when I get home this evening.

    I agree on possibly just writing the program in C. I already know C well and there are built in routines for handling the LCD in either 4 or 8 bit mode. Given the chip's built in usart, the only real code is going to be handling the commands to and from the scales and the conversion of incoming data.

    I suppose I can always practice my assembly on some future project Maybe I'll rewrite the software I used on my stepper driver boards using assembly... hmmm

    As for sharing, of course... I'll share everything I have once things are completed. MikroC spits out an asm file as well, so that might be worth looking at by someone that knows whats what... Could most definately be improved.

    I will keep you updated.



  20. #40
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    How's it going?

    Bill


Page 2 of 6 FirstFirst 12345 ... LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

PIC based DRO

PIC based DRO