Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
You could try connecting its output straight to an a/d input. It will likely vary the value.
Quote from: paulstreats on January 25, 2009, 06:06:18 PMYou could try connecting its output straight to an a/d input. It will likely vary the value.Are you sure?If the duty cycle is constant, the voltage is also constant. In this case it will be 0.5 * VmaxI would go with the interrupt technique and measure the period. What is the min/max frequency of the signal?Michel.
I've read another post here that goes over a technique that basically measures the length of a single pulse by resetting a timer when the pulse goes high, start counting with the timer, and then stopping and reading the timer value when the pulse goes low. Would this be a good method, and if so, how exactly would one go about implementing this technique in software for the Axon?
You could try connecting its output straight to an a/d input. It will likely vary the value.Are you sure?If the duty cycle is constant, the voltage is also constant. In this case it will be 0.5 * VmaxI would go with the interrupt technique and measure the period. What is the min/max frequency of the signal?Michel.
#define pulse_out PORTC#define ICP PIND,6void control(void){ TCCR1B=0X02;timerAttach(1,timer_ovf_isr()); timerAttach(4,timer1_capt_isr()); }
#include "global.h"unsigned char ov_counter; unsigned int rising_edge; unsigned int falling_edge; unsigned long pulse_clocks;void timer_ovf_isr(void) { ov_counter++; }void timer1_capt_isr(void){if(ICP){rising_edge=ICR1;TCCR1B=TCCR1B & 0xBF;ov_counter=0;}else{falling_edge=ICR1;TCCR1B=TCCR1B | 0x40;pulse_clocks=(unsigned long)falling_edge - (unsigned long) rising_edge + (unsigned long)ov_counter * 0x10000;pulse_out=pulse_clocks/500;}}
//SoR Include#include "SoR_Utils.h" //includes all the technical stuff#include "hardware.c" //declare hardware variables and ports//#include "CMUcam.c"//#include "Blackfin_Axon.c" //files for Blackfin Robot camera#include "control.c" //your code goes in here#include "pwm.c"#include "converter.c"//#include "timer640.c"//#include "axon_test.c" //include this is doing a function test for the Axonint main(void) { //declare variables here int i=0;//useless variable int j=0;//useless variable /****************INITIALIZATIONS*******************/ //other stuff Im experimenting with for SoR uartInit(); // initialize the UART (serial port) uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection uartSetBaudRate(2, 38400); // set UARTH speed uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx) rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf timer0Init(); // initialize the timer system TIMSK1=0x24; configure_ports(); // configure which ports are analog, digital, etc. a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage LED_on(); rprintf("\r\nSystem Warming Up"); //let system stabelize for X time for(i=0;i<=16;i++) { delay_cycles(5000); rprintf("."); } delay_cycles(6000); //read each ADC once to get it working accurately for(i=0;i<16;i++) j=a2dConvert8bit(i); LED_off(); /**************************************************/ /*********ADD YOUR CODE BELOW THIS LINE **********/ rprintf("Initialization Complete \r\n"); //wait until user pushes button while(!button_pressed()); reset_timer(); rprintf("\r\n init"); control();//use this for your code delay_cycles(1000);//an optional small delay to prevent crazy oscillations /*********ADD YOUR CODE ABOVE THIS LINE **********/ //return 0; }
Yep, the op said that the square wave frequency changes due to light intensity. An a/d port will take an average reading (provided that the pwm is above around 600hz). If you use a small value capacitor as well, this will act as a low pass filter and provide a more stable reading. It is a crudeish system, but is one that is used quite often and is simpler than the ccp method. (its how systems that dont have capture compare facilities work with pwm signals instead of paying more for a frequency/voltage converter).It is worth looking into the capture compare ports though... they are more accurate if you have them available. (if you are working with the axon then it is likely that the board admin has written a library to make using the ccp easier, try messaging him for more info.)