[C.CC USERS] Working with the ADC in occam:

Dr Peter D Minns minns627 at btinternet.com
Tue Jul 9 17:17:47 BST 2013


Hi Matt

Hope things are OK with you.

The Plumb (28/june version) software looks good and is working fine for my programs so far.

Seems to be problem with the Windows version (same as was happening with the  MAc version) in that we get a syntax error when compiling programs that compile fine on the mac version.

Was trying to produce occam code for the ADC but have not had any success so far.

I started out trying your "Plumbing" PROCs but with no success.

I  then tried making up an occam program using a similar arrangement I had used in C with the Arduino IDE.

Here it is :

-- raw adc using ATMEL registers:
#INCLUDE "plumbing.module"

PROC main()
  SEQ
    PLACED [1]BYTE admux ADMUX:
    PLACED [1]BYTE adcsra ADCSRA:
    PLACED [1]BYTE adcsrb ADCSRB:
    PLACED [1]BYTE didr0 DIDR0:
    PLACED [1]BYTE didr1 DIDR1:
    PLACED [1]BYTE adcl ADCL:
    PLACED [1]BYTE adch ADCH:
    PLACED [1]BYTE ddrd DDRD:
    PLACED [1]BYTE portd PORTD:
    
    SEQ
      admux[0] :=  #40  --ref is 5V, sel ch 0
      adcsra[0] := #86 --Enable ADC, prescalor x 64
      adcsrb[0] := #00 --not using auto-triggering 
      --didr0[0] :=  #3F -- disable digital inputs.
      --didr1[0]  :=  #03 -- likewise to 000 0011
      ddrd[0]  :=  #FF -- portd all outputs.
      adcl[0] := 0
      adch[0] := 0
      portd[0] :=  #00 -- initialise to zero.
      BYTE result:
      --[2]BYTE bytes RETYPES result:
      BOOL going :
      WHILE TRUE
        SEQ
          going := TRUE
          adcsra[0] := 1 << ADSC -- start conversion. Tried 6 as well
          WHILE going
            SEQ
              IF
                ADSC > 0
                  SEQ
                    going := FALSE
                    
                    result := adcl[0]    
                    portd[0] := BYTE result
                TRUE
                  SKIP    
               
:

I also tried your ports[REG] := #value as in ports[ADMUX] := #40
But did not work either (compiled OK).

Perhaps these registers have not yet been added to the compiler?

In C I could use pointers to addresses names, or ATMEL names but as far as I am aware there is no equivalent in occam.

You appear to be using the ATMEL register names for ports as portb, portd ext.

I know you said you were working on the SPI so perhaps I should try that first.  I have a C program for the SPI that I can translate to occam and try it out.  Is this available with Plumb version 20130628?




Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.concurrency.cc/pipermail/users/attachments/20130709/548a1f87/attachment.htm>


More information about the users mailing list