rgbp:
Hey guys,
I am trying to get the timer interrupt works. I used your library, also I tried using without library, but
if I set the frequency for 200kHz, I always get a waveform on oscilloscope with the half frequency, so 100kHz.
Is that right? I couldn't get 1MHz as someone said in a post before, the maximum was 585kHz, when I set the frequency for 2MHz.
Someone can help me?
Thanks
//Chirp wave output
//#include <DueTimer.h>
#define TAM 4095
int frequency = 1000000;
volatile int i = 0;
void waveGenerate(){
dacc_write_conversion_data(DACC_INTERFACE, (i=!i)*4095);
//dacc_write_conversion_data(DACC_INTERFACE, sinWave[i++]);
//if(i==4096)
// i=0;
}
void setup(){
Serial.begin(9600);
pinMode(DAC0, OUTPUT);
analogWriteResolution(12);
pmc_enable_periph_clk(DACC_INTERFACE_ID);
dacc_reset(DACC_INTERFACE);
dacc_set_transfer_mode(DACC_INTERFACE, 0);
dacc_set_power_save(DACC_INTERFACE, 0, 1); //Sleep mode = 0 (Normal Mode), Fast Wake Up = 1 (Enabled)
dacc_set_timing(DACC_INTERFACE, 0x0, 1, 0x0); //REFRESH 0x0, MAXS = 1 (Max Speed Mode Enabled), STARTUP = 0 (0 periods of DACClock)
dacc_set_writeprotect(DACC_INTERFACE, 0); //Disable
dacc_set_analog_control(DACC_INTERFACE, DACC_ACR_IBCTLCH0(0x02) |
DACC_ACR_IBCTLCH1(0x02) |
DACC_ACR_IBCTLDACCORE(0x01));
dacc_disable_trigger(DACC_INTERFACE);
dacc_set_channel_selection(DACC_INTERFACE, 0);
dacc_enable_channel(DACC_INTERFACE, 0);
Timer4.attachInterrupt(waveGenerate).setFrequency(frequency).start();
}
void loop(){
}
Notice that:
Setting timer interrupt for 1hz (for example), would generate 1seccond of HIGH and 1 seccond of LOW, read as 0.5hz (1/2 of the interrupt frequency)
If you set it to 200khz, than you would be setting High 100.000 times per seccond, and low 100.000times per seccond. witch is 100.000hz (100khz, or, half of 200khz)
=]