​ ​ ​ ​ M2 chips: Can Serial Out pin be overridden to become a DAC input? - Page 2
Page 2 of 2 FirstFirst 1 2
Results 11 to 14 of 14

Thread: M2 chips: Can Serial Out pin be overridden to become a DAC input?

  1. #11
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,741

    Default

    Rather than implement as you envisage currently; is there some other way that what you need can be achieved which is actually implementable ? That is, approach it from the perspective of what inputs you have and what you want to achieve. Could you even do some of what you want purely in software ?

  2. #12
    Senior Member
    Join Date
    Jan 1970
    Location
    Groningen, The Netherlands
    Posts
    467

    Default

    Indeed, with a small change in the analog part (the amplifier stage IC2b just before the comparator) it can be done I think: Just shifting the reference DC output voltage of that stage to a lower one (to be experimentally defined, something like 0.5V, sufficiently high to be able to discriminate between noise and the signal, sufficiently low to secure small-enough DAC voltage steps) I think the Picaxe DAC can be perfectly used with Vref- internally connected to GND:

    Dacdiscussion2.JPG

    The comparator output can then be routed to the interrupt logic. I have to see whether I can implement an SETINTFLAGS-like M2 implementation or otherwise route the comparator output externally to an input pin with a SETINT interrupt (or alternatively even to the gate of Timer1 to count the spikes automatically although that precludes the use of the neat Time variable on the M2)

    Some further research to be done, but it seems all well possible right now
    /Jurjen

    PS: maybe good to clarify the goal of this circuit: I want to determine the photon-related number of spikes/second (above noise level, so therefore this circuit as a programmable noise canceler)
    Last edited by kranenborg; 07-06-2012 at 11:03.

  3. #13
    Senior Member
    Join Date
    Jan 1970
    Location
    Groningen, The Netherlands
    Posts
    467

    Default

    Hello,

    Some investigations by my son and me seem to indicate that it should be possible on M2 chips to detect very fast spikes (above a certain noise level) using an interrupt (faster that the polled interrupt system generally can catch, and possibly equally fast as the hardware X2 interrupts). The following is a principal scheme of the setup that we tested (on a 08M2 , but also feasible on a 14M2, but not 18M2):

    SpikeDetector.jpg

    The DAC-comparator combination acts as a programmable noise canceler (Vref_DAC should be somewhat larger than the maximum expected noise amplitude), subsequently the SR-Latch acts as a memory bit to store the occurence of the fast event. This then can be discovered by the polled interrupt routine (SETINT only checks for interrupt conditions in between BASIC commands, it appears not to latch any interrupt conditions during command execution), which then uses the SRRESET command to reset the latch (and thereby remove the interrupt condition). The interrupt routine should of course only perform very basic and fast operations in order to allow the next event to be detected.

    The documented code that we have used follows later, but it is nice to see that by using some of the chip's internal modules it seems to be possible to overcome the speed limitation of the PICAXE polled interrupt concept as well as implement the programmable noise canceler, all without any extra components. Only the comparator needs to be configured using POKESFR operations, both the DAC and the latch can be configured using supporting BASIC commands only (even though formally the M2 version of the SRLATCH command does not support the comparator set option)

    Best regards,
    Jurjen & Joost
    Last edited by kranenborg; 12-06-2012 at 12:22.

  4. #14
    Senior Member
    Join Date
    Jan 1970
    Location
    Groningen, The Netherlands
    Posts
    467

    Default

    The following code for a simple test setup (described in the code as well) shows how fast events (in this case generated by a button press) can be counted using the configuration as described in the previous post. It shows which kind of initializations are needed to connect the different modules to each other according to the above diagram:

    Code:
    REM *****************************************************
    REM * Test: Fast spike detection using interrupts on M2 *
    REM * Jurjen Kranenborg, June 2012                      *
    REM * Reports number of key presses after 10 secs       *
    REM *                                                   *
    REM * The test code connects:                           *
    REM * - DAC                                             *
    REM * - Comparator (Yes, the M2 has one or more too)!   *
    REM * - SR-Latch                                        *
    REM * - Interrupt-enabled input                         * 
    REM * to detect fast events using standard polled       *
    REM * interrupt structure (SETINT)                      *
    REM *****************************************************
    
    #picaxe-08m2
    #no_data
    
    
    REM SYMBOL Declarations:
    REM --------------------
    
    REM Relevant settings for DAC
    REM with maximum output level (31/32 of input at Vref_DAC)
    SYMBOL DACCONFIG = %10000100
    SYMBOL DACTESTLEVEL = 31
    
    REM Relevant register addresses ansd settings for the comparator 
    REM (See PIC12F1840 datasheet)
    REM These settings imply that the comparator takes the DAC output and an input pin
    REM as inputs, and the comparator output is not routed to an external pin:
    
    SYMBOL CM1CON0 = %01010001		'Comparator Control register 0
    SYMBOL CM1CON1 = %01010010		'Comparator Control register 1
    SYMBOL CMOUT 	= %01010101		'Comparator Output register 
    
    SYMBOL valCM1CON0 = %10000100		'Comparator Control register 0 value
    SYMBOL valCM1CON1 = %00010001		'Comparator Control register 1 value
    SYMBOL valCMOUT 	= %00000000	'Comparator Output register value
    
    REM SRLatch configuration
    REM - use 28X2 definition for SRConfig2 to let the C1 comparator output set the latch
    REM - (not "officially" supported for M2 yet it works!)
    
    SYMBOL SRConfig1 = %10001000
    SYMBOL SRConfig2 = %00010000
    
    REM Hardware I/O connections 08M2:
    
    '                   Vcc
    '                    |
    '       -----        |
    '     -|+ ¤ -|-     22k
    '     -|-> C0|-      |
    '   ---|C4 C1|-------| (Vref_DAC)
    '  |  -|C3 C2|- SRQ  |
    ' >  |  -----  |    22k
    '  |  ----<----      |
    ' ---               ---
    
    Symbol SRLatchOutput = C.2	'Connected to IntInput
    Symbol SwitchInput = C.4	'Internal pullup enabled for this test setup only
    Symbol IntInput = C.3		'Connected to SRLatchOutput
    Symbol Vref_DAC = C.1		'Defined as Vref+ input for DAC using DACSETUP
    
    REM Interrupt defs (SETINT): Active-high polled interrupt on C.3 input
    
    SYMBOL INTcondition = %00001000
    SYMBOL INTmask = %00001000
    
    REM Variables:
    
    SYMBOL Counter = w1	'counter for number of key presses
    
    REM --------------------
    REM END of SYMBOL declarations
    
    
    
    REM Initialization:
    REM --------------
    
    REM DAC and Comparator initialization (See SYMBOL declarations).
    DACSETUP DACCONFIG
    DACLEVEL DACTESTLEVEL
    POKESFR CMOUT, valCMOUT
    POKESFR CM1CON0, valCM1CON0
    POKESFR CM1CON1, valCM1CON1
    
    REM SR-Latch configuration:
    SRLATCH SRConfig1, SRConfig2
    SRRESET
    OUTPUT SRLatchOutput
    
    
    
    REM *****
    REM MAIN:
    REM *****
    
    PULLUP %00010000	'at switch input -> only for this test setup!
    ENABLETIME		'Start counting seconds
    SETINT INTcondition, INTmask
    
    REM count number of button presses during 10 secs
    DO
    	DO 	
    	LOOP UNTIL time  >= 10
    	
    	SERTXD ("Counter: ", #Counter, CR, LF)	
    	
    	LET Counter = 0
    	LET time = 0
    	
    LOOP
    
    
    INTERRUPT:
    	PAUSE 200	'Key debounce effect, remove this line for other apps
    	SRRESET
    	INC Counter
    	SETINT INTcondition, INTmask
    	RETURN
    /Jurjen
    Last edited by kranenborg; 15-06-2012 at 00:48.

Bookmarks

Posting Permissions

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