PICAXE-08M2 DAC sample rate

dvd

New Member
I would like to send a pre-code signal at a fixed sample rate to the ADC.

  1. I am trying to understand what the upper sample rate is of the DAC on the 08M2 (or any other picaxe chip).
  2. How do I control said sample rate? Do I just introduce a pause between writing samples?
  3. Can anybody point me to a code example for this?
 

hippy

Technical Support
Staff member
I am not sure anyone has actually measured the maximum update rate of the DAC. It is basically however quickly you can issue DACLEVEL commands and you could use PAUSE or PAUSEUS commands between DACLEVEL commands.

This test programs sets the DACLEVEL 100 times consecutively on an 18M2 at 4MHz -

Code:
#Picaxe 18M2
#No_Data

#Define DAC2    DacLevel 31 : DacLevel 0

#Define DAC10   DAC2   DAC2   DAC2   DAC2   DAC2
#Define DAC50   DAC10  DAC10  DAC10  DAC10  DAC10
#Define DAC100  DAC50  DAC50

; DAC output on C.2 leg 1
; SYN output on C.1 leg 18

DacSetup %10100000 ; 0V / V+
Do
  High C.1
  DAC100
  Low C.1
  Pause 10
Loop
The high pulse on C.1 lasts just about 54.6ms so it's a DAC update about every 546us at 4MHz. About every 70us at 32MHz.

DAC.jpg
 

radiosparks

Member
DUH!, I must have missed something, somewhere. I just realized that you can nest #define, cool. Sorry for being a bit slow. :geek:
 

fernando_g

Senior Member
I am sorry to derail this discussion, but I don't understand what is the purpose of:
#Define DAC10 DAC2 DAC2 DAC2 DAC2 DAC2
#Define DAC50 DAC10 DAC10 DAC10 DAC10 DAC10
#Define DAC100 DAC50 DAC50

And how this operates to generate 100 iterations of the do:loop

Before anyone asks, yes, I have consulted manual 2.
 

cpedw

Senior Member
It's easiest understood IMHO starting at the bottom:
The line DAC 100 in the DO...LOOP is replaced by DAC 50 DAC 50 because of the #Define DAC 100 line. Then those DAC 50s are in turn replaced by DAC10 DAC10 DAC10 DAC10 DAC10 twice because of the #Define DAC50 ... line. Then each DAC 10 is replaced by 5 DAC 2s so there are 50 DAC 2s and each of those was defined to switch the DAC output up then down.
At least I think that's what happens!
 

fernando_g

Senior Member
Oooooooooooook. I get it. Well, let's say that I believe I get it.

But the next question begs: Why one has to do this in the first place? Is DAC100 on its own an invalid statement?
 

Buzby

Senior Member
Although the use of multiple nested #define loops is clever, I think it is not the best way to demonstrate to a beginner.

The result of the nested defines is this :

Code:
; DAC output on C.2 leg 1
; SYN output on C.1 leg 18

DacSetup %10100000 ; 0V / V+
Do
  High C.1
  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0  DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0   DacLevel 31 : DacLevel 0
  Low C.1
  Pause 10
Loop
The expanded #defines give one huge long line containing a hundred DacLevel commands !.
 
Top