dcf77 simulator

Hello!
Help me with code:
(Arduino: 1.6.7 (Windows 10), Плата:“Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)”

C:\arduino-1.6.7\Projects\DCF77_simulator\main\main.ino: In function ‘void timer1_init()’:

main:304: error: ‘OCR1C’ was not declared in this scope

OCR1C = 204;

^

main:308: error: ‘TCCR1’ was not declared in this scope

TCCR1 = (1<<CTC1)|(1 << CS10) | (1 << PWM1A) | (1 << COM1A1);

^

main:308: error: ‘CTC1’ was not declared in this scope

TCCR1 = (1<<CTC1)|(1 << CS10) | (1 << PWM1A) | (1 << COM1A1);

^

main:308: error: ‘PWM1A’ was not declared in this scope

TCCR1 = (1<<CTC1)|(1 << CS10) | (1 << PWM1A) | (1 << COM1A1);

^

C:\arduino-1.6.7\Projects\DCF77_simulator\main\main.ino: In function ‘void __vector_12()’:

main:335: error: ‘OCR1C’ was not declared in this scope

if (irq_counter&0b00000001) OCR1C=206; else OCR1C=205;

^

main:335: error: ‘OCR1C’ was not declared in this scope

if (irq_counter&0b00000001) OCR1C=206; else OCR1C=205;

^

exit status 1
‘OCR1C’ was not declared in this scope at the end)
#include <avr/io.h>
#include <stdint.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/wdt.h>
#include <stdbool.h>

#define FLAG_TENTH_SECOND 0
#define FLAG_SECOND 1

#define DCF_DATA_SIZE 8

#define DCF_DATA_STARTBIT 20
#define DCF_DATA_MEZ_1 17
#define DCF_DATA_MEZ_2 18

#define DCF_DATA_MINUTE 21
#define DCF_DATA_MINUTE_LENGTH 7
#define DCF_DATA_MINUTE_PARITY 28

#define DCF_DATA_HOUR 29
#define DCF_DATA_HOUR_LENGTH 6
#define DCF_DATA_HOUR_PARITY 35

#define DCF_DATA_DAY 36
#define DCF_DATA_DAY_LENGTH 6

#define DCF_DATA_WEEKDAY 42
#define DCF_DATA_WEEKDAY_LENGTH 3

#define DCF_DATA_MONTH 45
#define DCF_DATA_MONTH_LENGTH 5

#define DCF_DATA_YEAR 50
#define DCF_DATA_YEAR_LENGTH 8
#define DCF_DATA_DATE_PARITY 58

#define INT_TO_BCD(x) ((((x) / 10 )<< 4) + ((x) % 10))

volatile uint8_t flags;

static void timer0_init();
static void timer1_init();
static void portb_init();
static void bit_set(uint8_t* bits, uint8_t bit);
static void bits_clear(uint8_t* bits, uint8_t size);
static void dcf_calculate(uint8_t* dcf_data);
uint8_t bits_data_write(uint8_t* bits, uint8_t data, uint8_t startpos,
uint8_t length);

static uint8_t month_length(uint8_t month, uint8_t year);

int main(void) {

uint8_t dcf_data[DCF_DATA_SIZE];
uint8_t dcf_counter = 0;
uint8_t tenth_second_counter = 0;
bool output_value = false;

bool dcf_data_bit = false;

int i;

wdt_disable();
portb_init();
_delay_ms(1000);
timer1_init();
timer0_init();

sei();

dcf_calculate(dcf_data);

while (1) {

if (flags & (1 << FLAG_TENTH_SECOND)) {

flags &= ~(1 << FLAG_TENTH_SECOND);

//Start of a new Second
//get Data Bit from DCF Data Memory
if (tenth_second_counter == 0) {

if (dcf_data[0] & 0b00000001)
dcf_data_bit = true;
else
dcf_data_bit = false;

//Shift entire DCF Data Memory 1 Bit to the Right
for (i = 0; i < DCF_DATA_SIZE; i++) {
dcf_data >>= 1;
if (i < (DCF_DATA_SIZE - 1)) {
if (dcf_data[i + 1] & 0b00000001)
dcf_data |= 0b10000000;
}
}
}
//generate output (100 or 200 ms, No output in Second 59)
output_value = false;
if (tenth_second_counter == 0)
output_value = true;
if ((tenth_second_counter == 1) && dcf_data_bit)
output_value = true;
if (dcf_counter == 59)
output_value = false;
//Write output data to Port
if (output_value)
DDRB |= 0b00000001;
else
DDRB &= 0b11111110;
tenth_second_counter++;
if (tenth_second_counter == 10) {
dcf_counter++;
if (dcf_counter == 60) {
dcf_counter = 0;
dcf_calculate(dcf_data);
}
tenth_second_counter = 0;
}
}
}
return 0;
}
static void portb_init() {
DDRB = 0b00000010;
PORTB= 0b00000010;
}
//clear size Bytes in Memory
static void bits_clear(uint8_t* bits, uint8_t size) {
uint8_t i;
for (i = 0; i < size; i++)
bits = 0x00;
}
//set Bit bit in Memory
static void bit_set(uint8_t* bits, uint8_t bit) {
bits[bit >> 3] |= ((1 << (bit & 0x07)));
}
//write length bits , starting at startpos to memory
uint8_t bits_data_write(uint8_t* bits, uint8_t data, uint8_t startpos,
uint8_t length) {
uint8_t i;
uint8_t bitcount = 0;
for (i = 0; i < length; i++) {
if (data & 0b00000001) {
bit_set(bits, startpos + i);
//count 1-Bits for later Parity-Generation
bitcount++;
}
data >>= 1;
}
return bitcount;
}
static void dcf_calculate(uint8_t* dcf_data) {
uint8_t bitcount;
static uint8_t minute = 00;
static uint8_t hour = 8;
static uint8_t day = 11;
static uint8_t weekday = 6;
static uint8_t month = 8;
static uint8_t year = 12;
//initialize Memory
bits_clear(dcf_data, DCF_DATA_SIZE);
//Write Startbit
bit_set(dcf_data, DCF_DATA_STARTBIT);
//Set MET / MESZ
bit_set(dcf_data,DCF_DATA_MEZ_1);
//Write Date/Time Data with Parity to Memory
bitcount = bits_data_write(dcf_data, INT_TO_BCD(minute), DCF_DATA_MINUTE,
DCF_DATA_MINUTE_LENGTH);
if ((bitcount & 0b00000001))
bit_set(dcf_data, DCF_DATA_MINUTE_PARITY);
bitcount = bits_data_write(dcf_data, INT_TO_BCD(hour), DCF_DATA_HOUR,
DCF_DATA_HOUR_LENGTH);
if ((bitcount & 0b00000001))
bit_set(dcf_data, DCF_DATA_HOUR_PARITY);
bitcount = bits_data_write(dcf_data, INT_TO_BCD(day), DCF_DATA_DAY,
DCF_DATA_DAY_LENGTH);
bitcount += bits_data_write(dcf_data, INT_TO_BCD(weekday), DCF_DATA_WEEKDAY,
DCF_DATA_WEEKDAY_LENGTH);
bitcount += bits_data_write(dcf_data, INT_TO_BCD(month), DCF_DATA_MONTH,
DCF_DATA_MONTH_LENGTH);
bitcount += bits_data_write(dcf_data, INT_TO_BCD(year), DCF_DATA_YEAR,
DCF_DATA_YEAR_LENGTH);
if ((bitcount & 0b00000001))
bit_set(dcf_data, DCF_DATA_DATE_PARITY);
//Count clock
minute++;
if (minute >= 60) {
minute = 0;
hour++;
if (hour >= 24) {
hour = 0;
weekday++;
if (weekday >= 8)
weekday = 1;
day++;
if (day >= month_length(month, year)) {
day = 1;
month++;
if (month >= 13) {
month = 1;
year++;
if (year >= 100)
year = 0;
}
}
}
}
}
ISR (TIMER0_COMPA_vect) {
static int irq_counter = 0;
irq_counter++;
//set flag every tenth second
if (irq_counter == 25) {
irq_counter = 0;
flags |= (1 << FLAG_TENTH_SECOND);
}
}
static void timer0_init() {
OCR0A = 249;
TCCR0A = (1 << WGM01);
TCCR0B = (1 << CS02);
//enable Overflow Interrupt
TIMSK0 |= (1 << OCIE0A);
}
static void timer1_init() {
OCR1A = 103;
OCR1B = 0;
OCR1C = 204;
//Timer1 /2
TCCR1 = (1<<CTC1)|(1 << CS10) | (1 << PWM1A) | (1 << COM1A1);
* TIMSK1 |=(1<<OCIE1B);*
}
//returns lenth of a month
static uint8_t month_length(uint8_t month, uint8_t year) {
if (month == 2)
return (year % 4 == 0) ? 29 : 28;
if (month == 4)
return 30;
if (month == 6)
return 30;
if (month == 9)
return 30;
if (month == 11)
return 30;
return 31;
}
ISR (TIMER1_COMPB_vect) {
static uint8_t irq_counter;
if (irq_counter&0b00000001) OCR1C=206; else OCR1C=205;
irq_counter++;
}

Those errors usually indicate that the code was written for a different microprocessor model from what you’re compiling for. Please post a link to where you got the code from. Use the chain link icon on the toolbar to make it clickable.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Understood it was for Attiny85 this is for arduino (it seems mega 1280)

I have a mega 2560 and compiled file dcf77-micro.ino.md (arduino-1.6.13)
with corrections:
#include <TimerFour.h>
OCR4D->OCR4B
COM4D1->COM4B1
TCCR4D->TCR4B
without it compiled with errors like variant with timer_2.
Checked oscilloscope all outputs anywhere no the output signal and no DCF 77500 Hz.
Help to understand what’s going on.

dcf77-micro.ino (41.5 KB)

The timers are not interchangeable.

You will have to first understand how the original code uses the original timer, then modify it appropriately to use a different timer. Be sure to check the timer prescaler settings so that the operational frequencies and interrupt frequencies are the same.