16Mhz on atmegs238p

An area to discuss AVR and Arduino specific problems and examples

Moderator: Benj

chrisbooth1957
Posts: 26
Joined: Tue May 23, 2017 1:55 am
Been thanked: 1 time
Contact:

16Mhz on atmegs238p

Postby chrisbooth1957 » Wed Aug 23, 2017 12:41 am

i think i have found the problem with the DMX recive ( slave)i asume it needs the controler to run at the correct speed , i have writed a simple program to flash a led and it goes at twice the speed it should then i noticed you dont support the 16mhz controlers used in the nano and uno , only the 3v version is 8 mhs

i did a sort of fix as on the drop down menue i can select a clock speed of 19660800 ( no idea what this strange number ) but there is no option at all for it a 16mhz clock this is closer but still not ideal

this will i am sure cacth out other people as it is easer to program a nano using the avr programer and header as it saves 2k of program space for the booot loader , i have not checked if the uno runs at the correect speed but you may want to check as i know there are 2 versions of the arduino nano the 3.3 v version is 8mhz the normal 5v version 16 mhz

you will notice if you look most development boards for atmegs328 are 16 mhz

i just checked and it is curious you do list the 3.3v nano but have that as a 16mhz device when it is 8mhz , very strange that if i use the chip directly you only support 8mhz and yet if i use the same chip an an arduno board you only support 16 mhz ... i know i can compiled to hex with the chip set as a nano then upload . i will try that tomorow

this link may help re clock speeds https://learn.sparkfun.com/tutorials/ar ... ison-guide

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8536
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3525 times
Contact:

Re: 16Mhz on atmegs238p

Postby medelec35 » Wed Aug 23, 2017 8:20 am

Hi Chris,
chrisbooth1957 wrote:i noticed you dont support the 16mhz controlers used in the nano and uno

When starting a new project or Choose a target from project Options menu, you select the Arduino range by first selecting AVR then in the Family drop down menu select Arduino:
NanoUno.png
(131.09 KiB) Not downloaded yet


As you can see the clock speed is set at 16000000 by default.
You can manually edit the clock speed.
If I wanted to change the clock speed myself, then rather selecting 19660800, I would select 10000000 then just delete the left most 0 and enter 6 to leave 16000000.

Martin
These users thanked the author medelec35 for the post:
LeighM (Wed Aug 23, 2017 8:48 am)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

chrisbooth1957
Posts: 26
Joined: Tue May 23, 2017 1:55 am
Been thanked: 1 time
Contact:

Re: 16Mhz on atmegs238p

Postby chrisbooth1957 » Wed Aug 23, 2017 1:38 pm

thank you that worked for the atmegs328 chip but strangly does not for the arduino boards that use the chip , not a problem for me at the moment but will be for anyone trying to use the 3.3v version of a nano that runs at 8 mhz

i think it is a little bit confusing as you have a downward arrow and can select clock speeds on the atmega328 but dont have the common speed there to select from ie 16 mhz mhz , and in the fuse settings only talked about 8 mhz for the fuse setings

chrisbooth1957
Posts: 26
Joined: Tue May 23, 2017 1:55 am
Been thanked: 1 time
Contact:

Re: 16Mhz on atmegs238p

Postby chrisbooth1957 » Thu Aug 24, 2017 10:44 pm

thank you , i am working through the dmx slave again double checking things again ie clock speed. the reason i wanted to use the atmegs328 chip at 16mhz it get rid of the arduno boot loader as suspected that may be messing up the dmx slave , using hardware as recomended here but still the same problems with the dmx recive in that it apears to only be able to recive the first 10 channels as it should even if i set the number of channels to 512 , i am using the (getdatachannel(dmxaddress ) where dmx address is a 16bit variable . it appears to work if i set the dmxaddress to 0-9 but as soon as i hit 10 the channels are all over the place , i have the recive called in an interupt and leds set to light if the channel is 128 or greater . as soon as i change the address to 10 the led flashes , i cant see reason it should not work . has anyone here managed to get the dmx slave to work ?

update if i set the max number of dmx channels to 20 it appears to work but the problem there is as i am unable to set the start address from within the program i need to recive the full 512 channels and just use the 4 i need

chrisbooth1957
Posts: 26
Joined: Tue May 23, 2017 1:55 am
Been thanked: 1 time
Contact:

Re: 16Mhz on atmegs238p

Postby chrisbooth1957 » Fri Aug 25, 2017 10:02 pm

this may be part of the problem it appears the recive requires one start bit , 8 data bits and 2 stop bits but your uart component does not appear to support that format ? when i have looked at doing the recive the hard way
Attachments
AN3315.pdf
dmx spec
(506.26 KiB) Downloaded 59 times

derfleznew
Posts: 3
Joined: Wed Aug 09, 2017 7:30 pm
Contact:

Re: 16Mhz on atmegs238p

Postby derfleznew » Sat Aug 26, 2017 1:48 am

We had this same issue. We used the ATMEGA328P on our board design, and use a 16 MHz clock (common). So, by trial and error, we figured out that you can manually enter 16000000. While this seems to be OK, we are having major fits with addressing a Microchip MCP9600 I2C thermocouple chip, where the chip is randomly returning values for temperature that are missing bit 3 in the upper byte. We identified this as a timing issue (verified by scope), and might be that the FlowCode7 component for I2C has a flaw in it, relative to clock speeds. Or this could be related to the manual entered 16 MHz value and component bug. Not sure how to verify this. Very frustrating for sure.

chrisbooth1957
Posts: 26
Joined: Tue May 23, 2017 1:55 am
Been thanked: 1 time
Contact:

Re: 16Mhz on atmegs238p

Postby chrisbooth1957 » Thu Sep 07, 2017 9:21 pm

thank you that is very interesting as the i2c gave me major problems untill i set it to 100k , there was then the anoying problem of the changed not being saved so i had to do the same change of i2c speed every time i loaded the program . this has now been fixed so it saves the changes

i have now come to a simular conclusion as stolen an arduno dmx recive skecth that did some of what i wanted . modified it and added the i2c display and it worked first time on the same hardware that flowcode has trouble with . the sad part for flowcode is i now have it 95% writen in c and it workes and took me a fraction of the time i used fighting with flowcode

chrisbooth1957
Posts: 26
Joined: Tue May 23, 2017 1:55 am
Been thanked: 1 time
Contact:

Re: 16Mhz on atmegs238p

Postby chrisbooth1957 » Sat Sep 09, 2017 2:09 am

thank you for putting me on the right track maybe flowcode can look at fixing this bug as it makes the dmxslave unuseable with the atmega328 and probably other simular chips , below are my findings

i changed the crystal to 20 mhz on an uno as the chip should be able to work at that and it is a suported frequincy on flowcode but it does not work , the crystal on the one that workes most of the time was in fact 12mhz not 16mhz i never thought to check that and i have another uno clone with a 12 mhz crystal , i am still not convinced that this is the only problem as i cant get the dmx slave to work on an arduino nano ( it will work but is very un reliable) . from my other post you will see i now have this hardware working as it should writen in c so cant see how it can be a hardware problem

where it gets very interesting i am using a avr programer to program the chips so have the option of overwriting the arduino boot loader and writing direct to the chip

the uno with 20 mhz crystel works if i compile it for an arduno uno at 16mhz and uplode the hex file , but if i compile for an atmega328p at 20 mhz it does not work , it runs but does not recive dmx at all,all the buttons and display work , same if i change the frequancy to 16mhz same problem . i would have expected dmx to be fairly tolerent of an incorect frequince so that explaines why the 20 mhs workes when compiled for 16mhz uno and the 12 mhz workes both approx 25% out

it cant be anything to do with fuse setings as i am not changing then when i use the code compiled for the arduno and that workes , i have the box unticked that writes the fuse bits and they appear to be the correct setings on flowcode and i have the clock devide by8 disabled

this is not a real fix as i am stuck to only using a 16mhz crystal and cant use chips not supotred by arduino ie attiny at atmega32