4-20mA using SPI Interface


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    53

    Post 4-20mA using SPI Interface

    Hi All,

    I came across a 4-20mA board from MicroElektronika which uses the SPI to control the device, has anyone used such a board before?, I am looking for Code Examples, would anyone be able to assist?

    Regards,

    gavo

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: 4-20mA using SPI Interface

    Is it too much to ask to at least post a link to the board in question?
    I could try to find it on their site but I won't so the best answer *I* can give you is that you can use SHIFTOUT to do bitbanged SPI or use the MSSP module (if the PIC has one) to do it "in hardware".

    /Henrik.

  3. #3
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: 4-20mA using SPI Interface

    Hi

    This is some code I wrote to use that board as a basic loop calibrator. Worked OK for me.

    Take care

    Alec

    Code:
    '****************************************************************
    '*  Name    : Encoder test                                      *
    '*  Author  : alec noble                                        *
    '*  Notice  : Copyright (c) 2012 alec noble                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 9/27/2012                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    #CONFIG
        __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    #ENDCONFIG
    
    'DEFINE OSC 20
    
    '************************** setup LCD ****************************
    
    	DEFINE	LCD_DREG	PORTB		' Set Data to PortB
    	DEFINE 	LCD_DBIT	0			' Set starting Data to Bit4
    	DEFINE 	LCD_RSREG   PORTB		' Set Register Select to PortB
    	DEFINE 	LCD_RSBIT   4			' Set RS line to PORTB.4
    	DEFINE 	LCD_EREG	PORTB		' Set Enable to PortB
    	DEFINE 	LCD_EBIT  	5			' Set Enable line to PortB.5
    	DEFINE 	LCD_BITS	4			' Set for 4 bit Bus
    	DEFINE 	LCD_LINES	2			' Set number of lines to 
    
    '*********************************************************************
    CMCON = 7           'comparaters off - digital I/O on port A
    
    trisb = 0           'all bits outputs
    trisa = %00000111   'porta.0, 1, 2 input, all others output
    
    
    
    
    cntr    var word
    cntr_1  var word
    cntr_2  var word
    preset  var byte
    
    sck var porta.6
    sdi var porta.7
    cs  var porta.4
    
    
    cntr = 200
    preset = 0
    cs = 1
    
    lcdout $FE, $01
    pause 5
    lcdout  "ahn_loop_cal"
    
    pause 5000
    
    lcdout $FE, $01
    pause 5
    lcdout dec cntr
    
    '************************  Program **********************************
    
    main:
        if porta.2 = 1 then set
        if porta.0 = 1 then CW
        if porta.1 = 1 then CCW
        goto main
        
        set:
        pause 5
        if porta.2 = 0 then main
        preset = preset + 1
        while porta.2 = 1 : wend
        if preset  > 4 then preset = 0
        lookup2 preset, [200, 400, 600, 800, 1000], cntr
        goto display
        
        CW:
        pause 5
        if porta.0 = 0 then main
        if cntr = 1023 then main
        cntr = cntr + 1
        goto display
        
        
        CCW:
        pause 5
        if porta.1 = 0 then main
        if cntr < 190 then main
        cntr = cntr - 1
        goto display
        
        display:
        cntr_1 = cntr * 4
        lcdout $FE, $01, dec cntr_1, " mV"
        pause 5
        cntr_2 = cntr_1/2
        lcdout $FE, $C0, dec2 cntr_2/100, ".", dec2 cntr_2//100, " mA"
        goto DAC_out
        
    DAC_out:
    
        
        cntr_1.15 = 0
        cntr_1.14 = 0
        cntr_1.13 = 1       'GAIN OF 1
        cntr_1.12 = 1       'turn on DAC output
        low CS
    '    pause 5
        shiftout sdi, sck, 1, [cntr_1\16]
        high cs
            
        while porta.0 or porta.1 = 1
        wend
        
        goto main

  4. #4
    Join Date
    Sep 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Default Re: 4-20mA using SPI Interface

    Hi Alec,

    Many Thanks!, will try it!,

    Hendrik the link is http://www.mikroe.com/click/rs485-5v/

    Regards,

    Gavin

Similar Threads

  1. Creating 4 to 20MA ?
    By amgen in forum Off Topic
    Replies: 10
    Last Post: - 3rd May 2014, 22:45
  2. question about the pin to pin connections on a SPI interface
    By wdmagic in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th January 2013, 13:03
  3. Need to use SPI but I'm already using the SPI port
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th December 2012, 09:52
  4. 4-20mA output using PWM
    By gavo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th December 2007, 09:45
  5. 4-20mA to 0-5V configuration
    By leonel in forum General
    Replies: 0
    Last Post: - 31st August 2005, 12:33

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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