Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Attiny 417 output failure
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
nobner

Bascom Member



Joined: 29 Apr 2015
Posts: 21

germany.gif
PostPosted: Sun Nov 28, 2021 10:14 pm    Post subject: Attiny 417 output failure Reply with quote

Hello to all,
i'm using a Attiny 417 for driving RGBW-LED.
4x AD-Inputs, 8 bit, for checking dimming range.
4x Digital Outputs with variable Puls-Length for driving LED power supply.
3 Channels are working fine, the fourth channel (PortB.1) is producing double pulses (see attached pictures)
Program is the same for all 4 Channels.
I think i had a similar problem years ago and someone told me, that there is an alternative to set the output-ports (i'm using PortB.1 = 1)
Unfortunatley i can't find the post anymore.
Any idea's what the problem could be?
Are 4 AD-Inputs too much for stack ,or....?
Has there anything to be disabled for using PB.1 as digital output?

Thank's !!

(BASCOM-AVR version : 2.0.8.4 )
Code:

'RGBW Elektronik 3W
'ATTINY417
'Norbert Nestler
'V03 28.11.2021
'Fuses:
'Programmierung UPDI (PIN10)

$Regfile="atxtiny417.dat"
$Crystal=16000000
$hwstack=40
$swstack=16
$framesize=32

config Sysclock = 16_20mhz , Prescale = 1 , Clockout = Disabled '16/20MHz in Fuses auf 16Mhz setzen

config PORTA.1 = OUTPUT 'frei
config PORTA.2 = INPUT  'Eingang NTC
config PORTA.3 = OUTPUT 'Ausgangssignal weiss
WHITE_OUT alias PORTA.3
config PORTA.4 = INPUT  'Eingangssignal RED
config PORTA.5 = INPUT  'Eingangssignal grün
config PORTA.6 = OUTPUT 'Start LED Treiber
config PORTA.7 = INPUT  'Eingangssignal weiss

config PORTB.0 = OUTPUT 'Ausgangssignal grün
GREEN_OUT alias PORTB.0
config PORTB.1 = OUTPUT 'Ausgangssignal RED
RED_OUT alias PORTB.1
config PORTB.2 = OUTPUT 'Ausgangssignal blau
BLUE_OUT alias PORTB.2
config PORTB.3 = OUTPUT 'Test-LED
config PORTB.4 = INPUT  'Eingangssignal blau
config PORTB.5 = OUTPUT
config PORTB.6 = OUTPUT
config PORTB.7 = OUTPUT

config PORTC.0 = OUTPUT
config PORTC.1 = OUTPUT
config PORTC.2 = OUTPUT 'Test-Ausgang
config PORTC.3 = OUTPUT
config PORTC.4 = OUTPUT
config PORTC.5 = OUTPUT

Config Adc0 = Single , Resolution = 8bit , Adc = Enabled , Reference = VDD , Prescaler = 8 , Sample_len = 1 , Sample_cap = Above_1v , Init_delay = 32

disable interrupts

DIM RED_IN as byte
DIM GREEN_IN as byte
DIM BLUE_IN as byte
DIM WHITE_IN as byte

DIM RED_PAU as byte
DIM GREEN_PAU as byte
DIM BLUE_PAU as byte
DIM WHITE_PAU as byte

DIM OFF_ZEIT as byte

DIM i as byte
for i = 0 to 4  'Test LED blinkt 5x

PORTB.3 = 1
waitms 200
PORTB.3 = 0
waitms 200

next i

OFF_ZEIT = 2

PORTA.6 = 1  'Schaltregler einschalten

DO
'Einlesen
'---------------------------------------------------------------------------
'Kanal GRÜN
GREEN_IN = GETADC(5)
IF GREEN_IN > 240 THEN GREEN_IN = 255
GREEN_PAU = GREEN_IN
GREEN_IN = 255 - GREEN_IN
'---------------------------------------------------------------------------
'Kanal ROT
RED_IN = GETADC(4)
IF RED_IN > 240 THEN RED_IN = 255
RED_PAU = RED_IN
RED_IN = 255 - RED_IN
'---------------------------------------------------------------------------
'Kanal BLAU
BLUE_IN = GETADC(9)
IF BLUE_IN > 240 THEN BLUE_IN = 255
BLUE_PAU = BLUE_IN
BLUE_IN = 255 - BLUE_IN
'---------------------------------------------------------------------------
'Kanal WEISS
WHITE_IN = GETADC(7)
IF WHITE_IN > 240 THEN WHITE_IN = 255
WHITE_PAU = WHITE_IN
WHITE_IN = 255 - WHITE_IN
'---------------------------------------------------------------------------

'Ausgeben
'---------------------------------------------------------------------------
'Kanal GRÜN
IF GREEN_IN > 10 THEN
                 GREEN_OUT = 1
                 waitus GREEN_IN
                 GREEN_OUT = 0
                 waitus GREEN_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
'Kanal RED
IF RED_IN > 10 THEN
               RED_OUT = 1
               waitus RED_IN
               RED_OUT = 0
               waitus RED_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
'Kanal BLAU
IF BLUE_IN > 10 THEN
                BLUE_OUT = 1
                waitus BLUE_IN
                BLUE_OUT = 0
                waitus BLUE_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
'Kanal WEISS
IF WHITE_IN > 10 THEN
                 WHITE_OUT = 1
                 waitus WHITE_IN
                 WHITE_OUT = 0
                 waitus WHITE_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------

loop

end
 


Last edited by nobner on Mon Nov 29, 2021 1:21 pm; edited 1 time in total
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Nov 29, 2021 9:38 am    Post subject: Reply with quote

if a pin does not work always start with just toggling the pin.
also, trace/measure with a DVM on your PCB to see if that is the actual pin.

then check the 5.1 section in the PDF. it shows the alternative pin functions.
AIN10, XCK, SDA, WO1

thus when using TCA0 with WO output you could get into problems.

there is builtin support for rgbw :leds config rainbow

to set a pin to output you can best use CONFIG PORTB.1=output
SET PORTB.1 and PORTB.1=1 are equivalent

of course you can use the DDR and PORT register too but this makes code less portable.

_________________
Mark
Back to top
View user's profile Visit poster's website
nobner

Bascom Member



Joined: 29 Apr 2015
Posts: 21

germany.gif
PostPosted: Mon Nov 29, 2021 11:10 am    Post subject: Attiny 417 output failure Reply with quote

Hi Mark,
thank you for the hints.
I did measurement Input / Output. All 4 Channels are showing the same (correct) input signal and 3 channels are doing the correct output.
Only channel 4 (PB1) is giving the failure output.
How can i disable the alternative pin functions for AIN10, XCK, SDA, WO1?
Writing registers on xtiny seem to be different to the standard tiny's?

UPDATE:
one step further to solution:
When i disable the input section of one channel (here the white one) in software, PORTB.1 works fine.
Might this be a stack problem?

Code:

'RGBW Elektronik 3W
'ATTINY417
'Norbert Nestler
'V03 28.11.2021
'Fuses:
'Programmierung UPDI (PIN10)

$Regfile="atxtiny417.dat"
$Crystal=16000000
$hwstack=40
$swstack=16
$framesize=32

config Sysclock = 16_20mhz , Prescale = 1 , Clockout = Disabled '16/20MHz in Fuses auf 16Mhz setzen

config PORTA.1 = OUTPUT 'frei
config PORTA.2 = INPUT  'Eingang NTC
config PORTA.3 = OUTPUT 'Ausgangssignal weiss
WHITE_OUT alias PORTA.3
config PORTA.4 = INPUT  'Eingangssignal rot
config PORTA.5 = INPUT  'Eingangssignal grün
config PORTA.6 = OUTPUT 'Start LED Treiber
config PORTA.7 = INPUT  'Eingangssignal weiss

config PORTB.0 = OUTPUT 'Ausgangssignal grün
GREEN_OUT alias PORTB.0
config PORTB.1 = OUTPUT 'Ausgangssignal rot
RED_OUT alias PORTB.1
config PORTB.2 = OUTPUT 'Ausgangssignal blau
BLUE_OUT alias PORTB.2
config PORTB.3 = OUTPUT 'Test-LED
config PORTB.4 = INPUT  'Eingangssignal blau
config PORTB.5 = OUTPUT
config PORTB.6 = OUTPUT
config PORTB.7 = OUTPUT

config PORTC.0 = OUTPUT
config PORTC.1 = OUTPUT
config PORTC.2 = OUTPUT 'Test-Ausgang
config PORTC.3 = OUTPUT
config PORTC.4 = OUTPUT
config PORTC.5 = OUTPUT

Config Xpin = PortA.4 , Outpull = DISABLED , Sense = INP_DISABLED
Config Xpin = PortA.5 , Outpull = DISABLED , Sense = INP_DISABLED
Config Xpin = PortA.7 , Outpull = DISABLED , Sense = INP_DISABLED
Config Xpin = PortB.4 , Outpull = DISABLED , Sense = INP_DISABLED

Config Xpin = PortA.3 , Outpull = DISABLED
Config Xpin = PortB.0 , Outpull = DISABLED
Config Xpin = PortB.1 , Outpull = DISABLED
Config Xpin = PortB.2 , Outpull = DISABLED


Config Adc0 = Single , Resolution = 8bit , Adc = Enabled , Reference = VDD , Prescaler = 8 , Sample_len = 1 , Sample_cap = Above_1v , Init_delay = 32

disable interrupts

DIM RED_IN as byte
DIM GREEN_IN as byte
DIM BLUE_IN as byte
DIM WHITE_IN as byte

DIM RED_PAU as byte
DIM GREEN_PAU as byte
DIM BLUE_PAU as byte
DIM WHITE_PAU as byte

DIM OFF_ZEIT as byte

DIM i as byte
for i = 0 to 4  'Test LED blinkt 5x

PORTB.3 = 1
waitms 200
PORTB.3 = 0
waitms 200

next i

OFF_ZEIT = 2

PORTA.6 = 1  'Schaltregler einschalten

DO
'Einlesen
'---------------------------------------------------------------------------
'Kanal GRÜN
GREEN_IN = GETADC(5)
IF GREEN_IN > 240 THEN GREEN_IN = 255
GREEN_PAU = GREEN_IN
GREEN_IN = 255 - GREEN_IN
'---------------------------------------------------------------------------
'Kanal ROT
RED_IN = GETADC(4)
IF RED_IN > 240 THEN RED_IN = 255
RED_PAU = RED_IN
RED_IN = 255 - RED_IN
'---------------------------------------------------------------------------
'Kanal BLAU
BLUE_IN = GETADC(9)
IF BLUE_IN > 240 THEN BLUE_IN = 255
BLUE_PAU = BLUE_IN
BLUE_IN = 255 - BLUE_IN
'---------------------------------------------------------------------------
'Kanal WEISS
'WHITE_IN = GETADC(7)
'IF WHITE_IN > 240 THEN WHITE_IN = 255
'WHITE_PAU = WHITE_IN
'WHITE_IN = 255 - WHITE_IN
'---------------------------------------------------------------------------

'Ausgeben
'---------------------------------------------------------------------------
'Kanal GRÜN
IF GREEN_IN > 10 THEN
                 GREEN_OUT = 1
                 waitus GREEN_IN
                 GREEN_OUT = 0
                 waitus GREEN_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
'Kanal RED
IF RED_IN > 10 THEN
               RED_OUT = 1
               waitus RED_IN
               RED_OUT = 0
               waitus RED_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
'Kanal BLAU
IF BLUE_IN > 10 THEN
                BLUE_OUT = 1
                waitus BLUE_IN
                BLUE_OUT = 0
                waitus BLUE_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
'Kanal WEISS
IF WHITE_IN > 10 THEN
                 WHITE_OUT = 1
                 waitus WHITE_IN
                 WHITE_OUT = 0
                 waitus WHITE_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------

loop

end
 
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Nov 29, 2021 1:03 pm    Post subject: Reply with quote

that does not make sense. i would start with a verify and see if the code is programmed.

you hardly use stack. and all the color sections are equivalent.

but pb1 is also AIN10. so when using the A/D. you best put the CONFIG PORTB.1 after the config adc0

i could not find explicit info on a/d input pins digital mode usage.

_________________
Mark
Back to top
View user's profile Visit poster's website
nobner

Bascom Member



Joined: 29 Apr 2015
Posts: 21

germany.gif
PostPosted: Mon Nov 29, 2021 1:30 pm    Post subject: Attiny 417 output failure Reply with quote

Changing config Portb.1 behind config adc doesn't change anything.
Programming work's without problem - three channels working correct, the fourth, PB1 not.
I don't use the AD-input pins in digital mode? What do you mean with this comment?
I wonder why the frequency of the failure output is exactly 4 times higher than the correct one?


Code:

'RGBW Elektronik 3W
'ATTINY417
'Norbert Nestler
'V03 28.11.2021
'Fuses:
'Programmierung UPDI (PIN10)

$Regfile="atxtiny417.dat"
$Crystal=16000000
$hwstack=40
$swstack=16
$framesize=32

config Sysclock = 16_20mhz , Prescale = 1 , Clockout = Disabled '16/20MHz in Fuses auf 16Mhz setzen

Config Adc0 = Single , Resolution = 8bit , Adc = Enabled , Reference = VDD , Prescaler = 8 , Sample_len = 1 , Sample_cap = Above_1v , Init_delay = 32

config PORTA.1 = OUTPUT 'frei
config PORTA.2 = INPUT  'Eingang NTC
config PORTA.3 = OUTPUT 'Ausgangssignal weiss
WHITE_OUT alias PORTA.3
config PORTA.4 = INPUT  'Eingangssignal rot
config PORTA.5 = INPUT  'Eingangssignal grün
config PORTA.6 = OUTPUT 'Start LED Treiber
config PORTA.7 = INPUT  'Eingangssignal weiss

config PORTB.0 = OUTPUT 'Ausgangssignal grün
GREEN_OUT alias PORTB.0
config PORTB.1 = OUTPUT 'Ausgangssignal rot
RED_OUT alias PORTB.1
config PORTB.2 = OUTPUT 'Ausgangssignal blau
BLUE_OUT alias PORTB.2
config PORTB.3 = OUTPUT 'Test-LED
config PORTB.4 = INPUT  'Eingangssignal blau
config PORTB.5 = OUTPUT
config PORTB.6 = OUTPUT
config PORTB.7 = OUTPUT

config PORTC.0 = OUTPUT
config PORTC.1 = OUTPUT
config PORTC.2 = OUTPUT 'Test-Ausgang
config PORTC.3 = OUTPUT
config PORTC.4 = OUTPUT
config PORTC.5 = OUTPUT

Config Xpin = PortA.4 , Outpull = DISABLED , Sense = INP_DISABLED
Config Xpin = PortA.5 , Outpull = DISABLED , Sense = INP_DISABLED
Config Xpin = PortA.7 , Outpull = DISABLED , Sense = INP_DISABLED
Config Xpin = PortB.4 , Outpull = DISABLED , Sense = INP_DISABLED

Config Xpin = PortA.3 , Outpull = DISABLED
Config Xpin = PortB.0 , Outpull = DISABLED
Config Xpin = PortB.1 , Outpull = DISABLED
Config Xpin = PortB.2 , Outpull = DISABLED




disable interrupts

DIM RED_IN as byte
DIM GREEN_IN as byte
DIM BLUE_IN as byte
DIM WHITE_IN as byte

DIM RED_PAU as byte
DIM GREEN_PAU as byte
DIM BLUE_PAU as byte
DIM WHITE_PAU as byte

DIM OFF_ZEIT as byte

DIM i as byte
for i = 0 to 4  'Test LED blinkt 5x

PORTB.3 = 1
waitms 200
PORTB.3 = 0
waitms 200

next i

OFF_ZEIT = 2

PORTA.6 = 1  'Schaltregler einschalten

DO
'Einlesen
'---------------------------------------------------------------------------
'Kanal GRÜN
GREEN_IN = GETADC(5)
IF GREEN_IN > 240 THEN GREEN_IN = 255
GREEN_PAU = GREEN_IN
GREEN_IN = 255 - GREEN_IN
'---------------------------------------------------------------------------
'Kanal ROT
RED_IN = GETADC(4)
IF RED_IN > 240 THEN RED_IN = 255
RED_PAU = RED_IN
RED_IN = 255 - RED_IN
'---------------------------------------------------------------------------
'Kanal BLAU
BLUE_IN = GETADC(9)
IF BLUE_IN > 240 THEN BLUE_IN = 255
BLUE_PAU = BLUE_IN
BLUE_IN = 255 - BLUE_IN
'---------------------------------------------------------------------------
'Kanal WEISS
WHITE_IN = GETADC(7)
IF WHITE_IN > 240 THEN WHITE_IN = 255
WHITE_PAU = WHITE_IN
WHITE_IN = 255 - WHITE_IN
'---------------------------------------------------------------------------

'Ausgeben
'---------------------------------------------------------------------------
'Kanal GRÜN
IF GREEN_IN > 10 THEN
                 GREEN_OUT = 1
                 waitus GREEN_IN
                 GREEN_OUT = 0
                 waitus GREEN_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
'Kanal RED
IF RED_IN > 10 THEN
               RED_OUT = 1
               waitus RED_IN
               RED_OUT = 0
               waitus RED_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
'Kanal BLAU
IF BLUE_IN > 10 THEN
                BLUE_OUT = 1
                waitus BLUE_IN
                BLUE_OUT = 0
                waitus BLUE_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
'Kanal WEISS
IF WHITE_IN > 10 THEN
                 WHITE_OUT = 1
                 waitus WHITE_IN
                 WHITE_OUT = 0
                 waitus WHITE_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------

loop

end
 
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Nov 29, 2021 1:50 pm    Post subject: Reply with quote

Quote:
I don't use the AD-input pins in digital mode? What do you mean with this comment?

you use config ADC which enables the A/D converter.
Like i mentioned (but you do not give feedback about it) read the 5.1 section in the data sheet.
here you can see the pins and the alternative usage.
it should be clear that once you use a pin for one task, you can not use it for another. except when you disable the hardware. and when your hardware is up to the task.
so again pb1. AIN10 for ADC0, XCK for UART0, SDA for TWI0, WO1 for TCA0
and there is the simple digital function like set/reset

when you use a/d converter this is analog. and usually one can use a/d input pins as output pins. but i did not read anything specific in the sheet.

you could add some print statements to see if all your code is executed or if there is some reset.

i do not know about the hardware you use. maybe it picks up some signal on the reset.

i see no good reason for pb1 not working.
but you should test with the known loop
do
toggle portb.1
waitms 100
loop

and see if that works. then add more code in and see if it keeps working or where/when it would fail.

_________________
Mark
Back to top
View user's profile Visit poster's website
nobner

Bascom Member



Joined: 29 Apr 2015
Posts: 21

germany.gif
PostPosted: Mon Nov 29, 2021 2:34 pm    Post subject: Attiny 417 output failure Reply with quote

I understand what you mean, but as i know from fewer projects with e.g. Atmega328 there was never a problem to use a ADC Pin as an input and another pin as an digital output, thus this was an possible ADC Pin also. It even was not necessary to stop the ADC for that.
One post before i asked you about section 5.1 in the datasheet - how can i disable the alternative functions? With Atmega i used register writing to do so, but with xtiny it seems different? How can i disable the alternative functions? As "Stop ADC0" is not working, how can i stop the ADC during program execution?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Nov 29, 2021 3:41 pm    Post subject: Reply with quote

Config Adc0 = Single , Adc = disabled

or wrote 0 to adc0_CTRLA.0 (register names and locations vary from chip to chip) so best use the config as shown.

i still did not see a reference to the used hardware.

_________________
Mark
Back to top
View user's profile Visit poster's website
nobner

Bascom Member



Joined: 29 Apr 2015
Posts: 21

germany.gif
PostPosted: Mon Nov 29, 2021 8:10 pm    Post subject: Attiny 417 output failure Reply with quote

Hi Mark,
as suggested i tried to disable Adc after use - no effect on the failure.
My momentary failure conclusion: Using 3 Adc inputs - is working, using 4 Adc inputs - is not working. Can there be a kind of Adc-overflow?
Attached my fuses and the circuit diagram.

Norbert


Last edited by nobner on Tue Nov 30, 2021 10:47 pm; edited 1 time in total
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Nov 29, 2021 8:58 pm    Post subject: Reply with quote

it is not a stack problem. stack comes when you call sub routines. but you do not have them. you also do not use interrupts.
a/d overflow is not likely.

you can best add some print statements and print the values you measure. and see if all code is executed with values you think they should have.
PortA.1 can server as TX pin.
to get the alternative tx pin, use :
config COM1=9600, TXPIN=ALT1_PA1
or
Config Port_mux = Preserve , Usart0 = Alt1_pa1pa4

you can also try a modification on your pcb and use another pin for the output.

it will also be a good idea to check the vcc with a scope. also i do not know if there is a load on the circuit but try to measure the output without load.

then you can also try to fake the a/d value. just give it some hard coded value.

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Nov 30, 2021 7:53 pm    Post subject: Reply with quote

With a certain understanding to the beginners worries and problems, I would suggest something like that:
1) open trash bin
2) place code in trash bin
3) close trash bin
4) select empty trash bin

While it still may make sense, to execute on-time of different colors "one after each other", it reduces maximal brightness to one quart at default current.
The question is: why would one do or want that?

I can't also make sense out of the fact, that any ADC input value over 240 shortens runtime of the main loop and thus frequency of the PWM.
If the TO intends this behavior I'd surely am interested to hear about the reason.

Even if one does not want or does not know how to use hardware PWM or interrupt-driven soft-PWM, one can very easily do a soft-PWM in the main loop, which wins against this botchery by lengths.

If then a simplified and logically improved code exists, looking for errors is easier too.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Nov 30, 2021 8:33 pm    Post subject: Reply with quote

MWS, it does not resolve the portb.1 problem.
_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Nov 30, 2021 10:04 pm    Post subject: Reply with quote

albertsm wrote:
MWS, it does not resolve the portb.1 problem.

Did you check this behavior yourself on real hardware?
If alternative code runs, then one can still check about why this code-mess doesn't.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Nov 30, 2021 11:34 pm    Post subject: Reply with quote

Thought about something like the following, may have errors, have no xtiny-libs.
Calculated 4 channels two times 13 ADC-ticks at 2.5MHz ADC-clock to 52µs, which results in a PWM repeat rate of 75Hz.
It will perform differently than the other code, as getting the analog values is part of the PWM-loop.
The correct way is to use HW-PWM, the 417 seems to sport 6 PWM channels.
Code:
$Regfile="atxtiny417.dat"
$Crystal=16000000
$hwstack=40
$swstack=16
$framesize=32

config Sysclock = 16_20mhz , Prescale = 1 , Clockout = Disabled '16/20MHz in Fuses auf 16Mhz setzen

config PORTA.4 = INPUT  'Eingangssignal rot
config PORTA.5 = INPUT  'Eingangssignal grün
config PORTA.7 = INPUT  'Eingangssignal weiss
config PORTB.4 = INPUT  'Eingangssignal blau

config PORTA.3 = OUTPUT 'Ausgangssignal weiss
config PORTB.0 = OUTPUT 'Ausgangssignal grün
config PORTB.1 = OUTPUT 'Ausgangssignal rot
config PORTB.2 = OUTPUT 'Ausgangssignal blau

GREEN_OUT alias PORTB.0
RED_OUT alias PORTB.1
BLUE_OUT alias PORTB.2
WHITE_OUT alias PORTA.3

Config Adc0 = Single , Resolution = 8bit , Adc = Enabled , Reference = VDD , Prescaler = 8 , Sample_len = 1 , Sample_cap = Above_1v , Init_delay = 32

DIM RED_IN as byte
DIM GREEN_IN as byte
DIM BLUE_IN as byte
DIM WHITE_IN as byte

Dim PWM_Idx As Byte

Do
  If PWM_Idx = 0 Then
    GREEN_IN = GETADC(5)' PA.5
    RED_IN = GETADC(4)    ' PA.4
    BLUE_IN = GETADC(9)   ' PB.4
    WHITE_IN = GETADC(7) ' PA.7
  Else
    Waitus 52
  End If
    If GREEN_IN <= PWM_Idx Then GREEN_OUT = 0 Else GREEN_OUT = 1
    If RED_IN <= PWM_Idx Then RED_OUT = 0 Else RED_OUT = 1
    If BLUE_IN <= PWM_Idx Then BLUE_OUT = 0 Else BLUE_OUT = 1
    If WHITE_IN <= PWM_Idx Then WHITE_OUT = 0 Else WHITE_OUT = 1
      PWM_idx = PWM_idx +1
Loop

end
Back to top
View user's profile
nobner

Bascom Member



Joined: 29 Apr 2015
Posts: 21

germany.gif
PostPosted: Sat Dec 04, 2021 4:06 pm    Post subject: Attiny 417 output failure Reply with quote

Hi Mark,
finally i found the solution:
It is the name of the variable "RED_PAU". When i replace it with some other name (like "nonsense", or any other name), programm works bug-free.
Why is this so?
Thanks for support.

WORKS NOT:
Code:

'---------------------------------------------------------------------------
'Kanal ROT
RED_IN = GETADC(4)
IF RED_IN > 240 THEN RED_IN = 255
RED_PAU = RED_IN
RED_IN = 255 - RED_IN
'---------------------------------------------------------------------------
'Kanal RED
IF RED_IN > 10 THEN
               RED_OUT = 1
               waitus RED_IN
               RED_OUT = 0
               waitus RED_PAU
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
 


WORKS:
Code:

'---------------------------------------------------------------------------
'Kanal ROT
RED_IN = GETADC(4)
IF RED_IN > 240 THEN RED_IN = 255
nonsense = RED_IN
RED_IN = 255 - RED_IN
'---------------------------------------------------------------------------
'Kanal RED
IF RED_IN > 10 THEN
               RED_OUT = 1
               waitus RED_IN
               RED_OUT = 0
               waitus nonsense
END IF
waitus OFF_ZEIT
'---------------------------------------------------------------------------
 
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum