Go Down

Topic: Timer programming (Read 3 times) previous topic - next topic

dhenry

Quote
In my real program ISR should update a 16bit DAC


If that's the goal, AVR's adc module can be set up to be triggered automatically and periodically. It is fairly easy to set up. I can post a piece of code there if you want.

bubulindo


If that's the goal, AVR's adc module can be set up to be triggered automatically and periodically. It is fairly easy to set up. I can post a piece of code there if you want.


DAC != ADC...


If I understand well the question, value 32 on PORTB set pin 13. I think it doesn't matter which one is the bit I toggle, pin 13 or another.  I know programming timer for fast interrupt, occupy lot of CPU time but if all the CPU job is made by ISR, that is the faster and more precise timing we can obtain and It's what I need. In my real program ISR should update a 16bit DAC, in this code I just set pin 13 for checking the timing on oscilloscope. I haven't tried CTC mode because I don't need really to toggle a bit on a port, I need to update some port and toggle few bits in the interrupt service rountine. But I can't understand why this program doesn't works. I can suppose Arduino compiler puts some extra code on mine but I can't find any confirm to this supposition.


What you did with the 32 was set and reset 4 bytes. Not the port.

If you want to set or reset bits in the Arduino faster, this is the way.
Code: [Select]

//setting
PORTB |= 1 << 5;

//clearing
PORTB &= ~(1 << 5);


PORTB 5 is pin 13 in ARduino.

To toggle a pin:

Code: [Select]
PORTB ^= 1 << 5;

But how does this relate to a DAC???
Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

dhenry

Quote
What you did with the 32 was set and reset 4 bytes.


32 = 1 << 5.

So his code is setting / clearing a particular pin, and is identical to your code.

Quote
But how does this relate to a DAC???


For debugging purposes. He is trying to try to the code so it flips a pin - to be observed by a scope that signals that the timing portion of the code is working. He can then add the DAC portion of the code.

A fairly common way to build up and debug one's code.

bubulindo


For debugging purposes. He is trying to try to the code so it flips a pin - to be observed by a scope that signals that the timing portion of the code is working. He can then add the DAC portion of the code.

A fairly common way to build up and debug one's code.


So why the complex timing arrangement with two timed interrupts keeping the processor busy all the time?
And, most importantly, if the timing part underestimates the load that driving the DAC will have on the program, then all this is useless. First, test the DAC, see how fast can the Arduino drive it without timings and then worry about triggering the times at a rate the arduino can handle. Since no PWM is really needed, go for the simplest timing arrangement, with an overflow or with an Clear to count and overflow to better adjust the desired frequency.

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

dhenry

Quote
So why the complex timing arrangement with two timed interrupts keeping the processor busy all the time?


Not really sure about the "interrupts keeping the processor busy all the time" part. Interrupts are useful precisely because they do not keep the processor busy - they interrupt the processor only when certain conditions are met.

Quote
And, most importantly, if the timing part underestimates the load that driving the DAC will have on the program, ...


I do not know how the DAC part is to be implemented. The DAC could be really fast - a parallel DAC for example, or it could be preloaded by the main loop and strobed / activated by the isr. It could be implemented without causing excessive delays in the isr, rendering your question moot.

Quote
First, test the DAC, ...


Different ways of skinning the cat. Without knowing all the details, it is impossible to assert if one approach is better than another.

Go Up