collapse

* Posts Recentes

Amplificador - Rockboard HA 1 In-Ear por almamater
[Ontem às 19:13]


O que é isto ? por KammutierSpule
[26 de Março de 2024, 19:35]


Bateria - Portátil por almamater
[25 de Março de 2024, 22:14]


Emulador NES em ESP32 por dropes
[13 de Março de 2024, 21:19]


Escolher Osciloscópio por jm_araujo
[06 de Fevereiro de 2024, 23:07]


TP4056 - Dúvida por dropes
[31 de Janeiro de 2024, 14:13]


Leitura de dados por Porta Serie por jm_araujo
[22 de Janeiro de 2024, 14:00]


Distancia Cabo por jm_araujo
[08 de Janeiro de 2024, 16:30]


Meu novo robô por josecarlos
[06 de Janeiro de 2024, 16:46]


Laser Engraver - Alguém tem? por almamater
[16 de Dezembro de 2023, 14:23]

Autor Tópico: sfr05  (Lida 11894 vezes)

0 Membros e 1 Visitante estão a ver este tópico.

Offline tiagosilva510

  • Mini Robot
  • *
  • Mensagens: 100
Re: sfr05
« Responder #30 em: 29 de Junho de 2011, 23:01 »
e como faço agora pra programar os certos?

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: sfr05
« Responder #31 em: 29 de Junho de 2011, 23:03 »
Depende do que fizeste.
Não consegues nem ler os fuses?
Tens outro Atmega?
Se sim, faz um programa em que simplesmente toglas um pino, ligas esse pino ao pino Xtal1 do atmega bloqueado que tens, e ligas tambem a massa dos dois em conjunto, depois tentas ler a assinatura, se funcionar é porque tens os fuses errados no que toca a cristal/oscilador externo, se não ler, é porque desligas-te o ISP.
Avr fanboy

Offline tiagosilva510

  • Mini Robot
  • *
  • Mensagens: 100
Re: sfr05
« Responder #32 em: 30 de Junho de 2011, 14:59 »
ja esta a funcionar, obrigado senso

Offline tiagosilva510

  • Mini Robot
  • *
  • Mensagens: 100
Re: sfr05
« Responder #33 em: 30 de Junho de 2011, 17:04 »
agora passei ao passo seguinte.. ja coloquei o triger a funcionar.. estou a trabalhar no echo

Código: [Seleccione]
#define F_CPU 1000000
#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>

void startRange(void);
unsigned int echo(void);
void setup(void);

int main(void)
{
setup();

//unsigned int range;

while(1)
{
startRange(); // Send a high on the trigger pin to start a ranging
echo();
}
}

void startRange(void)
{
PORTD = (1<<DDD0); // Send trigger pin high
_delay_us(10);     // Wait 10us...
PORTD = (0<<DDD0); // Send trigger pin low
//_delay_us(10);
}

void setup(void)
{
DDRD = 0b00000001; // Port D pin 0 ouput all others input

}


unsigned int echo(void)
{
unsigned int range;
while((PIND = (1<<DDD1))); // Wait for echo pin to go high,  this indicates the start of the incoming pulse
//TCNT0 = 0x00;
//TCCR0B =0b00000100;
while((PIND = (0<<DDD1))); // Wait for echo pin to go low signaling that the pulse has ended
//TCCR0B = 0x08;
range = TCNT1/29; // Read back value in the timer counter register, this number divided by 29 will give us the range in CM

return(range);
}

preciso de ajuda com esses contadores.. pk faz-me muita confusao a maneira de funcionar os contadores.. n percebo muito de como os por a funcionar..

Cumprimentos

Offline tiagosilva510

  • Mini Robot
  • *
  • Mensagens: 100
Re: sfr05
« Responder #34 em: 01 de Julho de 2011, 21:03 »
nng da uma ajuda?

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: sfr05
« Responder #35 em: 02 de Julho de 2011, 00:08 »
Dá uma leitura no meu tutorial sobre timers:
http://hekilledmywire.wordpress.com/2011/05/28/introduction-to-timers-tutorial-part-6/

É que não configuras nada de nada dos timers e estás á espera que eles como que por milagre funcionem
Avr fanboy

Offline tiagosilva510

  • Mini Robot
  • *
  • Mensagens: 100
Re: sfr05
« Responder #36 em: 04 de Julho de 2011, 19:11 »
vou hoje mesmo ler o teu tutorial :)

agradeço desde ja a ajuda senso ;)

Offline tiagosilva510

  • Mini Robot
  • *
  • Mensagens: 100
Re: sfr05
« Responder #37 em: 20 de Julho de 2011, 20:38 »
nao estou a conseguir gerar uma interrupção com 1micro segundo.. alguem me ajuda? acho que estou a fazer as contas mal

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: sfr05
« Responder #38 em: 20 de Julho de 2011, 22:50 »
1us ou 1ms?
Avr fanboy

Offline tiagosilva510

  • Mini Robot
  • *
  • Mensagens: 100
Re: sfr05
« Responder #39 em: 20 de Julho de 2011, 23:38 »
1 us

Offline tcustodio

  • Mini Robot
  • *
  • Mensagens: 344
  • "beware of programmers who carry a soldering iron"
    • Youtube
Re: sfr05
« Responder #40 em: 21 de Julho de 2011, 00:20 »
segundo o código fonte das funções de delay um delay tão pequeno é impossível...

Citar
void delayMicroseconds(unsigned int us)
{
   // calling avrlib's delay_us() function with low values (e.g. 1 or
   // 2 microseconds) gives delays longer than desired.
   //delay_us(us);

#if F_CPU >= 16000000L
   // for the 16 MHz clock on most Arduino boards

   // for a one-microsecond delay, simply return.  the overhead
   // of the function call yields a delay of approximately 1 1/8 us.
   if (--us == 0)
      return;

   // the following loop takes a quarter of a microsecond (4 cycles)
   // per iteration, so execute it four times for each microsecond of
   // delay requested.
   us <<= 2;

   // account for the time taken in the preceeding commands.
   us -= 2;
#else
   // for the 8 MHz internal clock on the ATmega168

   // for a one- or two-microsecond delay, simply return.  the overhead of
   // the function calls takes more than two microseconds.  can't just
   // subtract two, since us is unsigned; we'd overflow.
   if (--us == 0)
      return;
   if (--us == 0)
      return;

   // the following loop takes half of a microsecond (4 cycles)
   // per iteration, so execute it twice for each microsecond of
   // delay requested.
   us <<= 1;
    
   // partially compensate for the time taken by the preceeding commands.
   // we can't subtract any more than this or we'd overflow w/ small delays.
   us--;
#endif

   // busy wait
   __asm__ __volatile__ (
      "1: sbiw %0,1" "\n\t" // 2 cycles
      "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
   );
}


ali pouco depois do início:
Citar
// for a one-microsecond delay, simply return.  the overhead
   // of the function call yields a delay of approximately 1 1/8 us.
   if (--us == 0)
      return;

:/
Tiago Custódio,
- Não me dêem álcool se estiver um piano por perto.

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: sfr05
« Responder #41 em: 21 de Julho de 2011, 00:24 »
Basta usar um timer de 8 bits, com prescaler a 1 e meter count até 16, mas isso não te dá muito tempo para executar código é usar o modo CTC a fazer o toogle to pino.

Podes fazer delay de 4 instruções ou mais usando o _delay_loop2(unsigned int val)
Avr fanboy

Offline tiagosilva510

  • Mini Robot
  • *
  • Mensagens: 100
Re: sfr05
« Responder #42 em: 23 de Julho de 2011, 21:06 »
o varrimento de leds ja esta feito... agora queria por um buzzer a apitar com maior frequencia qunato menor for a distancia...

Código: [Seleccione]
#define F_CPU 1000000
#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
#include<interrupt.h>

unsigned int distancia=0,distancia_1=0;
unsigned char ler_pino=0,contador=800;

int cont=0;
void startRange(void);
unsigned int echo(void);
void setup(void);


/*ISR(TIMER0_COMPA_vect) {
contador--; //decrementa o contador até chegar a 0 (500ms)
if(contador==0) {
contador=800;
PORTD=~PORTD;// vai negar o estado do led, se estiver aceso apaga e vice versa
}
}*/



int main(void)
{
setup();



while(1)
{
startRange(); // Send a high on the trigger pin to start a ranging
distancia=echo();
distancia_1=((distancia*6)/58);

if(distancia_1>=650){
PORTB = 0b00000001;
// OCR0A=170;
}
if(distancia_1<550){
PORTB = 0b00000011;
// OCR0A=150;
}
if(distancia_1<450){
PORTB = 0b00000111;
// OCR0A=120;
}
if(distancia_1<350){
PORTB = 0b00001111;
// OCR0A=100;
}
if(distancia_1<250){
PORTB = 0b00011111;
// OCR0A=70;
}
if(distancia_1<150){
PORTB = 0b00111111;
// OCR0A=40;
}
if(distancia_1<70){
PORTB = 0b01111111;
// OCR0A=15;

}
_delay_ms(300);
}
}



void startRange(void)
{
PORTC =0b00000001 ; // Send trigger pin high
_delay_ms(15);     // Wait 10us...
PORTC = 0b00000000; // Send trigger pin low
}

unsigned int echo(){
unsigned int cont_sonar=0;
ler_pino=PINC&0b00000010;
while(ler_pino!=0b00000010)
ler_pino=PINC&0b00000010;
while(ler_pino!=0b00000000)
{
cont_sonar++;
ler_pino=PINC&0b00000010;
}

return cont_sonar;
}
void setup(void)
{
DDRC = 0b00000001; // Port D pin 0 ouput all others input
DDRB = 0b01111111;
PORTB = 0b00000000;
DDRD = 0b00000001;
TIMSK0=TIMSK0|2; //habilita a flag de interrupção do TC0
SREG=SREG|0X80; //HABILITA AS INTERRUPÇOES GLOBAIS
TCCR0A=0b10000011; //Timer0A
TCCR0B=0b00000100; //prescaler 256
}

tou a tentar fazer isso atravez do OCR0A mas n tou a conseguir.. alguem me ajuda?