Society of Robots - Robot Forum
Software => Software => Topic started by: czechzilla on September 19, 2010, 08:25:32 PM
-
Greetings everybody, I have a couple of problems/questions about the atmega8 chip.
I recently decided to build a simple automatic soap dispenser just for fun and I am having a couple of programming issues. I have a decent amount of experience with a basic stamp and Ive taken classes in programming before but I just cant seem to get my programs to work for me.
Basically I want to have an IR led/detector to be able to tell when somebody's hand is close and then it will dispense the soap but I cant seem to get the I/O pins to work on the controller. I built the controller following the $50 robot tutorial and I wanted to hook up the emitter to the C pins on the atmega8 controller. So far Ive just been working with a regular led to gain some basic understanding of how the controller works but I can only get one of the pins to turn on. Basically I was just wondering if you guys had any suggestions of what to look at to help gain some understanding on programming or if there is any flaws in my thinking you can point out.
I did have one other question as well, with a basic stamp you can use the rctime command to see how long it takes to charge a capacitor, one example being hooked up to a photoresistor to "calibrate" it for different lighting conditions. Is there anything like that available for the atmel controllers?
Any help that anybody could provide would be awesome.
-
You really need to show us the code and the circuit diagram for us to be able to give you any useful advice :-)
Alternatively, just Google around: there are quite a few "hello world" tutorials on driving LEDs with an ATmega in assembly or C.
You can measure capacitor charging time using a counter and an interrupt, or with a busy loop (e.g., "while (!(PINX & _BV(something))) { _delay_us(xx); counter++; } "), but the exact implementation depends on the hardware arrangement, too.
-
Well the circuit diagram is the same as the $50 robot controller, which can be found here:
http://www.societyofrobots.com/images/sbs_avr_schematic.png (http://www.societyofrobots.com/images/sbs_avr_schematic.png)
This is the code I have to try and turn on the pins for C 0-3
#include <avr/io.h>
#include <util/delay.h>
int main (void)
{
DDRC = 0b00001111;
for ( ; 1==1 ; )
{
PORTC = 0xFF;
_delay_ms(100);
PORTC = 0x00;
_delay_ms(200);
}
return 1;
}
Basically when I run the code above my understanding is that pins 0-3 should be on which would turn those LED's on, but the only pin that is on is pin 5 which I didn't do anything to. Am I missing anything here?
Oh and thank you for the tip on getting the capacitor to work. I will definitely have to try that.
-
This should work, in principle... so you are connecting LEDs to pins 23-26 (PC0-PC3) on PDIP ATmega8, correct?
And you seeing the LED blink only on some other pin? Which one, exactly? PC5 (28) or PD3 (5)?
-
Well I have one LED that Ive just been switching between connecting to those 6 pins, the only one that causes the LED to turn on is PC5 (28) and it doesn't blink, it just stays on constantly.
-
If this is a standard, red indicator LED (i.e., ~2V, 20 mA), then it should work I think, unless there is something I am missing.
Are you sure you programmed the chip successfully? Do you have any other instrument to test it with? I.e., a voltmeter?
You were not making any changes to the fuses, and are not using an external oscillator? Did you configure the default frequency for the chip correctly (1000000 Hz)?
-
Does your compiler have an option, perhaps a "project setting", for the ATmega8 versus other AVRs? Make sure it isn't set to some other mega or ATtiny.
-
Ok so I feel like an idiot. I'm currently using AVR studio to program the controller and when I was programming it, the .hex file that was being uploaded wasn't the one that I was actually editing, it was using a .hex file from a different program so obviously I wasn't seeing any change in response from my controller board.
Thank you guys for all your help anyways, I'm sure at some point I will be needing more of it with all the projects I plan on doing in the future.
-
Don't feel bad. Other people have done that, too.
Not me though. Nope. Never. ;)
-
Alright, I have another question for everybody. I am trying to set up a photoresistor circuit to check the voltage. I basically have the exact same setup as in the $50 robot, except I have the photoresistor connected to the C5 pin I have a led hooked up to turn on and off depending on what voltage the photoresistor is at but its not working for me. I have the following code set up:
#include <avr/io.h>
#include <util/delay.h>
#include "global.h"
#include "a2d.h"
int main (void)
{
int sensor = 0;
int i = 120;
a2dInit();
a2dSetPrescaler(ADC_PRESCALE_DIV32);
a2dSetReference(ADC_REFERENCE_AVCC);
DDRC = 0b00010000; //led is on pin C4
sensor2 = sensor;
while (1)
{
if (sensor > 60)
{
PORTC = 0b00010000;
}
else if (sensor < 60)
{
PORTC = 0x00;
}
_delay_ms (10);
sensor = a2dConvert8bit(5);
}return 1;
return 1;
}
Im assuming its something wrong with the analog to digital converter code but I cant seem to figure out what it is. Any help/suggestions?