Show Posts
Pages: 1 [2] 3 4 ... 10
16  Using Arduino / Programming Questions / Re: Direct port manipulation using TIMER1 on: December 14, 2012, 07:39:55 am
Issue is the resolution which is fixed at 8 bit. We need a resolution of more than 10bit...
17  Using Arduino / Programming Questions / Direct port manipulation using TIMER1 on: December 14, 2012, 05:06:40 am
Hi,
I need to create 10 different PWM duyt cycle with a MEGA board. As the controller doesn't have so many different PWM duyt cycles I tried to do that by reading the TIMER1 register. I used the onboard LED so everyone reading this topic can try it easily.

I got avery uneven response and the LED is not having a conxtant PWM but having some light flickerings visible... smiley-confuse That shouldn't happen, right?



Here is my code
Code:
#include <avr/io.h>
#include <avr/interrupt.h>

void setup() {               
  // initialize the digital pin as an output.
  DDRB= B11111111; // set PORTB (digital 13-8) to outputs
  cli();          // disable global interrupts
  TCCR1A = 0;     // set entire TCCR1A register to 0
  TCCR1B = 0;     // same for TCCR1B
  TCCR1B |= (1 << CS10);  // Set CS10  bit only for prescaler 1
  sei(); // enable global interrupts:
}


void loop() {


  if (TCNT1 < 5){
    PORTB=B10000000;
  }


  if (TCNT1 > 20000){
    PORTB=B00000000;
  }
}
18  Community / Website and Forum / Playground :: Timer1 :: on: November 27, 2012, 11:45:58 pm
Hi,
I am not sure if this is the right part of the forum.

Anyhow I am struggeling with the calculation of the max period time of Timer1.

The calculation below the timing table says:

Quote
In general:
•Max Period = (Prescale)*(1/Frequency)*(2^17)
•Time per Tick = (Prescale)*(1/Frequency)

As this timer is a 16 bit (65535 counts) I am struggeling with the idea of 2^17 ...this would be 17 bit (131070 counts), wouldn't it? Therefore the max period would be wrong as well...

I am right? If not pls have a short explanation.
19  Using Arduino / Programming Questions / Re: Reading count value from Timer1 on: November 25, 2012, 02:53:35 pm
Hi,
I read the part of the datasheet. The complete 16-bit set can be accessed by reading " TCNT1 " according to 16.11.4 "The two Timer/Counter I/O locations (TCNT1H and TCNT1L, combined TCNT1) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter."

Correct result shown. Thanks for your hint to the right part of the datasheet

Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#define LEDPIN 13
int timer;
long counter;


void setup()
{
  Serial.begin(9600);
  pinMode(LEDPIN, OUTPUT);
  cli();                    // disable global interrupts
  pinMode(2, INPUT);        // Enable Pin2 as input to interrupt
  EIMSK |= (1 << INT0);     // Enable external interrupt INT0  (see table 13-2-2 in Atmel 328 spec)
  EICRA |= (1 << ISC01);    // Trigger INT0 on rising edge (see table 13-1 in Atmel 328 spec)
  EICRA |= (1 << ISC00);    // Trigger INT0 on riding edge (see table 13-1 in Atmel 328 spec)

  // initialize Timer1
  // ZERO Timer1
  TCCR1A = 0;               // set entire TCCR1A register to 0
  TCCR1B = 0;               // same for TCCR1B

  // set compare match register to desired timer count:
  OCR1A = 7000;            // turn on CTC mode:initial value changed in loop
  OCR1B = 14000;            // turn on CTC mode:initial value changed in loop
//TCCR1B |= (1 << WGM12);   // Set CTC mode. Resets the timer after compA has been reached
  TCCR1B |= (1 << CS10);    // prescaler 1024
  TCCR1B |= (1 << CS12);    // prescaler 1024
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt:
  TIMSK1 |= (1 << OCIE1B);  // enable timer compare interrupt:
  sei();                    // Enable global interrupts
}

void loop()
{}
ISR(TIMER1_COMPA_vect){
    counter= TCNT1;
  digitalWrite(LEDPIN, HIGH);
  counter= TCNT1;
Serial.print ("counteran:");

  Serial.println(counter);
}

ISR(TIMER1_COMPB_vect){
  digitalWrite(LEDPIN, LOW);
  Serial.print ("counteraus:");
  counter= TCNT1;
  Serial.println(counter);

TCNT1 = 0; // Reset Timer1 Count
}
20  Using Arduino / Programming Questions / Reading count value from Timer1 on: November 25, 2012, 08:17:45 am
Hi,
I need to read the count value from the Timer1. How can I read out the 16bit value from Timer1? I cannot find a starting point...
21  Topics / Science and Measurement / Using COMPA and COMPB correctly on: November 25, 2012, 07:10:22 am
Hi,
I am struggeling using CAMPA and COMPB correctly. I would like to start an action by an external interrupt on PIN2 (UNO) and start Timer1. After TIMER1 has started it shall use COMPA and COMPB to start certain actions, but NOT resetting the TIMER1.  That reset shall happen later on special command at a later point in time. The script should enable and disable the LED13 on the UNO board.  Here is the code I tried to start with COMPA and COMPB, but the LED won't go off...

Code:
// avr-libc library includes
#include <avr/io.h>
#include <avr/interrupt.h>

#define LEDPIN 13
int timer;
void setup()
{
 
  pinMode(LEDPIN, OUTPUT);
  cli();                    // disable global interrupts
  pinMode(2, INPUT);        // Enable Pin2 as input to interrupt
  EIMSK |= (1 << INT0);     // Enable external interrupt INT0  (see table 13-2-2 in Atmel 328 spec)
  EICRA |= (1 << ISC01);    // Trigger INT0 on rising edge (see table 13-1 in Atmel 328 spec)
  EICRA |= (1 << ISC00);    // Trigger INT0 on riding edge (see table 13-1 in Atmel 328 spec)

  // initialize Timer1
  // ZERO Timer1
  TCCR1A = 0;               // set entire TCCR1A register to 0
  TCCR1B = 0;               // same for TCCR1B

  // set compare match register to desired timer count:
  OCR1A = 15624;            // turn on CTC mode:initial value changed in loop
  OCR1B = 30000;            // turn on CTC mode:initial value changed in loop
  TCCR1B |= (1 << WGM12);   // Set CS10 and CS12 bits for 1024 prescaler:
  TCCR1B |= (1 << CS10);    // prescaler 1024
  TCCR1B |= (1 << CS12);    // prescaler 1024
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt:
  TIMSK1 |= (1 << OCIE1B);  // enable timer compare interrupt:
  sei();                    // Enable global interrupts
}

void loop()
{}
ISR(TIMER1_COMPA_vect){digitalWrite(LEDPIN, HIGH);}
ISR(TIMER1_COMPB_vect){digitalWrite(LEDPIN, LOW);}
22  Using Arduino / Interfacing w/ Software on the Computer / Re: Feeding the UNO EEPROM with external software through USB on: October 09, 2012, 12:37:37 pm
Right- the variables reflecting a specific EEPROM address will be filled one after another when sending the data

4711 12 5 7 9

4711--> write to eeprom
12   -->variable 1--> EEPROM position 1
5     -->variable 2--> EEPROM position 2
7....

Another dataset
4712 12 5 7 9

4711--> write to eeprom
12   -->variable 10--> EEPROM position 10
5     -->variable 11--> EEPROM position 11
7....
23  Using Arduino / Interfacing w/ Software on the Computer / Re: Feeding the UNO EEPROM with external software through USB on: October 09, 2012, 08:47:37 am
So there is NO way of feeding data into the EEPROM through FTDI? I need to accept that...  smiley-sad

May there is a back-door. Here is my idea:
I send the following to the Arduino through the USB: 4711 12 5
Arduino send the confirmation back sending:          12 5

Arduino interprets 4711 as command for writing into the EEPROM. And the values to be written would be 12 and 5. May a mor unique number than 4711 would be good...

24  Using Arduino / Interfacing w/ Software on the Computer / Feeding the UNO EEPROM with external software through USB on: October 09, 2012, 06:49:09 am
Hi,
I am interested in feeding the EEPROM (and only them) with a software without uploading the complete source code and writing through the EEPROM library. I do not know where to start so any hints or tutorials are welcome.
25  Using Arduino / Microcontrollers / Re: Uneven respone to interrupt command on: September 07, 2012, 02:18:40 pm
Dear all,
the essence I am reading is (and please correct me if I am wrong):
  • Change the analoge reading method (posted by Udo Klein). Sounds feasible although I need to regret that I do not have ANY clue regarding lines like "ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);". I need to read and learn!
  • Do not use any other interrupts beside the "ignite" one. No micros(), no millis(). Although this might be correct, I do not know how to establish a variable time delay on microseconds base to change ignition retard... smiley-confuse
26  Using Arduino / Microcontrollers / Re: Uneven respone to interrupt command on: September 05, 2012, 02:28:14 am
That does not work for me. Think about:

1) Analog read with a prescaler set to 16: 104 microseconds (and I have two of them)
2) LCD write with 4bit: takes more than 20 microseconds as well

Both single functoins are far to slow to "wait" for the trigger

What I did was the following

Code:
Pseudocode


setup
attachInterrupt

loop
{
do-other-things
}

function Interrupt action
put PIN13->high
jump to calculate_only_once_after_interrupt


function calculate_only_once_after_interrupt
calculatecalculatecalculatecalculatecalculate


function do-other-things
x=x+1
if x==8->x=1

if x=1
If the last LCD write was more than 25mS away-> write LCD
if x=2
read analog1

if x=2
read analog2

.
.
.

if x=8
write Pinxyz HIGH

The function do-other-things will lead to do one action out of 8 when called. That ensures proper execution of each function.
27  Using Arduino / Microcontrollers / Re: Uneven respone to interrupt command on: September 04, 2012, 09:31:58 am
Graynomad,
sinusoidal signal is coming from a inductive trigger "looking" to the flywheel

I calculated this delay AFTER the ignite to reduce any unforeseeable time delay.
28  Using Arduino / Microcontrollers / Re: Uneven respone to interrupt command on: September 04, 2012, 07:17:23 am
Hi Udo,
I like your approach (without dislike of the other helpful forum member!).
What I try to achieve is to get a 5V trigger signal from outside and kick a 5V signal out after a certain time. I think from my code using functions like "ignite" its clear that this will be an engine ignition.  I receive a trigger from Flywheel and kick the sinusoidal 5V signal (rectangularized by a comparator) out with a certain delay. I will use the "while" command to execute a delay without using "delay()" command.
The tests I have done shown on the osicilloscope where done without any delay function but only immediate putting the PIN to HIGH only.

 
The only thing I need is a consistent execution of ISR...not necessarily a quick one. I need to trust this execution time is correct without jumping around 20microseconds

29  Using Arduino / Microcontrollers / Re: Uneven respone to interrupt command on: September 03, 2012, 08:54:23 am
Yes I do something else between the interrupts (including short analog read and several other calculations, LCD submission...). Pls see my code under "external()".
30  Using Arduino / Microcontrollers / Re: Uneven respone to interrupt command on: September 02, 2012, 11:51:06 pm
In my code I am using the Interrupt0. Do you think it helps using another Interrupt port?
Pages: 1 [2] 3 4 ... 10