as a newbie having problem with my program in BASCOM?

7 posts / 0 new
Last post
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi guys i have some question about bascom program below:
please explain line by line what does a line does.
thanks.please give more explanation on PWM.why it is set to 10 and all about that.thanks

$regfile = "m16def.dat"
$crystal = 8000000

Config Timer1 = Pwm [=#444444][=red[/color]], Pwm = 10[/] , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 8

Enable Timer1
Enable Interrupts
Declare Sub Inc_pwm
Declare Sub Dec_pwm

CONFIG LCDPIN = PIN ,DB4= PORTB.1,DB5=PORTB.2,DB6=PORTB.3, DB7=PORTB.4,E=PORTB.5,RS=PORTB.6
Start Timer1

Dim I As Integer , W As Word

I = 500
Lcd "pwm =" ; I

Do
Debounce Pina.0 , 1 , Dec_pwm , Sub
Debounce Pina.1 , 1 , Inc_pwm , Sub
Pwm1b = I
Waitms 1

Loop

End

Sub Inc_pwm:
If I > 1000 Then I = 1000
I = I + 100
Cls
Home
Lcd "pwm =" ;I
Return
End Sub

Sub Dec_pwm
If I < 100 Then I = 100
I = I - 100
Cls
Home
Lcd "pwm =" ;I
Return
End Sub

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Header defines which chip you are using, and the clock frequency, ( 8 MHz).

Timer 1 is a 16 bit timer. PMW defines the mode you are using, (Timer, Counter, or PWM).

In PWM mode you have a choice of using 8, 9, or 10 bits, the 10 defines 10 bit mode.

The LCD command defines the pins to which one has connected an LCD, which is used to display the current PWM value.

Enable interrupts: Two lines, one to enable the Timer1 interrupt, and one to enable interrupts Globally, (i.e. overall enable).

The Do Loop just reads to push button switches, and if you push one it calls the sub to either increment or decrement the PWM value. The debounce "debounces" the push button press, so you do not get multiple Incr or Decr per push. Mechanical switches generate several pulses when opened or closed.

Every time you push a button the routine clears the LCD, moves the cursor to the Home position, (Top line, left most character), and then displays the PWM value.

Your hardware has to match that expected by the program to work.

Although looking at the value on the LCD is nice, you really need an O'scope to see the PWM output, and the effect of changing it.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
The Header defines which chip you are using, and the clock frequency, ( 8 MHz).

Timer 1 is a 16 bit timer. PMW defines the mode you are using, (Timer, Counter, or PWM).

In PWM mode you have a choice of using 8, 9, or 10 bits, the 10 defines 10 bit mode.

The LCD command defines the pins to which one has connected an LCD, which is used to display the current PWM value.

Enable interrupts: Two lines, one to enable the Timer1 interrupt, and one to enable interrupts Globally, (i.e. overall enable).

The Do Loop just reads to push button switches, and if you push one it calls the sub to either increment or decrement the PWM value. The debounce "debounces" the push button press, so you do not get multiple Incr or Decr per push. Mechanical switches generate several pulses when opened or closed.

Every time you push a button the routine clears the LCD, moves the cursor to the Home position, (Top line, left most character), and then displays the PWM value.

Your hardware has to match that expected by the program to work.

Although looking at the value on the LCD is nice, you really need an O'scope to see the PWM output, and the effect of changing it.

JC

thanks but what do you mean by:
timer 1 is a 16 bit timer. PMW defines the mode you are using, (Timer, Counter, or PWM).
do we have some entity by name of PWM?what is this?
i am newbie please explain it?
thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A timer is a binary counter. The trigger to make it count can come from the system clock, or a pulse on an external pin.

Some counters are 8 bits, meaning that they can count from 0000 0000 up to 1111 1111, (0-255 dec), before they 'roll over' and start counting at 0000 0000 again.

A 16 bit counter uses two, 8-bit bytes to count. It has a much greater range, 0 to 65,535 dec, before it rolls over to 0 again.

The 10 bits in the PWM refers to the resolution of the pulse widths you can generate. The greater the number of bits, the finer the resolution pulses you can generate.

Check out the data sheet for the AVR you are using, available from the ATMEL web site.

Check the tutorials and projects sections for examples using PWM.

Check out the BASCOM forum, also.

Use the search option for this and the Bascom forum to locate links discussing PWM usage.

Keep studying, it is great when the code runs and the project works!

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

More traffic about this here:

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=64176

(just how many threads will start about what is essentially the same question remains to be seen)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
More traffic about this here:

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=64176

(just how many threads will start about what is essentially the same question remains to be seen)


mind your own job,i dont need you to give me any help.so get lost.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Carefull

Watch your steps, with these people around here.

Manners & respect