is there anything i need to change about this code in order to make it work with the elegoo nano as everytime i try to verify it is says it can not compile it with the nano. the code was originally written for aduino uno
void XCLK_SETUP(void){
pinMode(9, OUTPUT); //Set pin 9 to output
//Initialize timer 1
//WGM13, WGM12, WGM11 & WGM10 bits SET- Fast PWM mode
//COM1A0 SET- Toggle OC1A on compare match
TCCR1A = (1 << COM1A0) | (1 << WGM11) | (1 << WGM10);
//SET CS10 bit for clock select with no prescaling
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
//Output Compare Register 1A(OCR1A) = 0
//This will lead to a match on every clock cycle
//Toggle OC1A output pin on every match instance
//Therefore, the generated waveform will have half
//the frequency of the driving clock i.e. 8Mhz
//OC1A pin- PB1 (alternate functn) pin i.e. Arduino pin 9
OCR1A = 0;
}
is there anything i need to change about this code in order to make it work with the elegoo nano as everytime i try to verify it is says it can not compile it with the nano. the code was originally written for aduino uno
The posted function is fine because the AT328 chip and its timers are the same for the nano and the uno.
You will have to post a more complete example which gives the error. You can also post the more complete error code given by the compiler.
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `setup'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'
Yes, the snippet will not compile because there is no setup() or loop() function which is required for the Arduino ide.
void XCLK_SETUP(void){
pinMode(9, OUTPUT); //Set pin 9 to output
//Initialize timer 1
//WGM13, WGM12, WGM11 & WGM10 bits SET- Fast PWM mode
//COM1A0 SET- Toggle OC1A on compare match
TCCR1A = (1 << COM1A0) | (1 << WGM11) | (1 << WGM10);
//SET CS10 bit for clock select with no prescaling
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
//Output Compare Register 1A(OCR1A) = 0
//This will lead to a match on every clock cycle
//Toggle OC1A output pin on every match instance
//Therefore, the generated waveform will have half
//the frequency of the driving clock i.e. 8Mhz
//OC1A pin- PB1 (alternate functn) pin i.e. Arduino pin 9
OCR1A = 0;
}
void setup()
{
XCLK_SETUP();
}
void loop()
{}
The only reason I can think of for a sketch to compile successfully on an UNO but fail on a Nano is that the sketch uses too much program (flash) memory on the Nano. The Nano allocates 1.5k bytes more of the program memory for the bootloader.
If the bootloader size is the issue, the Nano can be re-bootloader as an Uno. A small change to boards.txt should allow A6, A7 to be accessed on the Nano:
Change this line
uno.build.variant=standard
to be like the Nano, from standard (which is 6 analog inputs, a hardware package pinout limitation)) to eightanaloginputs: