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.
If F_CPU doesn't matter, how are delay functions calculated? I mean for something that is time sensitive(Controlling the pulse sent to the servo) it would make sense that F_CPU would be used to find the number of cycles needed to get closest to the delay required. Or do you mean that F_CPU is automatically changed by the compiler depending on the chip being used? To me, C seems much more confusing than assembly, maybe it is because I have taken a class on programming a HC6811 in assembly, but even though I know how to use C in programming on a computer, avr C just boggles my mind.
It seems like in C there are an insane amount of settings that need to be changed when creating a program for an avr, with most of these settings being spread out in multiple header files. I just have a very hard time keeping track of every header file that needs to be included, as well as what things need to be changed.
.include "m32def.inc".def SensorLeft = r19.def SensorRight = r20.def wreg = r21.def T1 = r24.def T2 = r25.equ Multi = 32 ; ~.1ms delay kinda/almost.equ Center = 15 ;~1.5ms delay...Kinda.equ Refresh = 150.equ Servo_Pins = 3 ;Pins not chosen yet.org $0000; Pin D1 will be the left motor; Pin D2 will be the right motorReset:ldi r16, low(RAMEND)out Spl, r16ldi r16, high(RAMEND)out sph, r16ldi wreg, Servo_Pinsout DDRB,wreg sbi ADCSRA, 7 ; Turns the ADC hardware on(Or at least should)sbi ADMUX, 5 ; Selects single run mode? ldi T1, Multildi T2, Centerrjmp MainMain: cbi ADMUX, 0 ; Select Pin 0 of the ADCsbi ADCSRA, 6 ; Tell it to take a conversionldi SensorLeft, ADCHldi wreg, ADCL;Needed only for it to be ready to redo it's conversionsbi ADMUX, 0 ; Select Pin 1 of the ADCsbi ADCSRA, 6 ; Tell it to take a conversionldi SensorRight, ADCHldi wreg, ADCL ; Needed only for it to be ready to redo it's conversion; It should now have the light sensor values needed.; Comparing the different values, to check which light sensor is higherldi T2,100rcall Delay;Uhhhh found out servo's don't like sending a constant repeated signal, this is suppoed to give it some timecp SensorLeft, SensorRightbrsh MotorLeft_Grjmp MotorRight_GMotorLeft_G:ldi wreg, Servo_Pinsout PORTB, wreg; the delay numbers will most likely need to be changed depeneding on how I assemble the robotldi T2, 10rcall Delaycbi PORTB, 0ldi T2, 10rcall Delaycbi PORTB, 1rjmp MainDelay: dec T1brne Delayldi T1, Multidec T2brne DelayretMotorRight_G:ldi wreg, Servo_Pinsout PORTB, wreg; the delay numbers will most likely need to be changed depeneding on how I assemble the robotldi T2, 10rcall Delaycbi PORTB, 1ldi T2, 10rcall Delaycbi PORTB, 0rjmp Main