View previous topic :: View next topic |
Author |
Message |
Rodders
Joined: 04 Mar 2010 Posts: 12 Location: Birmingham
|
Changing PWM duty cycles |
Posted: Thu Mar 04, 2010 5:10 pm |
|
|
NO MESSAGE
Last edited by Rodders on Tue Mar 09, 2010 7:37 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 04, 2010 5:54 pm |
|
|
Quote: |
#byte Port_A=0X80 // file address of Port B
#byte Tris_A=0X92 // file address of Tris B
#byte Port_B=0X81 // file address of Port A
#byte Tris_B=0X93 // file address of Tris A
#byte Port_C=0X82 // file address of Port C
#byte Tris_C=0X94 // file address of Tris C
|
Why are you not using the full, correct SFR register addresses ?
Why only the bottom 8 bits ? Also, in the case of Port A and B,
the comments are reversed. |
|
|
Rodders
Joined: 04 Mar 2010 Posts: 12 Location: Birmingham
|
|
Posted: Thu Mar 04, 2010 6:06 pm |
|
|
PCM programmer wrote: | Quote: |
#byte Port_A=0X80 // file address of Port B
#byte Tris_A=0X92 // file address of Tris B
#byte Port_B=0X81 // file address of Port A
#byte Tris_B=0X93 // file address of Tris A
#byte Port_C=0X82 // file address of Port C
#byte Tris_C=0X94 // file address of Tris C
|
Why are you not using the full, correct SFR register addresses ?
Why only the bottom 8 bits ? Also, in the case of Port A and B,
the comments are reversed. |
I am not sure I understand the bit about only the bottom 8 bits being used.
I got these adresses from the datasheet. They way we were taught was to have a struct as a pinmap of a port. Pins on Port A have the address 0x80 whilst the tris bits are on 0x92.
I thought it'd be more elegant than just having huge struct containing all the 24 pins in a row.
Is there another way I could set my pins? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 04, 2010 6:11 pm |
|
|
Look at this table in the 18F26K20 data sheet. What are the SFR addresses ?
Quote: |
TABLE 5-1: SPECIAL FUNCTION REGISTER MAP FOR PIC18F2XK20/4XK20 DEVICES
|
|
|
|
Rodders
Joined: 04 Mar 2010 Posts: 12 Location: Birmingham
|
|
Posted: Thu Mar 04, 2010 6:34 pm |
|
|
PCM programmer wrote: | Look at this table in the 18F26K20 data sheet. What are the SFR addresses ?
Quote: |
TABLE 5-1: SPECIAL FUNCTION REGISTER MAP FOR PIC18F2XK20/4XK20 DEVICES
|
|
The exact same addresses I used to set up my ports? I think I may have set up my pin map using already defined SFRs. I don't understand why that wouldn't work.
Instead should I use any addresses on bank 0 for the port adresses and then set the tris bits on the addresses available on bank 1? |
|
|
Rodders
Joined: 04 Mar 2010 Posts: 12 Location: Birmingham
|
|
Posted: Thu Mar 04, 2010 7:38 pm |
|
|
Rodders wrote: | PCM programmer wrote: | Look at this table in the 18F26K20 data sheet. What are the SFR addresses ?
Quote: |
TABLE 5-1: SPECIAL FUNCTION REGISTER MAP FOR PIC18F2XK20/4XK20 DEVICES
|
|
The exact same addresses I used to set up my ports? I think I may have set up my pin map using already defined SFRs. I don't understand why that wouldn't work.
Instead should I use any addresses on bank 0 for the port adresses and then set the tris bits on the addresses available on bank 1? |
Scrap this last post. I think I've entered the correct addressed for the pinmaps. Forgive my silly mistake and slow understanding. Took me time to understand what you meant.
Code: | #byte Port_C=0XF82 // file address of Port C
#byte Tris_C=0XF94 // file address of Tris C
#byte Port_B=0XF81 // file address of Port B
#byte Tris_B=0XF93 // file address of Tris B
#byte Port_A=0XF80 // file address of Port A
#byte Tris_A=0XF92 // file address of Tris A |
|
|
|
Rodders
Joined: 04 Mar 2010 Posts: 12 Location: Birmingham
|
|
Posted: Fri Mar 05, 2010 2:59 pm |
|
|
The code works fine now. I used a Switch case menu and the robot processes fine the line readings and converts them into motion.
However, I burned 2 PICS and am wondering should we use 4 diodes when connecting the the inputs from the H-bridge to the motors? I am running my motors using a 20kHz pwm pulse and would like to know which one is the recommended one for small dc motor applications?
P.S. Is it possible to implement PID without optical encoders around the wheel shaft of the motor. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 05, 2010 3:06 pm |
|
|
Quote: |
However, I burned 2 PICS and am wondering should we use 4 diodes
when connecting the the inputs from the H-bridge to the motors?
|
By "burned", do you mean "destroyed" or "programmed" ?
Post a schematic of your existing PIC, H-Bridge, and motor circuit. |
|
|
Rodders
Joined: 04 Mar 2010 Posts: 12 Location: Birmingham
|
|
Posted: Fri Mar 05, 2010 4:30 pm |
|
|
PCM programmer wrote: | Quote: |
However, I burned 2 PICS and am wondering should we use 4 diodes
when connecting the the inputs from the H-bridge to the motors?
|
By "burned", do you mean "destroyed" or "programmed" ?
Post a schematic of your existing PIC, H-Bridge, and motor circuit. |
Unfortunately I don't have it at the moment, the guy in charge of electronics has has it. I am just the programmer. I output 2 pwm signal plus 2 direction and brake signal to the H-bridge: LMD18200. The 2 outputs of the PIC are decoupled with a pair of capacitors connecting the output to bootstrap.
When I say burned, the pic will initially show a pwm output on the oscilloscope before it completely flatlines. Same result with new PICs or reprogrammed pics. The circuit will be revised because it seems to be draining way too much current, i.e. the robot motors will only run when supplied with 15V but will come to a standstill with any supply voltage ranging from 16V-30V. Electronics really isn't my forte, which is why I am focussing on implementing PID for a very smooth and effcient motion.
Is it possible to implement PID using input from the 4 sensors we're using to track the line? |
|
|
|