Go Down

Topic: How do I use the clock output on atmega328p? (Read 5259 times) previous topic - next topic

motola212

Hi,

I'm trying to interface a thermopile sensor with my arduino duemilanove with atmega328p 16Mhz.
The sensor is working with an odd version of SPI and I need to feed it with 1Mhz clock.
I use the arduino-0022 environment.
I defined f_cpu 1000000UL in the software.
I connected the clock pin to the arduino pin no. 8.
I changed the low fuse in the boards.txt to 0x80.
When sniffing the pin with arduinoscope I can see voltage running trough it but so does any other pin I sniff (which wasn't defined by pinMode).

The Atmega328p datasheet say that:

Quote
the normal operation of I/O
pin will be overridden when the fuse is programmed

but when I call pinMode(8, OUTPUT), the arduinoscope show me that the voltage in pin8 is 0.
What am I doing wrong?

Hope that there is someone out there that can help a frustrated man...

Thanks,
Yoel

Osgeld

changing th fuse setting in boards.txt wont do anything until you go to bootload another chip
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

motola212

I burned the program to the chip after the changes if that what you mean. If not, please explain.

MarkT

You almost certainly don't want to change the fuses - the SPI clock isn't a continuous clock, it sends bursts of 8 pulses only.  (Though you did say it was an odd SPI I suppose...)

It's possible to set the SPI clock to 8, 4, 2, 1MHz, 500, 250, 125kHz (Assuming a 16MHz system clock).  The fastest SPI rate is half the system clock.

What is the sensor? - someone may well have interfaced to it before on here...

And the fuses are not programmed when a sketch is downloaded, only the application area of flash memory is overwritten.  An ISP programmer is needed to change fuses or bootloader area.
[ I won't respond to messages, use the forum please ]

motola212

This sensor is called HTPA from heimann, I doubt it if anyone tried to interface it but I will be glad to meet him  ;)
The sensor need to be feed with the chip Master clock as well as the SPI clock (two different legs), that is why I need it.
Is there another way to get a 1Mhz clock to this sensor?
About the fuses, I thought that the arduino doesn't need a programmer like the STK does, I just use my AVRKSP II.

Yoel

Coding Badly


Each timer is able to directly manipulate up to two output pins.  I suggest you configure Timer 1 or Timer 2 to toggle an output pin at 1 MHz.  The datasheet and this should help...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1289879390

MarkT

I think you might mean one of this series?  http://www.heimannsensor.com/Heimann_Sensor_complete_Datasheet_HTPA_Rev6-1.pdf

That indeed requires an external 1MHz clock in addition to  SPI clock and data.  I think the CONT input controls whether the device acts as SPI slave or master and there's only one data pin for both modes - not really SPI!  In master mode it clocks at half the master clock so I think its safe to assume it can handle 500kHz SPI clock on SCLK_IO

BTW here's code that should set pin 3 to 1MHz - it uses timer2 and the normal analogWrite function for pins 3 and 11 won't be available if you do this.

Note that the pin and timer assignments are different on the Arduino Mega - this code is for standard Arduino only:
Code: [Select]

#define PWMout 3

void setup ()
{
 TCCR2A = 0xB3 ; // fast PWM with programmed TOP val
 TCCR2B = 0x09 ; // divide by 1 prescale
 TCNT2  = 0x00 ;
 OCR2A  = 0x0F ; // TOP = 15, cycles every 16 clocks
 OCR2B  = 0x07 ; // COMP for pin3
 pinMode (PWMout, OUTPUT) ;

 ...
}
[ I won't respond to messages, use the forum please ]

motola212

MarkT...

I think I'm in love with you  :)
It worked!
And the sensor gives a signal!
No matter what other bad stuff will happen, tonight I can sleep like a baby (Unless my baby will wake me up).

Thank you all for your help, for now  ;)
Yoel.

MarkT

Great!  If you can't sleep there's always the ATmega328 datasheets to read LOL.
[ I won't respond to messages, use the forum please ]

MarkT

Incidentally are those sensors expensive - I've just seen the thermal image examples on their website for the 32x31 pixel version - a low cost thermal imaging camera would be very very sweet...
[ I won't respond to messages, use the forum please ]

motola212

They are cheap only if you buy them in stocks (like 1000pcs.).
1 sensor of 8x8 costs several hundred US dollars.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy