Oshonsoft support for Atmega328p

Thread Starter

Stevel28

Joined May 28, 2020
10
Hoped to employ Oshonsoft AVR Simulator IDE to produce a PWM output from an Arduino Nano which uses the Atmega 328P micro. However this IDE appears not to support PWM for this micro, which surprises me, and I'm wondering if I've missed something?
 

ericgibbs

Joined Jan 29, 2010
18,766
hi Steve,
Welcome to AAC.
The PWM feature is not included in the supported peripherals list.

E

The IDE appears to accept and compile the PWM code, but no signal on the pins or scope.
 

Attachments

Last edited:

Thread Starter

Stevel28

Joined May 28, 2020
10
hi Steve,
Welcome to AAC.
The PWM feature is not included in the supported peripherals list.

E

The IDE appears to accept and compile the PWM code, but no signal on the pins or scope.
Hi Eric, Thanks for that. I'm thinking of writing Vladmir to question this omission. I did see recently on his website, that he was active, or planned to be soon, on supporting Arduinos. Can't wait.

Steve l
 

ericgibbs

Joined Jan 29, 2010
18,766
hi Steve,
I guess you know that Oshonsoft IDE supports ASM coding as part of a Basic language code.
Have you considered adding PWM by using the ASM option.

E
 

Ian Rogers

Joined Dec 12, 2012
1,136
Hi Steve... If you are the same Steve I've been talking to... Vlad doesn't seem to cover much of the AVR.. But.. All the registers are available.. You could even write high level routines using basic...
 

Thread Starter

Stevel28

Joined May 28, 2020
10
Hi Steve... If you are the same Steve I've been talking to... Vlad doesn't seem to cover much of the AVR.. But.. All the registers are available.. You could even write high level routines using basic...
I'm the same Steve Ian. Unfortunately i don't have a clue on how to write basic routines involving the registers.
 

Ian Rogers

Joined Dec 12, 2012
1,136
Just try this for me..

Code:
Proc pwminit()
  DDRB = 0x6
  OCR1AL = 0x47
  OCR1AL = 0x10
  TCCR1A = 0xf2
  TCCR1B = 0x1a
  ICR1L = 0x1f  '(at 8mhz clock we have: 50 = 8000000 / 8(1 + icr).foc = fosc / prescaler(1 + top))
  ICR1H = 0x4e
End Proc                                       

Proc pwmset(duty As Word)
  OCR1AL = duty.LB
  OCR1AH = duty.HB
End Proc
Set pwm with the bottom and init with the first.. pwm on pin 9 and 10...
 

Thread Starter

Stevel28

Joined May 28, 2020
10
Just try this for me..
(Ian's two procedures shown here)
End Proc
[/code]
Set pwm with the bottom and init with the first.. pwm on pin 9 and 10...
Not sure what you intended here Ian, I copied the two procedures to Osh AVR compiler on their own as presented by you and it came up up with error saying procedures must be inserted after end of program. So I wrote a simple program:

"Dim Duty as word
Loop:
duty = 255 'LED on Pin 9
GoTo Loop
End"

then put the two procedures below this, and it compiled, but declared the two Procs unused. Of course the LED didn't light.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi Steve,
Post the code for your short test program and will check the compiled code to see if the compiler has generated any code for those pWM's
E
 

Thread Starter

Stevel28

Joined May 28, 2020
10
hi Steve,
Post the code for your short test program and will check the compiled code to see if the compiler has generated any code for those pWM's
E

Here it is Eric:

Define CLOCK_FREQUENCY = 8
Dim duty As Word
loop:
duty = 255
Goto loop
End
Proc pwminit()
DDRB = 0x6
OCR1AL = 0x47
OCR1AL = 0x10
TCCR1A = 0xf2
TCCR1B = 0x1a
ICR1L = 0x1f '(at 8mhz clock we have: 50 = 8000000 / 8(1 + icr).foc = fosc / prescaler(1 + top))
ICR1H = 0x4e
End Proc
Proc pwmset(duty As Word)
OCR1AL = duty.LB
OCR1AH = duty.HB
End Proc
 

ericgibbs

Joined Jan 29, 2010
18,766
hi Steve,
Seems to be creating compiled Code, but the IDE will NOT respond to the Code.
E
Steve1.txt change to .asm...Compiled file
Steve2.txt is the List file
 

Attachments

Thread Starter

Stevel28

Joined May 28, 2020
10
hi Steve,
Seems to be creating compiled Code, but the IDE will NOT respond to the Code.
E
Steve1.txt change to .asm...Compiled file
Steve2.txt is the List file
This is all largely lost on me Eric; are you saying the finger is pointing at Vlad's IDE, and if so, should he be tipped off about it?
 

ericgibbs

Joined Jan 29, 2010
18,766
hi Steve,
Vlad points out that the PWM is not a AVR feature included in the simulation, I suspect his compiler creates the required Code, but it cannot be simulated.

My next step would be too write a short test program using the Basic code you posted method, program it into an actual atmega 328 and see if works.

E
 

Ian Rogers

Joined Dec 12, 2012
1,136
Just tried this on an Arduino... got a pulse from OC1a (pin 9)
Code:
Define CLOCK_FREQUENCY = 8
'Define SIMULATION_WAITMS_VALUE = 0
Dim duty As Word
duty = 100
Call pwminit()
loop:
'Call pwmset(duty)
'duty = duty + 30
WaitMs 30
Goto loop
End                                              
Proc pwminit()
DDRB = 0x6
OCR1AL = 0xff
OCR1AH = 0x0
OCR1BL = 0xff
OCR1BH = 0x2
TCCR1A = 0xf3
 TCCR1B = 0x0a
 ICR1L = 0xff  '(at 8mhz clock we have: 50 = 8000000 / 8(1 + icr).foc = fosc / prescaler(1 + top))
ICR1H = 0x03
'TIMSK1 = 0x6
End Proc                                        
Proc pwmset(duty As Word)
OCR1AL = duty.LB
OCR1AH = duty.HB
End Proc
 

Thread Starter

Stevel28

Joined May 28, 2020
10
Just tried this on an Arduino... got a pulse from .....]
hi again Ian, first want to say thanks for tacitly telling me I needed to call the procedures in the main program for them to become effective. I didn't know that.:)

Anyway, having loaded your program in the arduino nano, (LED on pin D10), I'm afraid the led lit up and remained on permanently. Maybe when you said you got a pulse, you meant a step? So after playing around with this thing for hours, I found the following program worked - don't ask me why. I didn't need to invoke the pwmset procedure at all.
BTW i notice the pwm output seems to be inverted. Wondering how toget it non-inverting?

Define CLOCK_FREQUENCY = 8
'Define SIMULATION_WAITMS_VALUE = 0
Dim duty As Word
duty = 10000
loop:
Call pwminit()
duty = duty + 5
WaitMs 20
If duty <= 0 Then duty = 10000
Goto loop
End
Proc pwminit()
DDRB = 0x6
OCR1AL = duty.LB '0x0
OCR1AH = duty.HB '0xff
OCR1BL = duty.LB '0xff
OCR1BH = duty.HB '0x2
TCCR1A = 0xf3
TCCR1B = 0x0a
ICR1L = 0xff '(at 8mhz clock we have: 50 = 8000000 / 8(1 + icr).foc = fosc / prescaler(1 + top))
ICR1H = 0x03
TIMSK1 = 0x6
End Proc
'Proc pwmset(duty As Word)
'OCR1AL = duty.LB
'OCR1AH = duty.HB
'End Proc

Steve
 

Ian Rogers

Joined Dec 12, 2012
1,136
The led will stay permanently lit.... Its a 5v pulse, all that will happen will be the brightness will change... PWM is running very fast, you'll need a scope to see it.

If you have a 25% PWM the led will be quite dim.. 66% it'll be half illuminated 90%+ it'll look bright.. PWM is not linear..

PWMinit should be called before the loop.. Change the duty inside the loop..
 

Ian Rogers

Joined Dec 12, 2012
1,136
The ICR1A is 65535 max... But I selected 10 bit.. if you want to use ICR1A as TOP then you need to select a different mode..
Also your example looks like it wants to start at 10000 and reduce... BUT!!! Vlad doesn't use signed numbers so the line
" If duty <= 0 Then duty = 10000 " is useless to you.. Also you need to -5 each loop for the LED to dim.
With the settings you have, ORCA should be 0 ~ 1024.. 10000 is far too high... I set IRCA to 1024 (TOP)..

If you read the datasheet there is a table that will allow several modes of PWM... The one I chose is the easiest for you..
 

Thread Starter

Stevel28

Joined May 28, 2020
10
The ICR1A is 65535 max... But I selected 10 bit.. if you want to use ICR1A as TOP then you need to select a different mode..
Also your example looks like it wants to start at 10000 and reduce... BUT!!! Vlad doesn't use signed numbers so the line
" If duty <= 0 Then duty = 10000 " is useless to you.. Also you need to -5 each loop for the LED to dim.
With the settings you have, ORCA should be 0 ~ 1024.. 10000 is far too high... I set IRCA to 1024 (TOP)..

If you read the datasheet there is a table that will allow several modes of PWM... The one I chose is the easiest for you..
Hi Ian, owe you apology. After having fun and games with this playtime exercise, discovered I was on the wrong pin -10 instead of 9. Still getting some odd results though. When first copying your code andchanging to .pin 9, worked like a dream, slow ramp up in brightness to top value, followed by step drop to minimum. However,after copying your code into another computer, I got the opposte waveform response - step up to max brightness, followed by gentle ramp down to miimum. A mysterious inversion had occurred. Haven't figured it out yet.
 
Top