software: use DAC1 to generate square waves
parent
a569069575
commit
aa02e2ba70
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp"
|
||||
}
|
||||
}
|
|
@ -14,5 +14,5 @@ void setup() {
|
|||
}
|
||||
|
||||
FASTRUN void loop() {
|
||||
generateSine(8150);
|
||||
generateSquareDAC1(1000000, 50);
|
||||
}
|
|
@ -11,8 +11,8 @@ Lower frequency waves using nanoseconds is not needed and could actually causes
|
|||
// Use FASTRUN to run code in RAM
|
||||
FASTRUN void generateSquare(float frequency, int duty){
|
||||
|
||||
digitalWriteFast(DAC1_SEL, HIGH);
|
||||
digitalWriteFast(DAC0_SEL, LOW);
|
||||
digitalWriteFast(DAC0_SEL, LOW);
|
||||
digitalWriteFast(DAC1_SEL, HIGH);
|
||||
|
||||
startGenerating();
|
||||
if(frequency < 1000){
|
||||
|
@ -48,6 +48,9 @@ FASTRUN void generateSquare(float frequency, int duty){
|
|||
}
|
||||
|
||||
FASTRUN void generateSquareDAC1(float frequency, int duty){
|
||||
|
||||
digitalWriteFast(DAC0_SEL, LOW);
|
||||
digitalWriteFast(DAC1_SEL, HIGH);
|
||||
|
||||
startGenerating();
|
||||
if(frequency < 1000){
|
||||
|
|
|
@ -14,10 +14,12 @@ void setupWaves(){
|
|||
//Set DACs resolution to 12 bits
|
||||
analogWriteResolution(12);
|
||||
|
||||
// Enable DAC0, from framework's analogWriteDAC0, place here from higher speeds
|
||||
// Enable DAC0 and DAC1, from framework's analogWriteDAC0/DAC1, place here from higher speeds
|
||||
// Reference voltage is 1.2V
|
||||
SIM_SCGC2 |= SIM_SCGC2_DAC0;
|
||||
DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS;
|
||||
SIM_SCGC2 |= SIM_SCGC2_DAC1;
|
||||
DAC1_C0 = DAC_C0_DACEN | DAC_C0_DACRFS;
|
||||
}
|
||||
|
||||
// Wait time by counting clock cycles
|
||||
|
|
Loading…
Reference in New Issue