View previous topic :: View next topic |
Author |
Message |
Paul Pawelski
Joined: 14 Nov 2004 Posts: 6
|
Posted: Sun Nov 14, 2004 3:44 am Post subject: Problem doing dual PWM with Timer1 |
|
|
I am trying to do dual PWM control on a Mega8. I based my code on Eddie Wright's code for his line following bot. To test the code, I hooked an LED to port B1 and another to port B2. Each of the LED's were also attached to ground through a 380 Ohm resistor. I put in the following code expecting to see both LED's light up at various intensities. The one on port B1 works like expected, but the other one never lights. What am I missing?
'--------------------------------------------------------------
' PWM_PCP.bas
' Test of two channel PWM by Paul Pawelski
'--------------------------------------------------------------
$regfile = "m8def.dat" 'identify the chip
$crystal = 1000000 'set the speed to 1 MHz
$baud = 19200 'UART speed
'--------------------------------------------------------------
'constants
Const Neutral = 0
Const Lslow = 75
Const Rslow = 75
Const Lmedium = 190
Const Rmedium = 180
Const Lfast = 255
Const Rfast = 245
'--------------------------------------------------------------
'aliases
Speedleft Alias Pwm1a
Speedright Alias Pwm1b
'--------------------------------------------------------------
'variables
Dim X As Bit
'--------------------------------------------------------------
'config PWM
Config Timer1 = Pwm , Pwm = 8 , Prescale = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
'--------------------------------------------------------------
'configure ports
Config Portb = Output
'--------------------------------------------------------------
'start PWM
Enable Interrupts
Start Timer1
'--------------------------------------------------------------
'MAIN CODE
Set X
While X = 1 ' the loop that never ends
Speedleft = Lmedium
Speedright = Rmedium
Wait 1 'wait one second
Speedleft = Lslow
Speedright = Rfast
Wait 1 'wait one second
Speedleft = Lfast
Speedright = Rslow
Wait 1 'wait one second
Speedleft = Neutral
Speedright = Rmedium
Wait 1 'wait one second
Wend
End
'--------------------------------------------------------------
Paul Pawelski |
|
Back to top |
|
|
Frankeman
Joined: 11 Aug 2004 Posts: 948 Location: the Netherlands
|
Posted: Sun Nov 14, 2004 9:29 am Post subject: |
|
|
Hi Paul,
Connect the resistor to +5V instead of ground, then it should work.
(don't forget to reverse the led)
Frank. |
|
Back to top |
|
|
Paul Pawelski
Joined: 14 Nov 2004 Posts: 6
|
Posted: Sun Nov 14, 2004 3:24 pm Post subject: Still No Signal on B2 |
|
|
Tried it. No luck. I also took my handy DMM and checked each port pin for output. Only port B1 was any activity relitive to ground.
Paul |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Sun Nov 14, 2004 9:22 pm Post subject: |
|
|
try that it will be good
Config Pinb.1 = Output ' important to let OC1A and OC1B in output
Config Pinb.2 = Output
Config Timer1 = Pwm , Pwm = 10 , Prescale = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Down
Pwm1a = 768
Pwm1b = 768
Start Timer1
Locate 2 , 1 : Lcd "pwm=10 ps=1"
End
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
Paul Pawelski
Joined: 14 Nov 2004 Posts: 6
|
Posted: Tue Nov 16, 2004 12:54 am Post subject: I Found the problem |
|
|
I found what the problem was and like most problems it was something stupid. Over the last two months, I have worked with four different micros: PIC, Athena, BS2, & AVR. With the PIC, whenever I clicked the program button, MPLAB forced me to save and compile the code so that what was on the screen matched what was sent. Athena and BS2 would both automatically retokenize the file that was on the screen each time I hit program. BASCOM does not do that. It always takes the saved compiled code file and sends it to the chip. So I had compiled my first pass at the code (where I guess I had config Portb.1 instead of config Portb in the code), but every change I made after that did not get compiled so I was always sending the same code to the chip no matter what I changed on the screen or saved in the text file.
One stupid mistake noted. Now I can continue on to my next stupid mistake! |
|
Back to top |
|
|
|