Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more. Accepting essential orders - here's how.
0

Capacitance Measurement
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

by mikewitt on Sun Mar 11, 2007 1:50 pm

There actually weren't any errors, just warnings (and they're still there) which I don't even know what they mean

Here's the warnings:
C:\cap_src>make all

-------- begin --------
avr-gcc (GCC) 4.1.1 (WinAVR 20070122)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling C: cap_src_2313.c
avr-gcc -c -mmcu=attiny2313 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char
-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-
adhlns=./cap_src_2313.lst -std=gnu99 -Wundef -MMD -MP -MF .dep/cap_src_2313.o.d
cap_src_2313.c -o cap_src_2313.o
cap_src_2313.c: In function 'main':
cap_src_2313.c:210: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
cap_src_2313.c:238: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
cap_src_2313.c:239: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
cap_src_2313.c:240: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
cap_src_2313.c:241: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
cap_src_2313.c:245: warning: passing argument 2 of 'eeprom_read_block' makes pointer from integer without a cast
cap_src_2313.c:253: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
cap_src_2313.c:254: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
cap_src_2313.c:255: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
cap_src_2313.c:256: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
cap_src_2313.c:260: warning: passing argument 2 of 'eeprom_read_block' makes pointer from integer without a cast


Linking: cap_src_2313.elf
avr-gcc -mmcu=attiny2313 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -fu
nsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adh
lns=cap_src_2313.o -std=gnu99 -Wundef -MMD -MP -MF .dep/cap_src_2313.elf.d cap_
src_2313.o --output cap_src_2313.elf -Wl,-Map=cap_src_2313.map,--cref -lm

Creating load file for Flash: cap_src_2313.hex
avr-objcopy -O ihex -R .eeprom cap_src_2313.elf cap_src_2313.hex
-------- end --------

rm cap_src_2313.o

C:\cap_src>make program-cap
avrdude -p attiny2313 -P com2 -c dasa -U flash:w:cap_src_2313.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e910a
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "cap_src_2313.hex"
avrdude: input file cap_src_2313.hex auto detected as Intel Hex
avrdude: writing flash (1848 bytes):

Writing | ################################################## | 100% 4.73s

avrdude: 1848 bytes of flash written
avrdude: verifying flash memory against cap_src_2313.hex:
avrdude: load data flash data from input file cap_src_2313.hex:
avrdude: input file cap_src_2313.hex auto detected as Intel Hex
avrdude: input file cap_src_2313.hex contains 1848 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 4.36s

avrdude: verifying ...
avrdude: 1848 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.


C:\cap_src>


I have no idea what that even means, so I can't fix it. But it works anyway.
mikewitt
 
Posts: 111
Joined: Thu Jan 04, 2007 9:18 pm
Location: KB9YJY, Wilmette, IL

by Olaf Marzocchi on Sun Mar 11, 2007 3:09 pm

Sorry, I meant which errors made your original code not to work? the differences between your code and the avrfreaks one.

About the warning, no problems if the code works. It says the function eeprom_write_byte expects a pointer as first argument, while you passed it an integer.

If you are new to C: a pointer is a "link" to something else. If the code works, probably the compiler substituted the integer indexX with its memry address.

Mh, well, the explanation should be longer, but maybe it's better to read a couple of paragraphs from the Kernighan & Ritchie C language manual.
Olaf Marzocchi
 
Posts: 73
Joined: Mon May 08, 2006 3:29 am

by mikewitt on Sun Mar 11, 2007 5:19 pm

The difference between my code and the AVR Freaks one is that it uses Timer0 and Timer1 to count the frequency, whereas my idea was to use the rising edge of the 555 circuit to trigger interrupt1, then it would toggle back and forth between states, the first state counting clock cycles between interrupts, the second using those counted clock cycles to figure out frequency. My way didn't work, the function I used (it's called startTimer) would only get through one cycle before being interrupted, so it always read the signal as 8MHz (Which my scope said was false).

Also, I use an LCD I got from SparkFun electronics with the SerLCD backpack, so I just feed the backpack a U(S)ART signal at 9600N1. Also, using USART allows the counter to communicate more universally to either other MCUs or, like in my case, to an LCD.

About the pointers, I've gotten rid of a few of the problem ones, but I need to read up on how to get rid of the others (when it's just a variable by itself, add an '&' in front.)
mikewitt
 
Posts: 111
Joined: Thu Jan 04, 2007 9:18 pm
Location: KB9YJY, Wilmette, IL

by mikewitt on Sun Mar 11, 2007 6:53 pm

Schematics: (note that the xtal is optional, if you don't use the xtal, no c2 or c3 either--see atmel datasheet for values. c1 should be at least 1000 uF, but it can be more. It can also be polarized.)
Image
mikewitt
 
Posts: 111
Joined: Thu Jan 04, 2007 9:18 pm
Location: KB9YJY, Wilmette, IL

by Olaf Marzocchi on Sun Mar 11, 2007 8:57 pm

Thank you for the explanation.

Q1 is just to turn off the 555, right?

xtal> I have a 12 MHz crystal, maybe I can use it, but I think I will have to set the 2313 working frequency to 24 MHz (it should be the maximum allowed).
Olaf Marzocchi
 
Posts: 73
Joined: Mon May 08, 2006 3:29 am

by mikewitt on Sun Mar 11, 2007 9:07 pm

Yeah, Q1 just turns off the 555 circuit. It helps eliminate noise when the device is being programmed.

About the Xtal, the ATTiny2313 is only rated to 20MHz (Although the ones I have are rated at only 10). To use the xtal, you need to burn the cksel fuses to 111 (in your case, because your xtal is faster than 8MHz), and set the SUT fuses to 11 (because the huge cap we have takes a couple ms to charge up). The datasheet also says you should use 12-22pF caps for c2 and c3. These values will work for any xtal greater than 8MHz (i.e. your 12MHz xtal)
mikewitt
 
Posts: 111
Joined: Thu Jan 04, 2007 9:18 pm
Location: KB9YJY, Wilmette, IL

by Olaf Marzocchi on Mon Mar 12, 2007 5:25 pm

mikewitt wrote:About the Xtal, the ATTiny2313 is only rated to 20MHz


I remember the same thing, but I have a spec sheet with this line:

–ATtiny2313: 0 - 12 MHz @ 2.7 - 5.5V, 0 - 24 MHz @ 4.5 - 5.5V

So I thought they improved the specs.

About the schematics: can you suggest an LCD as well? I have no experience with them.
Olaf Marzocchi
 
Posts: 73
Joined: Mon May 08, 2006 3:29 am

by mikewitt on Mon Mar 12, 2007 6:14 pm

The LCD I use is from SparkFun electronics, the one I use is this one: http://www.sparkfun.com/commerce/product_info.php?products_id=813
and it works great, the specs are right there on their site. It communicates via a 9600 baud UART (which is one wire) with one start bit, one stop bit, and no parity. You send it ASCII characters, and it displays them.

The UART interface is provided through the backpack, otherwise you need about 11 I/O lines, and you have to figure out how to implement the HD44780 interface (which is publicly available, just more complicated than I care to figure out). The backpack just makes it easier.

SparkFun also has lots of other LCDs, so if you don't like white on black, they have other colors to choose from as well. In any event, the backpack makes communication incredibly easy.
mikewitt
 
Posts: 111
Joined: Thu Jan 04, 2007 9:18 pm
Location: KB9YJY, Wilmette, IL

by mikewitt on Mon Mar 12, 2007 8:57 pm

I've finally taken some photos of my setup:
Image
Scary, no?

Image


Image
mikewitt
 
Posts: 111
Joined: Thu Jan 04, 2007 9:18 pm
Location: KB9YJY, Wilmette, IL

by Olaf Marzocchi on Tue Mar 13, 2007 4:55 am

WOW
Olaf Marzocchi
 
Posts: 73
Joined: Mon May 08, 2006 3:29 am

by mikewitt on Tue Mar 13, 2007 10:24 pm

I just cleaned it up:
Image
Image

Those should be more usable.
mikewitt
 
Posts: 111
Joined: Thu Jan 04, 2007 9:18 pm
Location: KB9YJY, Wilmette, IL

by mikewitt on Wed Mar 14, 2007 7:21 pm

Updated the source, now _MUCH_ smaller, (about half of the size it was, and now no warnings) no EEPROM calls, etc...

I've put it in a new location, because I'm going to be adding a couple new things to it when I get a chance.

For now here's the new path to the source: (old source is still up)
http://witt.michael.googlepages.com/cap_src_v2.zip
mikewitt
 
Posts: 111
Joined: Thu Jan 04, 2007 9:18 pm
Location: KB9YJY, Wilmette, IL

by adafruit on Wed Mar 14, 2007 7:39 pm

awesome project!

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

by Olaf Marzocchi on Wed Mar 14, 2007 8:00 pm

Yes, I agree.

Only the LCD, with its price, is a bit overkill to me (I live in Europe and I would spend more than 30 euros for it, for the same price I can find a complete capacimeter), so I will have to find something to replace it. Maybe a 7-segment led, or maybe an lcd from a broken nokia phone. I saw some ready libraries.

But this is a really good project, you can also see clearly the development.

BTW: have you tried it with big capacitors? something in the mF range.
Olaf Marzocchi
 
Posts: 73
Joined: Mon May 08, 2006 3:29 am

by mikewitt on Wed Mar 14, 2007 11:05 pm

I tried it with a 1000uF cap, and it doesn't exactly work, 1000uF is 1,000,000,000 fF, and it is only a 9,999,999 count meter, so that won't work. Also, at that large of a capacitance value, the freqency is low, so it doesn't work too well. Now that the code is down to only 1.1kb on flash, I'm going to start adding auto ranging soon (and maybe work with some digital potentiometers too...).

EDIT:
Also, about the LCD, if it's just shipping, SparkFun has resellers in Europe, the LCD I use is here: http://robosavvy.com/store/product_info.php/products_id/218, and there's another reseller in france. While it does work out to about 26 euros (before shipping and VAT) it's money well spent, because it will work in the future, and it uses screw terminals which means no soldering (not that soldering is bad, just you don't need to worry about using it in a different project). It uses UART as well, which many of the Atmel AVRs have built in, so it's extremely easy to interface with, whereas a broken Nokia LCD will take lots of code to program for as well as lots of I/Os and will be hard to connect.
mikewitt
 
Posts: 111
Joined: Thu Jan 04, 2007 9:18 pm
Location: KB9YJY, Wilmette, IL

Please be positive and constructive with your questions and comments.