78 posts / 0 new

## Pages

Author
Message

Hello everybody. Tell me how to generate a signal on two outputs. I only get on PB1, although PB0 should have an inverted signal, but it does not. Fuse settings is 4MHz-64ms from internal RC generator.

DDRB=0; DDRB= (1<<PB0)|(1<<PB1);
PORTB=0;

TCCR1=0; TCNT1=0;
OCR1C=180;                                        // PWM FRQ=140Hz

OCR1A=50;
TCCR1=(1<<PWM1A)|(1<<COM1A1)|(0<<COM1A0);
TCCR1 |= (1<<CS13)|(1<<CS11)|(1<<CS10);

This topic has a solution.
Last Edited: Sat. Oct 21, 2017 - 02:21 PM

OCR1C=180;                                        // PWM FRQ=140Hz

TCCR1 |= (1<<CS13)|(1<<CS11)|(1<<CS10);

Huh?  With a clock speed of 4 MHz, a period of 181 ticks, and a timer prescaler of 1024, the frequency would be 4000000 / (181 * 1024) = 21.6 Hz, not 140 Hz.  140 Hz implies a clock speed of 24.9 MHz.  Something isn't right here...

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

tvitklg wrote:
although PB0 should have an inverted signal, but it does not

`TCCR1= ... (1<<COM1A1)|(0<<COM1A0);`

The wrong way round. COM bits must be 01, not 10.

Stefan Ernst

sternst wrote:

The wrong way round. COM bits must be 01, not 10.

if so there

`TCCR1= ... (0<<COM1A1)|(1<<COM1A0);`

is no signal at all (no PB0, no PB1)

if there

`TCCR1= ... (1<<COM1A1)|(1<<COM1A0);`

Only inverted signal in PB1

Last Edited: Thu. Oct 19, 2017 - 10:31 AM

joeymorin wrote:

Huh?  With a clock speed of 4 MHz, a period of 181 ticks, and a timer prescaler of 1024, the frequency would be 4000000 / (181 * 1024) = 21.6 Hz, not 140 Hz.  140 Hz implies a clock speed of 24.9 MHz.  Something isn't right here...

The oscilloscope shows exactly 140Hz

As far as I understand the instruction in the table, I chose the divisor ck/64

tvitklg wrote:

As far as I understand the instruction in the table, I chose the divisor ck/64

'This forum helps those who help themselves.'

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

tvitklg wrote:

Hello everybody. Tell me how to generate a signal on two outputs. I only get on PB1, although PB0 should have an inverted signal, but it does not. Fuse settings is 4MHz-64ms from internal RC generator.

TCCR1=(1<<PWM1A)|(1<<COM1A1)|(0<<COM1A0);

'This forum helps those who help themselves.'

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

As far as I understand the instruction in the table, I chose the divisor ck/64

Not according to the datasheet (as Brian has shown).  Also, /64 wouldn't result in 140 Hz.  At 4 MHz, I'd expect 4000000 / (181 * 64) = 345.3 Hz.  140 Hz would imply a 1.6 MHz clock.

I think it's time you showed a small, >>complete<< program which demonstrates the problem.  Maybe also show the arithmetic you used to arrive at 140 Hz.

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

Last Edited: Thu. Oct 19, 2017 - 11:36 AM

joeymorin wrote:

Not according to the datasheet (as Brian has shown).  Also, /64 wouldn't result in 140 Hz.  At 4 MHz, I'd expect 4000000 / (181 * 64) = 345.3 Hz.  140 Hz would imply a 1.6 MHz clock.

I think it's time you showed a small, >>complete<< program which demonstrates the problem.  Maybe also show the arithmetic you used to arrive at 140 Hz.

I understand it myself. I did not focus on arithmetic. The frequency for me is not the most important thing does not matter. For a long time I was not engaged in microcontrollers there can be errors. The main thing is to get a Singal on PB0.
In the fuse settings, there are no 25MHz only 8 and 4 (CKDIV8=off). Only PLL can be enabled. Because of what such a high frequency with my divisors.

To simplify the understanding, I used the description in Russian for ATTINA15L

I generate this example from CodeVisionAVR (CodeWizardAVR) But it does not work...

void main(void)
{
// Input/Output Ports initialization
// Port B initialization
// Function: Bit5=In Bit4=In Bit3=In Bit2=In Bit1=Out Bit0=Out
DDRB=(0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (1<<DDB1) | (1<<DDB0);
// State: Bit5=T Bit4=T Bit3=T Bit2=T Bit1=0 Bit0=0
PORTB=(0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=(0<<COM0A1) | (0<<COM0A0) | (0<<COM0B1) | (0<<COM0B0) | (0<<WGM01) | (0<<WGM00);
TCCR0B=(0<<WGM02) | (0<<CS02) | (0<<CS01) | (0<<CS00);
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 31.250 kHz
// Mode: PWMA top=OCR1C
// OC1A output: OC1A=PWM, /OC1A=/PWM
// OC1B output: Disconnected
// Timer Period: 4.992 ms
// Output Pulse(s):
// OC1A Period: 4.992 ms Width: 2.5121 ms
// Timer1 Overflow Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
PLLCSR=(0<<PCKE) | (0<<PLLE) | (0<<PLOCK);

TCCR1=(0<<CTC1) | (1<<PWM1A) | (0<<COM1A1) | (1<<COM1A0) | (1<<CS13) | (0<<CS12) | (0<<CS11) | (0<<CS10);
GTCCR=(0<<TSM) | (0<<PWM1B) | (0<<COM1B1) | (0<<COM1B0) | (0<<PSR1) | (0<<PSR0);
TCNT1=0x00;
OCR1A=0x4E;
OCR1B=0x00;
OCR1C=0x9B;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=(0<<OCIE1A) | (0<<OCIE1B) | (0<<OCIE0A) | (0<<OCIE0B) | (0<<TOIE1) | (0<<TOIE0);

// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=(0<<INT0) | (0<<PCIE);
MCUCR=(0<<ISC01) | (0<<ISC00);

// USI initialization
// Mode: Disabled
// Clock source: Register & Counter=no clk.
// USI Counter Overflow Interrupt: Off
USICR=(0<<USISIE) | (0<<USIOIE) | (0<<USIWM1) | (0<<USIWM0) | (0<<USICS1) | (0<<USICS0) | (0<<USICLK) | (0<<USITC);

// Analog Comparator initialization
// Analog Comparator: Off
// The Analog Comparator's positive input is
// connected to the AIN0 pin
// The Analog Comparator's negative input is
// connected to the AIN1 pin
ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIS1) | (0<<ACIS0);
// Digital input buffer on AIN0: On
// Digital input buffer on AIN1: On
DIDR0=(0<<AIN0D) | (0<<AIN1D);

while (1)
{

}
}

Last Edited: Thu. Oct 19, 2017 - 05:36 PM

It helps if you embed the picture - so that we can see it - rather than attach it:

Instructions here: http://www.avrfreaks.net/comment...

EDIT

Added the Atmel original side-by-side for easy comparison.

Last Edited: Thu. Oct 19, 2017 - 01:12 PM

The datasheet is:

tvitklg wrote:
I used the description in Russian for ATTINA15L

These are NOT the same.

David (aka frog_jr)

I generate this example from CodeVisionAVR (CodeWizardAVR) But it does not work

Explain 'does not work'.  What >>does<< it do?

The code wizzard has chosen a period of 156 and a prescalers of 128. At 8MHz you should get about 400 Hz.

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

joeymorin wrote:
At 8MHz you should get about 400 Hz.

tvitklg wrote:
// Timer Period: 4.992 ms

5ms would be 200Hz, right? Lessee if we can divine a bit more...

tvitklg wrote:
// Clock value: 31.250 kHz

...and CS bits

(1<<CS13) | (0<<CS12) | (0<<CS11) | (0<<CS10);

...which is /128 and implies that OP told the CV project that the AVR's clock speed is 4MHz.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Nothing works. There are no signals anywhere.

## Attachment(s):

Last Edited: Thu. Oct 19, 2017 - 07:23 PM

...which is /128 and implies that OP told the CV project that the AVR's clock speed is 4MHz.

Yes that's what he says he wants, but where is that being configured?  The CV wizard code he posted doesn't tickle CLKPR.  Does CV have a runtime which handles this before main() (akin to AVR GCC's .initN sections)?  Fuses will set either 1 MHz or 8 MHz from the internal RC, or 2 MHz or 16 MHz from the PLL.

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

OP posted while I was typing.  Attached main.cpp does not match his screenshot.  Attachment boils down to this:

```#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>

int main(void) {

DDRB=(0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (1<<DDB1) | (1<<DDB0);

TCCR1=(0<<CTC1) | (1<<PWM1A) | (0<<COM1A1) | (1<<COM1A0) | (1<<CS13) | (0<<CS12) | (0<<CS11) | (0<<CS10);
OCR1A=0x4E;
OCR1C=0x9B;

ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIS1) | (0<<ACIS0);

while (1) {
}

}
```

No CLKPR, yet screenshot shows configuring for /1 i.e. 8 MHz from RC or 16 MHz from PLL.

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

Last Edited: Thu. Oct 19, 2017 - 07:34 PM

joeymorin wrote:
but where is that being configured?

As with F_CPU in GCC, you "tell" CV in the Project what speed your AVR is running at.

And also as with F_CPU, that doesn't make the chip run at a particular speed.

joeymorin wrote:
Fuses will set either 1 MHz or 8 MHz from the internal RC, or 2 MHz or 16 MHz from the PLL.

OP posted a screenshot of a "Dragon" tool that I'm not familiar with, that shows/implies a 4MHz selection. Confusing, as the datasheet says the nominal internal oscillator values are 8MHz and 6.4MHz.  (along with 128kHz and use of CKDIV8, right?)  Could the shown tool be using "_4MHZ" as a shorthand/typo for the 6.4MHz selection?

==========================

Anyway, we can put aside that question for the moment, as

tvitklg wrote:
Nothing works. There are no signals anywhere.

Well, joey, you >>asked<< for a complete program, and I was hoping for that also.  What do we find?

-- OP used CV Wizard to generate such.

-- But the posted attachment is a C++ program which CV doesn't do...

-- ...and indeed examination shows it to be GCC:

#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
int main(void)

...

Main loop is empty.  So we are back to the basics -- did the program compile?  did the right .HEX get to the chip?  does the AVR come out of reset?

Apparently OP has a 'scope, so pins other than PB0/PB1 could be made outputs and then toggled in the main loop.  E.g.

DDRB=(0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (1<<DDB2) | (1<<DDB1) | (1<<DDB0);

...

while (1)

{

PINB = 1<<PB2;

}

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

theusch wrote:

-- OP used CV Wizard to generate such.

-- But the posted attachment is a C++ program which CV doesn't do...

-- ...and indeed examination shows it to be GCC:

#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
int main(void)

...

Main loop is empty.  So we are back to the basics -- did the program compile?  did the right .HEX get to the chip?  does the AVR come out of reset?

Apparently OP has a 'scope, so pins other than PB0/PB1 could be made outputs and then toggled in the main loop.  E.g.

Naturally, I replaced at the beginning of the file tiny25.h from CVAVR and then everything was compiled.

It does not matter, since it's just an example of timer settings that resulted in the generated CVAVR file

Also, the main cycle is empty, why should it be not empty? After all, the PWM after the configuration should work by itself. So it works for me on PB1

Last Edited: Thu. Oct 19, 2017 - 08:13 PM

tvitklg wrote:
So it works for me on PB1

???  It works on PB1?  But you said

tvitklg wrote:
Nothing works. There are no signals anywhere.

Which is it?

Is the only problem the lack of the inverted signal /OC1A on PB0?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

20 posts and getting no where!

Seems to be a language barrier here that could be solved by the OP showing us his complete code, please use the "<>" code editor to post it.

Jim

Pretty sure he did.  Attached to #14.  Boils down to code in #16.

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

I said that CVAVR is just an example and it does not matter because nothing works. And it works on PB1 in the initial setup in the very first post.

Yes the only problem is the absence of an inverted signal on PB0...

tvitklg wrote:
I said that CVAVR is just an example and it does not matter because nothing works. And it works on PB1 in the initial setup in the very first post.

So, then, please try the "sanity checks" I mentioned:

So we are back to the basics -- did the program compile?  did the right .HEX get to the chip?  does the AVR come out of reset?

Apparently OP has a 'scope, so pins other than PB0/PB1 could be made outputs and then toggled in the main loop.  E.g.

DDRB=(0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (1<<DDB2) | (1<<DDB1) | (1<<DDB0);

...

while (1)

{

PINB = 1<<PB2;

}

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

tvitklg wrote:
Yes the only problem is the absence of an inverted signal on PB0...

In #7, Brian pointed out the problem in your original code in #1 -- the COM bit settings did not call for the inverted signal.  And indeed you see the correct COM settings in the CV code.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

theusch wrote:

tvitklg wrote:
Yes the only problem is the absence of an inverted signal on PB0...

In #7, Brian pointed out the problem in your original code in #1 -- the COM bit settings did not call for the inverted signal.  And indeed you see the correct COM settings in the CV code.

The answer was earlier in post №4

```#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
int main(void)
{    DDRB=(0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (1<<DDB2) | (1<<DDB1) | (1<<DDB0);

while (1)

{

PINB = 1<<PB2;

}

}```

Your code is work meander=280kHz on PB2

Last Edited: Thu. Oct 19, 2017 - 09:28 PM

joeymorin wrote:

## Attachment(s):

So we have the .LSS etc.  Does this match the main.cpp you posted earlier?

Examining the .LSS is "interesting" without the source lines.  But Tiny25 I/O map is pretty simple, so let's try to find the timer setup...

I'm happy with the TCCR1 setup value of 0x58 to register 0x30...

```3e:	88 e5       	ldi	r24, 0x58	; 88
40:	80 bf       	out	0x30, r24	; 48
```

and we see 78 loaded to OCR1A and 155 loaded to OCR1C

``` 46:	8e e4       	ldi	r24, 0x4E	; 78
48:	8e bd       	out	0x2e, r24	; 46
4a:	1b bc       	out	0x2b, r1	; 43
4c:	8b e9       	ldi	r24, 0x9B	; 155
4e:	8d bd       	out	0x2d, r24	; 45
```

Looks good to me.  And you reported that the toggle program works, so the AVR is not in reset, and the right .HEX is being loaded.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Oct 19, 2017 - 09:28 PM

theusch wrote:

So we have the .LSS etc.  Does this match the main.cpp you posted earlier?

This is the one that attached. I downloaded it from here from the forum because I deleted it from my after attached. Paste it into AtmelStudio 6.2 >> compiled it and now attached output compiled binary file

Last Edited: Thu. Oct 19, 2017 - 09:39 PM
```
main_4.hex:     file format ihex

Disassembly of section .sec1:

00000000 <.sec1>:
0:	0e c0       	rjmp	.+28     	;  0x1e
2:	13 c0       	rjmp	.+38     	;  0x2a
4:	12 c0       	rjmp	.+36     	;  0x2a
6:	11 c0       	rjmp	.+34     	;  0x2a
8:	10 c0       	rjmp	.+32     	;  0x2a
a:	0f c0       	rjmp	.+30     	;  0x2a
c:	0e c0       	rjmp	.+28     	;  0x2a
e:	0d c0       	rjmp	.+26     	;  0x2a
10:	0c c0       	rjmp	.+24     	;  0x2a
12:	0b c0       	rjmp	.+22     	;  0x2a
14:	0a c0       	rjmp	.+20     	;  0x2a
16:	09 c0       	rjmp	.+18     	;  0x2a
18:	08 c0       	rjmp	.+16     	;  0x2a
1a:	07 c0       	rjmp	.+14     	;  0x2a
1c:	06 c0       	rjmp	.+12     	;  0x2a

1e:	11 24       	eor	r1, r1
20:	1f be       	out	0x3f, r1	; 63
22:	cf ed       	ldi	r28, 0xDF	; 223
24:	cd bf       	out	0x3d, r28	; 61

26:	02 d0       	rcall	.+4      	;  0x2c
28:	1d c0       	rjmp	.+58     	;  0x64

2a:	ea cf       	rjmp	.-44     	;  0x0

; DDRB = (1<<PB1) | (1<<PB0);
2c:	83 e0       	ldi	r24, 0x03	; 3
2e:	87 bb       	out	0x17, r24	; 23

30:	18 ba       	out	0x18, r1	; 24
32:	1a bc       	out	0x2a, r1	; 42
34:	13 be       	out	0x33, r1	; 51
36:	12 be       	out	0x32, r1	; 50
38:	19 bc       	out	0x29, r1	; 41
3a:	18 bc       	out	0x28, r1	; 40
3c:	17 bc       	out	0x27, r1	; 39

; TCCR1 = (1<<PWM1A) | (1<<COM1A0) | (1<<CS13);
3e:	88 e5       	ldi	r24, 0x58	; 88
40:	80 bf       	out	0x30, r24	; 48

42:	1c bc       	out	0x2c, r1	; 44
44:	1f bc       	out	0x2f, r1	; 47

; OCR1A = 78;
46:	8e e4       	ldi	r24, 0x4E	; 78
48:	8e bd       	out	0x2e, r24	; 46
4a:	1b bc       	out	0x2b, r1	; 43

; OCR1C = 155;
4c:	8b e9       	ldi	r24, 0x9B	; 155
4e:	8d bd       	out	0x2d, r24	; 45

50:	19 be       	out	0x39, r1	; 57
52:	1b be       	out	0x3b, r1	; 59
54:	15 be       	out	0x35, r1	; 53
56:	1d b8       	out	0x0d, r1	; 13

; ACSR = (1<<ACD);
58:	80 e8       	ldi	r24, 0x80	; 128
5a:	88 b9       	out	0x08, r24	; 8

5c:	13 b8       	out	0x03, r1	; 3
5e:	14 ba       	out	0x14, r1	; 20
60:	16 b8       	out	0x06, r1	; 6

62:	ff cf       	rjmp	.-2      	;  0x62

64:	f8 94       	cli
66:	ff cf       	rjmp	.-2      	;  0x66```

Yup.  Should work.

The .hex file.

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

Last Edited: Thu. Oct 19, 2017 - 09:45 PM

joeymorin wrote:

The .hex file.

```#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
int main(void)
{    DDRB=(0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (1<<DDB2) | (1<<DDB1) | (1<<DDB0);

while (1)

{

PINB = 1<<PB2;

}

}```

this ?

## Attachment(s):

Last Edited: Thu. Oct 19, 2017 - 09:50 PM

I mean download it to the attiny25 i.e. program it to the t25's flash.

Are you sure you are succeeding in programming the t25 with the correct hex file?  How have you confirmed this?

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

Last Edited: Thu. Oct 19, 2017 - 09:51 PM

joeymorin wrote:

I mean download it to the attiny25 i.e. program it to the t25's flash.

Are you sure you are succeeding in programming the t25 with the correct hex file?  How have you confirmed this?

Last Edited: Thu. Oct 19, 2017 - 10:00 PM

How have you confirmed this?

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

joeymorin wrote:

How have you confirmed this?

Come to Russia, I'll show you everything by myself, you can click on the download button in the Atmel Studio 6.2...

It is possible to take such a microcircuit and write down the attached examples at home. I think microcosm is not that hard to find. I have them just in their pockets and on the table lying about 5 pieces.

p.s.

Wrote in support. Most likely they will answer exactly what the problems may be. Because the situation is the same as with my question on the unique identifier at32uc3l064 (uC ID)

Last Edited: Fri. Oct 20, 2017 - 11:25 AM

joeymorin wrote:
How have you confirmed this?

OP tried my suggested sanity-check code as shown in #34, and reported activity on PB2.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

OP tried my suggested sanity-check code as shown in #34, and reported activity on PB2.

He reported in #27 that he saw 280 kHz on PB2.  The .hex file he posted in #34 of the attempt shows that PB2 should be toggling every 3 cpu cycles, for a period of 6 cpu cycles.  If he's seeing 280 kHz, this implies a cpu speed of 840 kHz.  That's pretty far off tolerance for a 1 MHz oscillator.

Are you sure you are succeeding in programming the t25 with the correct hex file?  How have you confirmed this?

One possibility the OP is not successfully uploading the code he believes he is.  One way to confirm/refute this is to use avrdude to read the t25's flash and create a .hex file.  Posting the .hex file generated by the toolchain from source only tells us the toolchain is working.

Another possibility is that this isn't a genuine t25.

Yet another possibility is that the t25 is fused to run in t15 compatibility mode.  In this mode TIMER1 functions differently and the compare match unit has no complimentary outputs, and the RC oscillator runs at 6.4 MHz, and the prescaler is set to /4 for a clock speed of 1.6 MHz.  If the OP has set the prescaler to /8 using code he has yet to show us, this might explain an apparent cpu speed of 840 kHz, except that CLKPR is disabled in t15 compatibility mode.  We have also seen images of t15 datasheets in Russian.

So, OP, what are your fuses set to?

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

Last Edited: Fri. Oct 20, 2017 - 02:40 PM

joeymorin wrote:
Yet another possibility is that the t25 is fused to run in t15 compatibility mode.

That seems like a best-guess at this time.  OP'd use of my sanity code approach convinces me that the .HEX is making it to the chip.  I've only use the complementary outputs a couple times over the years, and do not recall any problems.

joeymorin wrote:
So, OP, what are your fuses set to?
We >>almost<< had the answer in #14.  If OP posts the same screenshot without the pull-down active, then perhaps we can solve the mysteries of the clock source and timer operation.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

joeymorin wrote:

Are you sure you are succeeding in programming the t25 with the correct hex file?  How have you confirmed this?

I realized this that you do not believe me that I upload the examples to the chip. Therefore, I wrote and come and press the button.

Last Edited: Fri. Oct 20, 2017 - 03:40 PM

From tiny25 data sheet:

6.1.6 Internal PLL in ATtiny15 Compatibility Mode
Since ATtiny25/45/85 is a migration device for ATtiny15 users there is an ATtiny15 compatibility mode for backward
compatibility. The ATtiny15 compatibility mode is selected by programming the CKSEL fuses to ‘0011’.
In the ATtiny15 compatibility mode the frequency of the internal RC oscillator is calibrated down to 6.4 MHz and the
multiplication factor of the PLL is set to 4x. See Figure 6-3. With these adjustments the clocking system is
ATtiny15-compatible and the resulting fast peripheral clock has a frequency of 25.6 MHz (same as in ATtiny15).

If I am not mistaken, that is how the fuses are set in post #42 and /OC1A is not available in Tiny15 mode (as per post #40).

David (aka frog_jr)

OK, so I've finished what I wanted to do today and have 20 minutes to play.

I don't have a tiny25 but I do have a tiny85. I made this waveform....

...with this code...

```#include <io.h>

void main(void)
{

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=(1<<CLKPCE);
CLKPR=(0<<CLKPCE) | (0<<CLKPS3) | (0<<CLKPS2) | (0<<CLKPS1) | (0<<CLKPS0);
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Function: Bit5=In Bit4=In Bit3=In Bit2=In Bit1=Out Bit0=In
DDRB=(0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (1<<DDB1) | (1<<DDB0);
// State: Bit5=T Bit4=T Bit3=T Bit2=T Bit1=0 Bit0=T
PORTB=(0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 250.000 kHz
// Mode: PWMA top=OCR1C
// OC1A output: OC1A=PWM, /OC1A=/PWM
// OC1B output: Disconnected
// Timer Period: 1 ms
// Output Pulse(s):
// OC1A Period: 1 ms Width: 0 us
// Timer1 Overflow Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
PLLCSR=(0<<PCKE) | (0<<PLLE) | (0<<PLOCK);

TCCR1=(0<<CTC1) | (1<<PWM1A) | (0<<COM1A1) | (1<<COM1A0) | (0<<CS13) | (1<<CS12) | (1<<CS11) | (0<<CS10);
GTCCR=(0<<TSM) | (1<<PWM1B) | (0<<COM1B1) | (0<<COM1B0) | (0<<PSR1) | (0<<PSR0);
TCNT1=0x00;
OCR1A=0x32;
OCR1B=0x00;
OCR1C=0xF9;;

while (1)
{

}
}```

'This forum helps those who help themselves.'

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

tvitklg wrote:
I realized this that you do not believe me that I upload the examples to the chip.
Wrong picture - in that programming dialog it's "Memories" that is of more interest than "Fuses". The point being that the .hex file listed for programming to the AVR "flash" may be some old thing and not the file you are building. (everyone's made this mistake at some time!).

OP'd use of my sanity code approach convinces me that the .HEX is making it to the chip.

It convinces me that he succeeded in getting your sanity check to the chip.  It doesn't convince me that he's getting his own test code to the chip.  Several threads kicking around here of users unwittingly uploading previous attempt's .hex files.

realized this that you do not believe me that I upload the examples to the chip.

Belief is irrelevant.  Proof is not.  I was asking for >>independent<< confirmation that the .hex file you though was being burned to the chip >>actually<< was.  Hence my suggestion of reading flash with avrdude.  Have you done this?

I agree it is unlikely, but thus far your problem has not been solved, or even identified.  Ruling out the obvious is the first step in any troubleshooting adventure.

Again, independent confirmation of >>actual<< fuse values is more valuable than a screenshot of a fuse >>selection<< in AS.

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

Last Edited: Fri. Oct 20, 2017 - 04:01 PM

I think joey made a great guess.  Unlike some other AVR models (M103C fuse; M161C fuse), this one apparently does the Tiny15 thing "indirectly".

We see the fuses are 0xff, 0xdf, 0xc3.  We will leave the topic of not using the BOD for another time.

Extended is don't care.  High of 0xdf is default:

Now we get to Low of 0xc3:

No CKDIV8.  Fastest start-up time?  Can also be left for another time.  But CKSEL3:0 of 3...

That pretty much explains the clock speed and probably the other issue...

OP, try 8MHz internal oscillator...

I'll leave to OP to search the datasheet for "attiny15" for all the associated caveats.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

What a witch hunt!  Good digging, everyone... [I'll wager a virtual cold one that OP's original puzzle is now explained.]

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

I have these fuses...

'This forum helps those who help themselves.'

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

No CKDIV8

CKDIV8 ignored in t15 mode.

That pretty much explains the clock speed and probably the other issue...

Almost.  A clock speed of 840 kHz is 1/2 of the expected 1.6 MHz, tolerance accounted for.  However CLKPR is ignored in t15 mode, so how did the OP get 280 kHz for a 6-clk period in #27?  Whoops.  Can't do arithmetic without coffee, it seems.  280 kHz is correct for a 6-clk period and 1.6 MHz.  Problem solved, I expect.

OP, try 8MHz internal oscillator...

I'll leave to OP to search the datasheet for "attiny15" for all the associated caveats.

My question is why does the OP want t15 mode in the first place?

Even more curious, why does AS use "INTRCOSC_4MHZ_6CK_15CK_64MS" for a CKSEL mode which results in a fixed 1.6 MHz system clock?  Since the OP seems to want 4 MHz, it would explain his choice.  AS strikes again?

 "Experience is what enables you to recognise a mistake the second time you make it." "Good judgement comes from experience.  Experience comes from bad judgement." "When you hear hoofbeats, think horses, not unicorns." "Fast.  Cheap.  Good.  Pick two." "Read a lot.  Write a lot." "We see a lot of arses on handlebars around here." - [J Ekdahl]

Last Edited: Fri. Oct 20, 2017 - 04:13 PM