Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <util/delay.h>
- volatile uint32_t ul_count;
- void InitTimer1(){
- // initialize Timer1
- TCCR1A = 0;
- TCCR1B = 0;
- TCCR1B |= (1 << WGM12);
- TCCR1B |= (1 << CS11);
- OCR1A = 1999;
- }
- void InitAnalogComp(){
- // Configurar
- // Entrada no inversora: AIN0
- // Entrada inversora: ADC0
- ADCSRB|=(1<<ACME);
- }
- ISR(TIMER1_COMPA_vect){
- ul_count++;
- }
- float calcular_C(uint32_t ul_count){
- return (ul_count/100.0);
- }
- int main(void){
- cli(); // disable global interrupts
- Serial.begin(115200); // USART a 115200 bps
- DDRB |= (1 << DDB4); //PORT B4 como salida
- InitAnalogComp();
- InitTimer1();
- ul_count = 0;
- sei(); // Enable global interrupts
- while(1){
- // Enable timer1 interrupt mask for compare match A
- TCNT1 = 0;
- TIMSK1 |= (1 << OCIE1A); // Turn on the timer
- PORTB |= (1 << PB4); // (pin 12 = HIGH)
- while((ACSR & (1 << ACO))); // Wait to 63% of charge.
- TIMSK1 &= ~(1 << OCIE1A); // Turn off the timer
- PORTB &= ~(1 << PB4); // (pin 12 = LOW)
- // Enviar el valor de tau en (unidad de tiempo??)
- Serial.print("Tau = ");
- Serial.println(ul_count);
- //Implementar una funcion que calcule C: float CalcularC(ul_count, R)
- Serial.print("C=");
- Serial.println((float)calcular_C(ul_count));
- ul_count = 0;
- // Esperar 5 segundos para la próxima medición
- _delay_ms(5000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement