Pages: [1]   Go Down
Author Topic: How do I use the clock output on atmega328p?  (Read 3943 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

changing th fuse setting in boards.txt wont do anything until you go to bootload another chip
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12048
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This sensor is called HTPA from heimann, I doubt it if anyone tried to interface it but I will be glad to meet him  smiley-wink
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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 206
Posts: 12847
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12048
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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) ;

  ...
}
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

MarkT...

I think I'm in love with you  smiley
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  smiley-wink
Yoel.
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12048
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great!  If you can't sleep there's always the ATmega328 datasheets to read LOL.
Logged

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

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12048
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: